XSL FO在JBOSS AS 7中无法进行XSLT转换

时间:2013-09-24 00:03:47

标签: java xslt jboss7.x xsl-fo

我有以下代码

SAXTransformerFactory stfactory;
stfactory = (SAXTransformerFactory) TransformerFactory.newInstance();

/// ClassLoaderUriResolver is another class.
 stfactory.setURIResolver(new ClassLoaderUriResolver()); 

 InputStream is = this.getClass().getClassLoader().getResourceAsStream("xsl/Hello.xsl");
 StreamSource streamSource = new StreamSource(is);

  mergeHandler = stfactory.newTransformerHandler(streamSource);

 XMLReader xmlReader = XMLReaderFactory.createXMLReader();

还有一些代码......

问题在于此        mergeHandler = stfactory.newTransformerHandler(streamSource);

当我在JBOSS IDE中将此程序作为独立的JAVA程序运行时,使用相同的jar集

  • 的Xalan-2.7.0.jar
  • xercesImpl-2.7.1.jar
  • XML的API-1.3.04.jar
  • XML的API-EXT-1.3.04.jar

我看到调用stfactory.newTransformerHandler(streamSource);

返回
org.apache.xalan.transformer.TransformerHandlerImpl

和MY XLST翻译作为简单的java程序正常工作

在Jboss AS 7容器上运行时的相同代码 我看到调用stfactory.newTransformerHandler(streamSource);

返回
org.apache.xalan.transformer.TransformerIdentityImpl (不是TransformerHandlerImpl)

因此,当我作为Web应用程序的一部分运行Jboss AS 7 Container时,XSLT转换没有发生,我没有看到任何错误。我的XLS FO文档未翻译。

如何强制代码使用 org.apache.xalan.transformer.TransformerHandlerImpl

1 个答案:

答案 0 :(得分:2)

我得到了它的工作。

在jboss中,除了我们可以排除的模块外,还有另一个位于根C:\ jboss-eap-6.0 \ jboss-modules.jar的jar。在这个jar里面有一个名为“__redirected”的文件夹,带有一个__TransformerFactory.class类,代码如下。

Class clazz = __RedirectedUtils.loadProvider(id, javax/xml/transform/TransformerFactory, loader);

这会强制从“C:\ jboss-eap-6.0 / jboss-modules.jar”加载“org.apache.xalan.processor.TransformerFactoryImpl”

然而,这不是一个模块,所以我不能使用jboss-deployment-structure.xml排除它,尽管我已经为Xalan,Xercel和XML api排除了以下jboss模块。因为我们在EAR lib中有一个特定的罐来满足这个要求。

的JBoss部署-structure.xml

<jboss-deployment-structure xmlns:p="urn:jboss:deployment-structure:1.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <deployment>
                            <exclusions>
                                          <module name="org.apache.xerces" />
                                            <module name="org.apache.xalan" />
                                            <module name="org.apache.xml-resolver" />
                            </exclusions>

            </deployment>

所以我评论了以下代码

  stfactory = (SAXTransformerFactory) TransformerFactory.newInstance();

并添加了

  Class clazz = Class.forName("org.apache.xalan.processor.TransformerFactoryImpl");
  stfactory = (SAXTransformerFactory) clazz.newInstance();

现在我明白了

  • org.apache.xalan.processor.TransformerFactoryImpl是从C加载的:/jboss-eap-6.0/standalone/deployments/TST.ear/lib/xalan-2.7.0.jar

    < / LI>
  • 调用stfactory.newTransformerHandler(streamSource)返回“org.apache.xalan.transformer.TransformerHandlerImpl”而不是“org.apache.xalan.transformer.TransformerIdentityImpl”

所以我相信jar“C:\ jboss-eap-6.0 \ jboss-modules.jar”是类加载器的一部分,在EAR类加载器之上。所以它没有使用Xalan.2.7.0.jar作为“org.apache.xalan.processor.TransformerFactoryImpl”。但是当我们调用stfactory.newTransformerHandler(streamSource)时,它将返回“org.apache.xalan.transformer.TransformerIdentityImpl”

对于这种行为,可能存在C:\ jboss-eap-6.0 \ jboss-modules.jar中隐藏的内容。

我不明白的是在一个测试中我使用了Xalan.2.7.0.jar并在java.endorsed.dir中添加了它仍然使用C:\ jboss-eap-6.0 \ jboss-modules。 jar,这有点令人惊讶,因为我认为所支持的罐子甚至会在C:\ jboss-eap-6.0 \ jboss-modules.jar之前加载。

但是无论如何,当前的修复程序解决了这个问题,它只在Jboss应用程序服务器7上发生。代码在Webspshere 7.0中没有任何变化,也在我作为独立的java程序运行时。