org.springframework.ws and Xalan problem on Jboss

2019-08-30 02:53发布

问题:

Hello I'm facing problem with Jboss EAP 6.x after update org.springframework.ws - spring-xml

In my project I have use Xalan in version 2.7.2 , now I want to update org.springframework.ws - spring-xml from version 2.4.0 to 2.4.4 and upload wars of my app on Jboss EAP 6.x

While deployment I got error:

Caused by: java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalDTD at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:571) at __redirected.__TransformerFactory.setAttribute(__TransformerFactory.java:169) [jboss-modules.jar:1.3.5.Final-redhat-1] at org.springframework.xml.transform.TransformerFactoryUtils.defaultSettings(TransformerFactoryUtils.java:56) [spring-xml-2.4.4.RELEASE.jar:] at org.springframework.xml.transform.TransformerFactoryUtils.newInstance(TransformerFactoryUtils.java:32) [spring-xml-2.4.4.RELEASE.jar:] at org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping.(PayloadRootAnnotationMethodEndpointMapping.java:58) [spring-ws-core-2.4.4.RELEASE.jar:] ... 31 more

After fast investigation I have found that in spring-xml version 2.4.4 it's new TransformerFactoryUtils which uses TransformerFactory from same package as Xalan , and it's leads to problem with classloader.

I try to follow solutions from TransformerFactory and Xalan Dependency Conflict and xalan and xerces in jboss eap 6.0.1 but both won't work for me.

I have also found some solution on redhat site : https://access.redhat.com/solutions/1410603 but without subscription I don't have access for it...

And one face same issue? Maybe have some solution which may work in this case? Big thanks in advance.

回答1:

I have the same issue even for JBoss EAP 7.2

Since JBoss runs on JDK 6, 7, and 8, that is why the included Xalan does not have ACCESS_EXTERNAL_DTD support as it was added in JDK 7.

You may force JBoss to use TransformerFactory from Oracle JDK 8. Set the variable transformerFactoryClass to com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl. See the snapshot below.

final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setDefaultUri(uri);
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);

try {
    logger.debug("Getting class for name: {}", transformerFactoryClass);
    final Class<?> clazz = Class.forName(transformerFactoryClass);
    Assert.isAssignable(TransformerFactory.class, clazz, "Must be instance of Class<? extends TransformerFactory>");
    webServiceTemplate.setTransformerFactoryClass((Class<? extends TransformerFactory>) clazz);
} catch (ClassNotFoundException e) {
    logger.error("Unable to get class for name: {}", transformerFactoryClass);
    throw new IllegalArgumentException(e);
}