others - Wildfly:org.xnio. channels.FixedLengthOverflowException

这在JBoss AS 7.1中工作得很好,在Undertow中,即使是"小"文件,也会收到以下异常:


13:04:43,292 ERROR [io.undertow.request] (default task-15) Blocking request failed HttpServerExchange{ GET /project/getFile.xhtml}: java.lang.RuntimeException: org.xnio.channels.FixedLengthOverflowException
 at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:527)
 at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:287)
 at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
 at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
 at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
 at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168)
 at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
 at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
Caused by: org.xnio.channels.FixedLengthOverflowException
 at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.write(AbstractFixedLengthStreamSinkConduit.java:97)
 at org.xnio.conduits.Conduits.writeFinalBasic(Conduits.java:132) [xnio-api-3.2.0.Final.jar:3.2.0.Final]
 at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.writeFinal(AbstractFixedLengthStreamSinkConduit.java:137)
 at org.xnio.conduits.ConduitStreamSinkChannel.writeFinal(ConduitStreamSinkChannel.java:104) [xnio-api-3.2.0.Final.jar:3.2.0.Final]
 at io.undertow.channels.DetachableStreamSinkChannel.writeFinal(DetachableStreamSinkChannel.java:172)
 at io.undertow.servlet.spec.ServletOutputStreamImpl.writeBufferBlocking(ServletOutputStreamImpl.java:580)
 at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputStreamImpl.java:614)
 at io.undertow.servlet.spec.HttpServletResponseImpl.closeStreamAndWriter(HttpServletResponseImpl.java:451)
 at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:525)
 ... 9 more

删除Try.catch,日志和错误处理以节省一些空间),


public void downloadFile(FileEntity fileEntity) {
 FacesContext fc = FacesContext.getCurrentInstance();
 ExternalContext ec = fc.getExternalContext();

 ec.responseReset();
 ec.setResponseContentType(getMimeType(fileEntity.getFile()));
 ec.setResponseContentLength(new Long(fileEntity.getFile().length()).intValue());
 ec.setResponseHeader("Content-Disposition","attachment; filename="" + ConversionHelper.validateFilename(fileEntity.getDisplayFileName()) +""");

 OutputStream output = ec.getResponseOutputStream();
 FileInputStream fis = new FileInputStream(fileEntity.getFile());

 IOUtils.copy(fis, output);

 fc.responseComplete();
 }

我注意到这行


ec.setResponseContentLength(new Long(fileEntity.getFile().length()).intValue());

使用


ec.setResponseContentLength(new Long(fileEntity.getFile().length()).intValue() + 9);


为了调用下载,在getFile.xhtml中使用了类似的东西:


 <f:metadata>
 <f:viewParam name="fileId" required="true"
 value="#{getFileController.fileId}"></f:viewParam>
 </f:metadata>

 <h:outputLabel value="#{getFileController.download()}" />

这通常会产生:


<label>value</label>


 <f:metadata>
 <f:viewParam name="fileId" required="true"
 value="#{getFileController.fileId}"></f:viewParam>
 <f:event listener="#{getFileController.dlNow()}" type="preRenderView"></f:event>
 </f:metadata>


时间: 作者:

如果你调用output.close(),应该可以工作,这看起来像JSF的问题,与Undertow无关。

...