I created a servlet filter to convert HTML returned by a servlet (or JSP) into PDF. This filter used the standard mechanism of passing along a fake HttpServletResponse that captures the output to memory – so that that HTML output can be rendered to PDF before being sent back to the client.
This worked fine in Tomcat, but in Weblogic 8.1 I started getting a ServletException: “Original response not available.” According to this post, it’s because Weblogic is checking the HttpServletResponse at some point, and expects either an instance of its *own* HttpServletResponse implementation, or else a HttpServletResponseWrapper with a Weblogic instance as the original response.
Update: Unfortunately, that post’s suggestions aren’t enough to fix it. If you do a forward (i.e. to a JSP), WebLogic checks to make sure the request is its own implementation (i.e. and not a filter). So it doesn’t seem like you can filter non-servlets in WebLogic 8.1.
The workaround I finally ended up using was to implement a servlet that renders the HTML using Freemarker instead of JSP, captures it directly, and sends it to the PDF converter. This is probably a better design, ultimately, than tricking the J2EE application into thinking it’s writing out to the client when it’s really not. The fact that JSP is so tightly bound to the J2EE application stack is one good reason to choose a different templating technology, like Freemarker. You can call it from wherever you like and write its output wherever you like, including an in-memory byte array, so it gives you a lot more flexibility.