Translet class loaded, but unable to create translet instance

54 Views Asked by At

I use this piece of code to do a XSL-FO transformation with FOP:

    protected static void transformTo(Result result, Source src, String mimeFormat, String sFileNameXsl)
            throws FOPException {
        try {
            TransformerFactory factory = TransformerFactory.newInstance("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", ClassLoader.getSystemClassLoader());
            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");

            File myXslFile = new File(sFileNameXsl);
            StreamSource xsltSource = new StreamSource(myXslFile);
            Transformer transformer = factory.newTransformer(xsltSource);
            transformer.setParameter("fop-output-format", mimeFormat);
            transformer.transform(src, result);
        } catch (Exception e) {
            throw new FOPException(e);
        }
    }

It works fine by itself but as soon as it runs on a JBoss server, it breaks with the following error on the call to newTransformer.

javax.xml.transform.TransformerConfigurationException: Translet class loaded, but unable to create translet instance.
    at com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.defineTransletClasses(TemplatesImpl.java:437)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.getTransletInstance(TemplatesImpl.java:451)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.newTransformer(TemplatesImpl.java:486)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:762)

The code is a secured version of an original unsafe code that used to work even on JBoss environment :

    protected static void transformTo(Result result, Source src, String mimeFormat, String sFileNameXsl)
            throws FOPException {
        try {
            TransformerFactory factory = TransformerFactory.newInstance();

            File myXslFile = new File(sFileNameXsl);
            StreamSource xsltSource = new StreamSource(myXslFile);
            Transformer transformer = factory.newTransformer(xsltSource);
            transformer.setParameter("fop-output-format", mimeFormat);
            transformer.transform(src, result);
        } catch (Exception e) {
            throw new FOPException(e);
        }
    }

In JBoss context, before executing newTransformer, the expression :

Thread.currentThread().getContextClassLoader()

evaluates to :

ModuleClassLoader for Module "deployment.myserver.war:main" from Service Module Loader

My jboss-deployment-structure.xml looks like :

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <module name="org.jboss.as.server" />
            <module name="org.jboss.as.controller" />
            <module name="org.jboss.xnio" />
            <module name="org.jboss.remoting3" />
            <module name="org.jboss.security.negotiation" />
        </dependencies>
        <exclusions>
            <module name="org.apache.log4j" />
            <module name="org.apache.commons.logging" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>
0

There are 0 best solutions below