title: WebLogic "Exceeded stated content length" Error
body: <p>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.</p>
  
  <p>The servlet filter resizes images. This error is occurring then writing the contents a FileInputStream (from disk) to response.getOutputStream() :</p>
  
  <p><strong>java.net.ProtocolException: Exceeded stated content length of 2228
   at weblogic.servlet.internal.ChunkOutput.writeStream(ChunkOutput.java:411)</strong></p>
  
  <p>See the end of this message for the full stack trace.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>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?</p>
  
  <p>//----</p>
  
  <pre><code>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)) &gt;= 0) {
  
      out.write(buf, 0, count);
  }
  
  in.close();
  
  out.close();
  </code></pre>
  
  <p>//----</p>
  
  <p>Thank you.</p>
  
  <p>Regards</p>
  
  <p>Brett S</p>
  
  <p>The full stack trace is:</p>
  
  <pre><code>####&lt;3/11/2009 09:52:20 AM EST&gt; &lt;Error&gt; &lt;HTTP&gt; &lt;nmi02&gt; &lt;cgServer&gt; &lt;[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'&gt; &lt;&lt;WLS Kernel&gt;&gt; &lt;&gt; &lt;&gt; &lt;1257202340094&gt; &lt;BEA-101019&gt; &lt;[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)
  </code></pre>