• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Content Length problem

 
John El
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on an upgrade to WebLogic 10.3 Portal, and I'm not too familiar with it.

I've come across an interesting problem that I hope someone here can shed some light on.

We use Jasper Reports to build some pdfs, and we send them to the browser by settting a byte[] in the session like so:

getRequest().getSession().setAttribute("report", report);

and we use several jsps like this to dump it to the browser:

<%@ page import="java.io.*, java.util.*"%>
<%
response.setContentType("application/pdf");
byte[] pdf = (byte[]) request.getSession().getAttribute("report");
request.getSession(false).removeAttribute("report");
response.setContentLength(pdf.length);
response.getOutputStream().write(pdf);
response.getOutputStream().flush();
response.getOutputStream().close();
%>


But it didn't work, I can't recall the exact error. A co-worker said to add 2 to the content length, like so:

response.setContentLength(pdf.length + 2);

It worked, no more error, work continues.

The other day I suddenly got this error (I'm making up the numbers):
java.net.ProtocolException: Didn't meet stated Content-Length, wrote: '2566' bytes instead of stated: '2568' bytes.

Exactly 2 more than the length, so I pulled the +2 out and everything was fine....but why did it complain in the first place?

Then, in another project, a similar error:
java.net.ProtocolException: Didn't meet stated Content-Length, wrote: '2567' bytes instead of stated: '2568' bytes.

This is 1 more than the length.

So what gives?
Why did we need to add 2 in the first place?
Why could we remove the +2 in one project?
Why is it writing 1 more byte than the pdf.length in another project?

What could be different across these projects that makes this difference?
What should I do? Just pull out the 'response.setContentLength(pdf.length);' and hope for the best?

Everything seems to run fine, I just get an error in the log, so I'm not too worried about it, but it is a puzzle.

Anyone have a guess?
 
John El
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick update, I've just restarted the server and the error has stopped showing up in my log.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic