Meaningless Drivel is fun!*
The moose likes Websphere and the fly likes WASD 4.0.3: display pdf: WriteBeyondContentLength Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "WASD 4.0.3: display pdf: WriteBeyondContentLength" Watch "WASD 4.0.3: display pdf: WriteBeyondContentLength" New topic
Author

WASD 4.0.3: display pdf: WriteBeyondContentLength

david chan
Ranch Hand

Joined: Jun 10, 2002
Posts: 46
Hi,
I have following error when displaying PDF file to browser but it works fine in tomcat. Here is my sample code, my buffer size is usually between 50kb to 100kb, any idea?:
"<"%@ page buffer="300kb" autoFlush="false"%>
"<".%
response.setContentType("application/pdf");
byte[] buffer = (byte[])request.getAttribute("buffer");
if (buffer != null) {
int size = buffer.length;
response.setContentLength(size);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(buffer, 0, size);
ouputStream.flush();
ouputStream.close();
}
%>
========= end of code ========
I can view the PDF from browser but there is exception from my WASD 4.0.3 test environment:
[10/10/02 11:41:27:157 EDT] 1b18cea7 WebGroup X Servlet Error: : com.ibm.servlet.engine.srt.WriteBeyondContentLengthException
at com.ibm.servlet.engine.srt.BufferedServletOutputStream.write(BufferedServletOutputStream.java:285)
at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:236)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:250)
at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:233)
at _viewPDF_jsp_6._jspService(_viewPDF_jsp_6.java:109)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:142)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:300)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:430)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:565)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:167)
at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:297)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:110)
at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:523)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:282)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:112)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1014)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:417)
at org.apache.struts.action.RequestProcessor.processActionForward(RequestProcessor.java:390)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:271)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:167)
at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:297)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:110)
at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:523)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:282)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:112)
at com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:91)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:184)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:122)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
Riley Brook
Greenhorn

Joined: Oct 24, 2002
Posts: 5
Had this problem myself.
You are using JSPs to write binary content which is generally not advised (servlets preferred).
The JSPWriter will write out content when you have two <% %> <% %> scriptlet tags defined AND whatever template tags you have before, in between (carriage return, spaces, etc.), and after. So setting the content-length = size of the PDF is actually wrong since the content length would include these extra characters.
If you must do it via JSP make sure there are NO trailing spaces, at the end of your JSP and your scriplet blocks are back-to-back <% %><% %>. then your content-lenght number will be accurate.
hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WASD 4.0.3: display pdf: WriteBeyondContentLength