Hi,
I have an xsl file that includes an external image:
<fo:external-graphic src="/images/BrandGraphic.PNG"/>
When running as a standalone Java application the transformer.transform
function works, and I get a valid PDF file.
When running in Tomcat/OSGI, on the same server (same JRE), I get the
following error:
FATAL ERROR: 'java.lang.IllegalArgumentException: Unknown function:
gatherContextInfo'
:Unknown function: gatherContextInfo
If I remove the image from the XSL, everything works.
I checked in the fop 1.0 source, and see that this comes from
org.apache.fop.util.text.AdvancedMessageFormat
public FunctionPart(String functionName) {
this.function = getFunction(functionName);
if (this.function == null) {
throw new IllegalArgumentException("Unknown function: " +
functionName);
}
}
Unfortunately no stack trace is output when catching this exception, and
tracing back through the code I can see various places from where this
could have got called.
the 'gatherContextInfo' function itself is in
org.apache.fop.fo.FONode.java, and is overridden in sub-classes.
On the class-loading side, I've verified that the same jars are loaded in
both tomcat and standalone. The following are the ones that I find are
essential for my transform to work:
avalon, batik, commons-io, commons-logging, xmlgraphics.
On tomcat there are many more libraries loaded, but the only overlap I can
see is commons-logging, where my war file already uses a different version
of this.
I have asked the same question on stackoverflow:
https://stackoverflow.com/questions/27066409/apachefop-tomcat-osgi-error-java-lang-illegalargumentexception-unknown-functio
, but I haven't get much response beyond what I'd already looked at so
far.
One other issue I found running FOP in Tomcat/OSGI, was the need to
override the PDF renderer, with this code:
FOUserAgent useragent = fopFactory.newFOUserAgent();
PDFRenderer pdfrenderer = new PDFRenderer();
pdfrenderer.setUserAgent(useragent);
useragent.setRendererOverride(pdfrenderer);
fopFactory.addElementMapping(new FOElementMapping());
...
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, useragent, out);
otherwise the code would fail with:
Caused by: java.lang.UnsupportedOperationException: Don't know how to
handle "application/pdf" as an output format. Neither an FOEventHandler,
nor a Renderer could be found for this output format.
at
org.apache.fop.render.RendererFactory.createFOEventHandler(RendererFactory.java:360)
Does anyone have any idea what could be going wrong here?
Best Regards,
Iain
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU