Export a PDF file from a servlet ATG: IllegalStateException: response already committed

Question of high level

"When a servlet in my servlet pipeline ATG wrote a PDF document to the HTTP response output stream, well that the PDF file is delivered to the browser of the client user successfully, an error is recorded on the server: Servlet failed with Exception java.lang.IllegalStateException: response already committed."  Why does this happen?

Details

My ATG 10.1.2 application needs to be able to generate and return a PDF document to the client browser when the user clicks on a particular button on the site.

Although I don't know if it is a best practice of the ATG, the approach that I landed on this is to insert a new custom servlet, 'PdfExportServlet', in the pipeline of servlet ATG.  The PdfExportServlet, for the applications it considers PDF application and decides to manage, generates the PDF content (using Jasper reports engine) and writes the PDF content to the HTTP response output stream.  Here's the relevant part of the code:

response.setContentType("application/pdf");

// (... The code that generates a JasperPrint object with the PDF content...)

final byte [] pdfBinaryContent = JasperExportManager.exportReportToPdf (jasperPrint);

response.setContentLength (pdfBinaryContent.length);

final ServletOutputStream outputStream = response.getOutputStream ();

outputStream.write (pdfBinaryContent);

outputStream.flush ();

outputStream.close ();

It works very well, and the PDF file is displayed in the client browser.  However, a mistake is also recorded in the log file of the application on the server:

[< WL-101020 > < [path of the module: shop ServletContext@1369332778[app:storeFront: / shop spec-version: 2.5]] Servlet failed with Exception

java.lang.IllegalStateException: response already committed

at weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(ServletResponseImpl.java:1631)

at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:637)

at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:602)

at weblogic.servlet.FileServlet.findSource(FileServlet.java:269)

at weblogic.servlet.FileServlet.doGetHeadPost(FileServlet.java:191)

at weblogic.servlet.FileServlet.service(FileServlet.java:173)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

to weblogic.servlet.internal.StubSecurityHelper$ ServletServiceAction.run (StubSecurityHelper.java:227)

at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)

at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)

at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)

at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)

at atg.servlet.GenericFilterService.doFilterChain(GenericFilterService.java:621)

....

One frustrating thing about this error that had made it difficult to solve, is that it does not occur on my PC; local development this log message appears only when the application is running on one of our servers of pre-production or production.  This made try scan multiple possible solutions that are problematic, because every change to the code requires a fresh deployment to our shared, pre-production server which takes time.

I tried the following variations on the above code, or resulting in a change in the manifestation of the question (the error message that appears in the log):

  1. After the call to outputStream.close (), on the theory that it may help prevent the servlets downstream demand has already been posted, and no other attempts to modify and validate the request should be made added a call to response.flushBuffer ().
  2. Removed calls to outputStream.flush () and outputStream.close (), on the theory that some members of servlet (TailPipelineServlet?) downstream pipeline may be responsible for closing the outputStream, and try to do it prematurely was responsible for the mistake.

I also have so far have not found anything relevant in the documentation of the ATG/Oracle may provide a clue as to what is happening here, or what general best practices about having a custom servlet in the ATG pipeline that generates output to outputStream of the answer.

All the tips about the cause of this error, or what needs to be done to resolve this would be welcome!

Thank you

-Jon

I figured out the call to outputStream.write () is originally the HttpServletResponse to commit, because the size of the buffer of the ServletResponse is less than the size of my PDF data Byte.  Reference: ServletResponse (Java EE 6)

However, when I let my servlet to return with the HttpServletResponse in a State that is not validated, the client browser gets served a 404 instead of the PDF data.  I am currently looking into this issue.

Tags: Oracle Applications

Similar Questions

Maybe you are looking for

  • HP-15f039wm: need help to find the driver

    I got lost. need help finding the (USB) Universal Serial Bus controller. would be very grateful for help.

  • Drain the Iphone 6s battery

    Good afternoon! My iphone 6s this drain the battery. The battery is only lasting six hours without use. What should I do to solve this problem. NOTE: Sorry I'm using google translator.

  • HP 6700 Premium: Behavior strange scan

    Machine has worked perfectly for almost two years.  It still prints perfectly.  BUT, I just returned from a two week trip, & now, whenver I go to scan, he asked me to do an installation of the printer, and I have to re - enter the router IP address e

  • Variants: How to assign a new value without alteration/losing its attributes?

    Hello I work with data varying with some metadata stored as attributes. Data values change frequently, but the metadata values are fairly constant. I am looking for a way to update the value of a Variant while preserving its attributes (or equivalent

  • Cannot delete the files read-only on display

    Hello I copied files from my PC to the view, but when they were on the PC, they were marked read-only. Now, I found that I can't remove them from the sandisk as it says that they are read-only. How do I change the properties of the files so I can del