You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Savino, Matt C" <Ma...@questdiagnostics.com> on 2002/01/03 18:32:19 UTC

Servlet called multiple times solved

Thanks to David Frankson and the other members of this board, I have finally
fully solved the problem with IE calling FOP two or three times problem. The
first solution came from this:

http://support.microsoft.com/support/kb/articles/Q293/7/92.ASP

But if you read the fine print, you notice that IE only uses
user-agent=contype on the second hit. That still leaves the first and third
hits calling FOP. There are some clues to tell the difference betweent the
first and third hits, so I was trying to only return the full PDF on the
third hit. The problem is that IE sometimes decides to be content with only
one hit, and sometimes it decides to make all three. There is no apparent
rhyme or reason to this decision. If you only return the content-type on the
first call when IE has decided to only make one call it just sits there.
Anyway, the second part of the solution was to cache the PDF byte-array in
the user's session and return it on any subsequent hits on the first pass.
As a key to test that the PDFs are truly the same, I use a counter in the
query string which is the time in milliseconds. 

Anyway here's the code. As usual there's a bunch of extra stuff, but I
figure it may help. Please ask if you have any questions.

-Matt

 <<ReportGeneratorServlet.java>> 

RE: Servlet called multiple times solved

Posted by Jim Urban <ji...@netsteps.net>.
That works great for the way you are calling FOP.  However, I am using the
new improved method for calling FOP (see below).  Do you have a way of
handling the duplicate calls which will work with this implementation?

Thanks,
Jim

	public void renderFO(Transformer pdfTransformer, Source iInputSource,
HttpServletResponse uResponse)
		throws java.io.IOException
	{
		try
		{
			// -------
			// Clear the output buffer completely before attempting to return a PDF
			// -------
			mHttpServletResponse.reset();
			// -------
			// Get the response output stream. and set the content type to PDF
			// -------
			OutputStream out = uResponse.getOutputStream();
			uResponse.setContentType("application/pdf");

			// -------
			// Create a FOP driver, set the logger,
			// set the ouput mode to PDF and set the output stream.
			// -------
			Driver driver = new Driver();
			driver.setLogger(mLogger);
			driver.setRenderer(driver.RENDER_PDF);
			driver.setOutputStream(out);
			// -------
			// Create SAXResult based on FOP Driver content handler
			// which will accept SAX events and build FOP tree
			// -------
			Result saxResult = new SAXResult(driver.getContentHandler());

			// Use the Transformer to transform an XML Source and
			// send the output to a Result object. Implicitely it will
			// create the FOP tree by firing SAX events.
			pdfTransformer.transform(iInputSource, saxResult);

			// The user is already viewing the PDF!
			out.flush();
			out.close();
		}
		catch (TransformerException e)
		{
			System.err.println("Unable to generate PDF:  " + e.toString());
		}
	}




-----Original Message-----
From: Savino, Matt C [mailto:Matt.C.Savino@questdiagnostics.com]
Sent: Thursday, January 03, 2002 11:32 AM
To: 'fop-dev@xml.apache.org'
Subject: Servlet called multiple times solved


Thanks to David Frankson and the other members of this board, I have finally
fully solved the problem with IE calling FOP two or three times problem. The
first solution came from this:

http://support.microsoft.com/support/kb/articles/Q293/7/92.ASP

But if you read the fine print, you notice that IE only uses
user-agent=contype on the second hit. That still leaves the first and third
hits calling FOP. There are some clues to tell the difference betweent the
first and third hits, so I was trying to only return the full PDF on the
third hit. The problem is that IE sometimes decides to be content with only
one hit, and sometimes it decides to make all three. There is no apparent
rhyme or reason to this decision. If you only return the content-type on the
first call when IE has decided to only make one call it just sits there.
Anyway, the second part of the solution was to cache the PDF byte-array in
the user's session and return it on any subsequent hits on the first pass.
As a key to test that the PDFs are truly the same, I use a counter in the
query string which is the time in milliseconds.

Anyway here's the code. As usual there's a bunch of extra stuff, but I
figure it may help. Please ask if you have any questions.

-Matt

 <<ReportGeneratorServlet.java>>


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org