Andreas Delmelle
Mon, 05 May 2008 07:56:21 -0700
On May 5, 2008, at 10:55, Andreas Schröder wrote: Hi
I already posted in the user group, but they only wonder about my error and can't help. So I think that it is a bug.I use Apache FOP 0.95beta but the same error also occured in 0.94 stable version: When trying to make a new instance of the fop factory with "FopFactory fopFactory = FopFactory.newInstance();" I get an exception with the following stack trace:java.lang.ClassCastException: org.apache.fop.render.afp.extensions.AFPExtensionHandlerFactorycannot be cast to org.apache.fop.util.ContentHandlerFactory
I dug up the earlier thread on fop-users@, and I suspect that Jörg's reply is the one that holds the key.
<quote> In a web application, this may also be happen if the AFPExtensionHandlerFactory has been loaded in a different security context , which means it is an implementation of the ContentHandlerFactory of the other context. </quote>From the stack trace, we can deduce that you create a new fopFactory instance for each run ('newInstance()' always means 'new FopFactory ();'). The original ContentHandlerFactory class has probably already been loaded when the servlet container first initialized, by the default ClassLoader (or by the ClassLoader used in the first run).
No idea how this can be verified, though. To ascertain whether this is the case, my personal first shot would be to try to set up a central fopFactory instance, which would also be loaded only once, when the webapp is first initialized. The big difference would be that you'd use that very same FopFactory for all the requests, which should eliminate the issue...
HTH! Andreas