You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Nate Ashford <na...@ashfordconsulting.com> on 2002/10/18 19:31:11 UTC

Initializing FOP in a Servlet

I am able to run FOP fine if I embed it in a standalone console
application, but if I embed it in a Servlet, I get the following error
the first time I hit the servlet:

java.lang.NullPointerException
	at org.apache.fop.apps.Service.providers(Unknown Source)
	at org.apache.fop.apps.Driver.setupDefaultMappings(Unknown Source)
	at org.apache.fop.apps.Driver.(Unknown Source)
	at org.apache.fop.apps.Driver.(Unknown Source)
	...

Most bizarre is the fact that FOP then seems to run fine if I hit the
servlet a second time.

Does anyone know how I can get it to initialize right? I know I could
just trap the exception and retry, but that's really not the Right way
to do it.

--Nate


Re: Initializing FOP in a Servlet

Posted by Oleg Tkachenko <ol...@multiconn.com>.
xavier gibouin wrote:

> As <xsl:import> is a high level tag, how can i do  :
>  
> <xsl:for each ..>
>     <xsl:import...>
> </xsl:for-each>

You cannot, import is compile-time instruction. Usual approach is 
2-stage transformation, on first one you generate xsl stylesheet using
<xsl:for-each...>
	<outxsl:import ...
and on the second stage you apply this generated stylesheet.

PS. I should note again it's offtopic here, having xslt questions you 
can find much greater assistance in xsl-list at 
http://www.mulberrytech.com/xsl/xsl-list.
-- 
Oleg Tkachenko
eXperanto team
Multiconn International, Israel


Re: Initializing FOP in a Servlet

Posted by xavier gibouin <xa...@axonie.com>.
hi,

As <xsl:import> is a high level tag, how can i do  :

<xsl:for each ..>
    <xsl:import...>
</xsl:for-each>

thanks

Xavier Gibouin
Axonie
Espace Mercoeur
8, rue Mercoeur
44000 Nantes
02.40.48.53.23
xavier.gibouin@axonie.com

Re: Initializing FOP in a Servlet

Posted by Nate Ashford <na...@ashfordconsulting.com>.
On Fri, 2002-10-18 at 17:28, Oleg Tkachenko wrote:
> Nate Ashford wrote:
> 
> > Does anyone know how I can get it to initialize right? I know I could
> > just trap the exception and retry, but that's really not the Right way
> > to do it.
> Usual leading questions go:
> 1. Which fop version are you talking about?

0.20.4

> 2. How did you embed fop?

Driver driver = new Driver(inputSource, fopOut);
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
MessageHandler.setScreenLogger(logger);
driver.setLogger(logger);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();

> 3. Turn on debug and provide debug trace.

I assume you are referring to setting the log level to debug, which I
have done. I get no information from FOP when the error occurs.

--Nate



Re: Initializing FOP in a Servlet

Posted by Oleg Tkachenko <ol...@multiconn.com>.
Nate Ashford wrote:

> Does anyone know how I can get it to initialize right? I know I could
> just trap the exception and retry, but that's really not the Right way
> to do it.
Usual leading questions go:
1. Which fop version are you talking about?
2. How did you embed fop?
3. Turn on debug and provide debug trace.

-- 
Oleg Tkachenko
eXperanto team
Multiconn International, Israel


Re: Initializing FOP in a Servlet

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Nate Ashford wrote:
> I get this with both Tomcat 4.0.3 and Tomcat 4.0.6.

I was under the impression it was a last minute fix in 4.0.4,
but this may be a misunderstanding.
Please ask on the tomcat list under which circumstances it
is possible to get a null class loader. Unfortunately, the
problem report omitted the details. It might help to mention
Bug #10255.
For a more immediate solution, it often helps to move the webapp
jars into tomcat's lib directory.

J.Pietschmann


Re: Initializing FOP in a Servlet

Posted by John Gentilin <ge...@eyecatching.com>.
In my case, the FOP calls are in a class that supports my ReportEngine
interface. That way I can plug-in different report engines. When I am
loading report engines, I use the Context Classloader to create a new
instance. Since the class loader was specified for the engine class, maybe
it effects the class loading for Driver class that gets instantiated in the engine

class. What does not make sense is the, it works the second time issue.
Can you run it in your IDE ?? JBuilder puts all the required libraries in the
System classpath and runs the class directly. If it runs fine in the IDE but
not when you just run Tomcat, it is most likely a Context Classloader issue.

The code is below.

ClassLoader ldr = Thread.currentThread().getContextClassLoader();
Class cls = getClass().forName(name, true, ldr);
eng = (ReportEngine) cls.newInstance();

Regards
John G

Nate Ashford wrote:

> I get this with both Tomcat 4.0.3 and Tomcat 4.0.6.
>
> On Mon, 2002-10-21 at 09:03, John Gentilin wrote:
> > I just did this in Tomcat 3.3.1 this weekend with no problem.
> > What Servlet engine are you using ??
> >
> > "J.Pietschmann" wrote:
> >
> > > Nate Ashford wrote:
> > > > I am able to run FOP fine if I embed it in a standalone console
> > > > application, but if I embed it in a Servlet, I get the following error
> > > > the first time I hit the servlet:
> > > >
> > > > java.lang.NullPointerException
> > > >       at org.apache.fop.apps.Service.providers(Unknown Source)
> > > >       at org.apache.fop.apps.Driver.setupDefaultMappings(Unknown Source)
> > > >       at org.apache.fop.apps.Driver.(Unknown Source)
> > > >       at org.apache.fop.apps.Driver.(Unknown Source)
> > > >       ...
> > > >
> > > > Most bizarre is the fact that FOP then seems to run fine if I hit the
> > > > servlet a second time.
> > > >
> > > > Does anyone know how I can get it to initialize right? I know I could
> > > > just trap the exception and retry, but that's really not the Right way
> > > > to do it.
> > >
> > > This is probably a classloader problem which has been filed in
> > > Bugzilla, FOP gets a null class loader from the servlet container.
> > > Ask the servlet container vendor (probably Tomcat 4.0.x x>=4) for
> > > a solution (they wont like it, because its presumably a security fix,
> > > so be persistent).
> > >
> > > J.Pietschmann
> >
> > --
> > --------------------------------------
> > John Gentilin
> > Eye Catching Solutions Inc.
> > 18314 Carlwyn Drive
> > Castro Valley CA 94546
> >
> >     Contact Info
> > gentijo@eyecatching.com
> > Ca Office 1-510-881-4821
> > NJ Office 1-732-422-4917
> >
> >

--
--------------------------------------
John Gentilin
Eye Catching Solutions Inc.
18314 Carlwyn Drive
Castro Valley CA 94546

    Contact Info
gentijo@eyecatching.com
Ca Office 1-510-881-4821
NJ Office 1-732-422-4917




Re: Initializing FOP in a Servlet

Posted by Nate Ashford <na...@ashfordconsulting.com>.
I get this with both Tomcat 4.0.3 and Tomcat 4.0.6.

On Mon, 2002-10-21 at 09:03, John Gentilin wrote:
> I just did this in Tomcat 3.3.1 this weekend with no problem.
> What Servlet engine are you using ??
> 
> "J.Pietschmann" wrote:
> 
> > Nate Ashford wrote:
> > > I am able to run FOP fine if I embed it in a standalone console
> > > application, but if I embed it in a Servlet, I get the following error
> > > the first time I hit the servlet:
> > >
> > > java.lang.NullPointerException
> > >       at org.apache.fop.apps.Service.providers(Unknown Source)
> > >       at org.apache.fop.apps.Driver.setupDefaultMappings(Unknown Source)
> > >       at org.apache.fop.apps.Driver.(Unknown Source)
> > >       at org.apache.fop.apps.Driver.(Unknown Source)
> > >       ...
> > >
> > > Most bizarre is the fact that FOP then seems to run fine if I hit the
> > > servlet a second time.
> > >
> > > Does anyone know how I can get it to initialize right? I know I could
> > > just trap the exception and retry, but that's really not the Right way
> > > to do it.
> >
> > This is probably a classloader problem which has been filed in
> > Bugzilla, FOP gets a null class loader from the servlet container.
> > Ask the servlet container vendor (probably Tomcat 4.0.x x>=4) for
> > a solution (they wont like it, because its presumably a security fix,
> > so be persistent).
> >
> > J.Pietschmann
> 
> --
> --------------------------------------
> John Gentilin
> Eye Catching Solutions Inc.
> 18314 Carlwyn Drive
> Castro Valley CA 94546
> 
>     Contact Info
> gentijo@eyecatching.com
> Ca Office 1-510-881-4821
> NJ Office 1-732-422-4917
> 
> 



Re: Initializing FOP in a Servlet

Posted by John Gentilin <ge...@eyecatching.com>.
I just did this in Tomcat 3.3.1 this weekend with no problem.
What Servlet engine are you using ??

"J.Pietschmann" wrote:

> Nate Ashford wrote:
> > I am able to run FOP fine if I embed it in a standalone console
> > application, but if I embed it in a Servlet, I get the following error
> > the first time I hit the servlet:
> >
> > java.lang.NullPointerException
> >       at org.apache.fop.apps.Service.providers(Unknown Source)
> >       at org.apache.fop.apps.Driver.setupDefaultMappings(Unknown Source)
> >       at org.apache.fop.apps.Driver.(Unknown Source)
> >       at org.apache.fop.apps.Driver.(Unknown Source)
> >       ...
> >
> > Most bizarre is the fact that FOP then seems to run fine if I hit the
> > servlet a second time.
> >
> > Does anyone know how I can get it to initialize right? I know I could
> > just trap the exception and retry, but that's really not the Right way
> > to do it.
>
> This is probably a classloader problem which has been filed in
> Bugzilla, FOP gets a null class loader from the servlet container.
> Ask the servlet container vendor (probably Tomcat 4.0.x x>=4) for
> a solution (they wont like it, because its presumably a security fix,
> so be persistent).
>
> J.Pietschmann

--
--------------------------------------
John Gentilin
Eye Catching Solutions Inc.
18314 Carlwyn Drive
Castro Valley CA 94546

    Contact Info
gentijo@eyecatching.com
Ca Office 1-510-881-4821
NJ Office 1-732-422-4917




Re: Initializing FOP in a Servlet

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Nate Ashford wrote:
> I am able to run FOP fine if I embed it in a standalone console
> application, but if I embed it in a Servlet, I get the following error
> the first time I hit the servlet:
> 
> java.lang.NullPointerException
> 	at org.apache.fop.apps.Service.providers(Unknown Source)
> 	at org.apache.fop.apps.Driver.setupDefaultMappings(Unknown Source)
> 	at org.apache.fop.apps.Driver.(Unknown Source)
> 	at org.apache.fop.apps.Driver.(Unknown Source)
> 	...
> 
> Most bizarre is the fact that FOP then seems to run fine if I hit the
> servlet a second time.
> 
> Does anyone know how I can get it to initialize right? I know I could
> just trap the exception and retry, but that's really not the Right way
> to do it.

This is probably a classloader problem which has been filed in
Bugzilla, FOP gets a null class loader from the servlet container.
Ask the servlet container vendor (probably Tomcat 4.0.x x>=4) for
a solution (they wont like it, because its presumably a security fix,
so be persistent).

J.Pietschmann