java WebLogic“超出规定的内容长度”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1664996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 17:30:06  来源:igfitidea点击:

WebLogic "Exceeded stated content length" Error

javaweblogic

提问by user201372

I have a servlet filter that is generating "Exceeded stated content length" errors in WebLogic 10.0. I would appreciate any suggestions to fix this issue please. Details as follows.

我有一个 servlet 过滤器,它在 WebLogic 10.0 中生成“超出规定的内容长度”错误。我将不胜感激任何解决此问题的建议。详情如下。

The servlet filter resizes images. This error is occurring then writing the contents a FileInputStream (from disk) to response.getOutputStream() :

servlet 过滤器调整图像大小。发生此错误,然后将内容写入 FileInputStream(从磁盘)到 response.getOutputStream() :

java.net.ProtocolException: Exceeded stated content length of 2228 at weblogic.servlet.internal.ChunkOutput.writeStream(ChunkOutput.java:411)

java.net.ProtocolException:在 weblogic.servlet.internal.ChunkOutput.writeStream(ChunkOutput.java:411) 中超出规定的 2228 内容长度

See the end of this message for the full stack trace.

有关完整的堆栈跟踪,请参阅此消息的结尾。

Our environment is WebLogic 10.0 with Java 1.5 (on Windows XP). However, we have been using this same servlet filter on Tomcat 6, Java 1.6 for over a year so without any problems. Also, we did successfully test a previous version of this servlet filter with WebLogic 8.1.

我们的环境是带有 Java 1.5 的 WebLogic 10.0(在 Windows XP 上)。但是,我们已经在 Tomcat 6、Java 1.6 上使用相同的 servlet 过滤器一年多了,所以没有任何问题。此外,我们确实使用 WebLogic 8.1 成功测试了此 servlet 过滤器的先前版本。

The content lengths stated in the stack trace errors do accurately match the sizes of the source files on disk. So, I don't know how the content length is getting too large.

堆栈跟踪错误中声明的内容长度确实与磁盘上源文件的大小准确匹配。所以,我不知道内容长度是如何变得太大的。

The errors occur after loading 6 images each about 2kB in size. So, I did wonder if the issue might be related to the WebLogic response buffer size which I gather is about 12 kB.

加载 6 个图像后发生错误,每个图像大小约为 2kB。因此,我确实想知道该问题是否与我收集的 WebLogic 响应缓冲区大小有关,该大小约为 12 kB。

I attempted to increase the response buffer size using the response.setBufferSize() method. However, WebLogic would not accept that command because the response had already started. Does anyone know of a way to configure the default response buffer size in WebLogic?

我尝试使用 response.setBufferSize() 方法增加响应缓冲区大小。但是,WebLogic 不会接受该命令,因为响应已经开始。有谁知道在 WebLogic 中配置默认​​响应缓冲区大小的方法?

Below is a simplified version of the code. I did try adding out.flush(), but to no avail. Is there something missing that would cause a problem with WebLogic but not Tomcat?

下面是代码的简化版本。我确实尝试添加 out.flush(),但无济于事。是否缺少会导致 WebLogic 出现问题而不是 Tomcat 问题的内容?

//----

//----

File file = new File(mFileName);
int fileLength = file.length();
response.setContentLength(fileLength);
response.setContentType(contentType);

OutputStream out = response.getOutputStream();

FileInputStream in = new FileInputStream(mFileName);

byte[] buf = new byte[1024];
int count = 0;

while ((count = in.read(buf)) >= 0) {

    out.write(buf, 0, count);
}

in.close();

out.close();

//----

//----

Thank you.

谢谢你。

Regards

问候

Brett S

布雷特

The full stack trace is:

完整的堆栈跟踪是:

####<3/11/2009 09:52:20 AM EST> <Error> <HTTP> <nmi02> <cgServer> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1257202340094> <BEA-101019> <[weblogic.servlet.internal.WebAppServletContext@8615a2 - appName: '_workshop_auto_generated_ear_', name: '/', context-path: ''] Servlet failed with IOException
java.net.ProtocolException: Exceeded stated content length of 2228
 at weblogic.servlet.internal.ChunkOutput.writeStream(ChunkOutput.java:411)
 at weblogic.servlet.internal.ChunkOutputWrapper.writeStream(ChunkOutputWrapper.java:168)
 at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:498)
 at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:486)
 at weblogic.servlet.FileServlet.sendFile(FileServlet.java:407)
 at weblogic.servlet.FileServlet.doGetHeadPost(FileServlet.java:231)
 at weblogic.servlet.FileServlet.service(FileServlet.java:170)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
 at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226)
 at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124)
 at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
 at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
 at com.nminnovation.nmf.images.ConverterFilter.doFilter(ConverterFilter.java:98)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
 at com.nminnovation.nmf.util.CacheControlFilter.doFilter(CacheControlFilter.java:50)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
 at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3368)
 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
 at weblogic.security.service.SecurityManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;Lweblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedAction;)Ljava.lang.Object;(Unknown Source)
 at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2117)
 at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2023)
 at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1359)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)

回答by user201372

Thanks for your reply Jim.

感谢您的回复吉姆。

The solution was to remove response.setContentLength() then add response.flushBuffer()

解决方案是删除 response.setContentLength() 然后添加 response.flushBuffer()

File file = new File(mFileName);
int fileLength = file.length();
//removed this line:
//response.setContentLength(fileLength);
response.setContentType(contentType);

OutputStream out = response.getOutputStream();

FileInputStream in = new FileInputStream(mFileName);            
byte[] buf = new byte[ fileLength ];
int count = 0;
while ((count = in.read(buf)) >= 0) {
    out.write(buf, 0, count);
}
in.close();
out.close();
//and added this line:
response.flushBuffer();

Thanks again.

再次感谢。

Regards Brett S

问候布雷特 S

回答by Jim Garrison

A Google search for

谷歌搜索

weblogic "Exceeded stated content length"

turns up a number of hits, the most interesting of which is here.

出现了许多热门歌曲,其中最有趣的是这里

In summary, try doing response.resetBuffer()after setting the content-length.

综上所述,response.resetBuffer()在设置content-length后尝试做。