Forum Bugs

java example using input and output streams

gjardine
Whats the correct way to obtain the input/ouput streams for the convert method? The html is generated dynamically from jsp's. I'm trying to capture the response befor sending it and then converting it to PDF.


HttpServletResponse httpResponse = (HttpServletResponse) (response);
responseWrapper = Response.getResponse(httpResponse);

ByteArrayInputStream bais = new ByteArrayInputStream(responseWrapper.getData());
ByteArrayOutputStream baos = new ByteArrayOutputStream();

convert(bias,baos)
outputBytes = baos.toByteArray();

...setting content type headers
then:

OutputStream outStream = httpResponse.getOutputStream()
outStream.write(outputBytes);
outStream.flush();

The convert method's return status is true and I can write a PDF file to disk
from the baos. Can't output the contents to the browser

thanks
mikeday
What is the responseWrapper class that you are using?
gjardine
Hi,

it extends HttpServletResponseWrapper. The call to getData() returns a byte[] from the byteStream.
mikeday
It seems that this is not an issue with Prince as such, but an issue with the servlet wrapper / filtering setup that you have got, which is difficult to debug from the fragment of code provided.

Since you are able to capture the output from your JSP and pass it to Prince to get a PDF, what happens when you try to write that PDF to the servlet output stream to return it to the browser? Do you get an exception on the Java side, or do you get an unexpected response on the client side?