6

我在 Eclipse RAP(Rich Ajax Platform 1.3.2)和 Java 1.5 中使用 jetty 6.1.23。我正在向浏览器发送 PNG 图像。这些是导致麻烦的代码片段:

服务器端:

response.setContentType(application.getMimeType(".png"));
response.setContentLength(outputSize);
response.setHeader("Cache-Control", "no-cache"); 
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Max-Age", 0); 
ServletOutputStream servletoutputstream = response.getOutputStream();

servletoutputstream.write(imageBytes); // this throws EofException

servletoutputstream.flush();

客户端:

<img src="path to the servlet that is loading the image">

奇怪的是,这个问题并非一直都在发生。在我们投入生产后,它会间歇性地发生。我们的测试环境没有问题。生产环境和我们的测试环境唯一的区别是,在生产环境中,用户离我们的服务器很远,而在测试环境中,他们非常接近。

抛出异常时,客户端浏览器端根本不会显示图像!到底是怎么回事?我能做些什么来修复它或至少有一个解决方法?

这是完整的异常跟踪(我突出显示了关键异常):

08 Feb 2012 11:49:08,955 ERROR [1584291438@qtp-2135195460-260] plugin.sda - 
org.mortbay.jetty.EofException
    at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:789)
    at org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:568)
    at org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:1006)
    at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:650)
    at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:590)
    at com.scotiabank.ebss.common.viewer.util.ViewerUtil.sendBytes(ViewerUtil.java:533)
    at com.scotiabank.ebss.common.viewer.servlets.ViewerServlet.doGet(ViewerServlet.java:242)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
    at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:924)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcher.writev0(Native Method)
    at sun.nio.ch.SocketDispatcher.writev(SocketDispatcher.java:61)
    at sun.nio.ch.IOUtil.write(IOUtil.java:192)
    at sun.nio.ch.SocketChannelImpl.write0(SocketChannelImpl.java:393)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:416)
    at java.nio.channels.SocketChannel.write(SocketChannel.java:375)
    at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:232)
    at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:211)
    at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:712)
    ... 27 more
4

2 回答 2

3

该问题似乎与网络相关,与 Jetty 几乎没有关系。

您正在尝试将大量数据写入另一端已关闭的网络套接字。这就是Broken pipe异常的意思。

您需要找出 HTTP 连接意外关闭的原因。原因可能与 Jetty 有关,但我强烈怀疑不是。

于 2012-02-09T11:06:36.830 回答
1

检查请求/响应大小限制。尝试下载小于 4k 的较小图像。

于 2012-02-09T12:10:43.520 回答