Xalan Transformer factory not found in JBoss eap 6.1 - jboss

We have an ear application with a singleton ejb which sets up JAXP configuration.
We set the TransformerFactory system property via code, with System.setProperty():
System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
The jboss-deployment-structure.xml file content is the following:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment>
<dependencies>
<module name="org.apache.xalan" slot="main" export="true"/>
<module name="org.apache.xerces" slot="main" export="true" />
</dependencies>
</deployment>
</jboss-deployment-structure>
we got the exception:
Exception in thread "main" javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
If I use the following line of code instead of setting the system property, it works.
TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", TransformerFactory.class.getClassLoader());
I would like to know why it doesn't work.
Do I misunderstand something about JBoss modules class loading?

Related

Exclude static httpcomponent module without excuding resteasy from JBoss EAP 7.1

I need to exclude default httpcomponent module from my application, but I also use restasy and don't want to exclude or broke it. For httpcomponent I want to use versions from dependencies in my project. Is it possible with JBoss EAP 7.1?
Version of modules in jboss :
jackson-databind-2.8.9.redhat-1
jackson-core-2.8.9.redhat-1
jackson-annotations-2.8.9.redhat-1
I've tried to add to jboss-deployment-structure.xml this config but it didn't help:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.httpcomponents" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
</exclusions>
<dependencies>
</dependencies>
</deployment>
</jboss-deployment-structure>
It should work, I can provide you a tested example (I've excluded the jettinson provider for my web app):
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
I see only modules in your question, do you have the correct deployment -> exclusions structure?
If you need a list of JBoss EAP 7 modules, go here.

loading shared native modules from ear file than from web apps in JBoss environment

There is a jar which loads native libraries .so files. This jar is available as a jboss module on the server. Native files can be loaded only once per classloader.
There are two war modules war1, war2 inside an ear1 file. if the module is configured as jboss module in both war1 & war2, I have no issues. But I am looking for an alternative where if i configure the jar which is loading the native library in the earfile/lib and the war refers from there, does that work. That particular class should load only once and shoudl be available in both the war files.
Solution:
We need to add sub-deployment section to the jboss deployment xml file inside ear/Meta-INF folder. That way the jboss module can be made available to all other submodules/war modules.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.aexp.sec.crypto" export="TRUE" />
</dependencies>
</deployment>
<sub-deployment name="crypto-war1-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
<sub-deployment name="crypto-war2-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Note: For the Benefits of the future users, adding the solution of #Vamshidhar Cheburthy below,
We need to add sub-deployment section to the JBoss deployment XML file inside ear/Meta-INF folder. That way the JBoss module can be made available to all other submodules/war modules.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.aexp.sec.crypto" export="TRUE" />
</dependencies>
</deployment>
<sub-deployment name="crypto-war1-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
<sub-deployment name="crypto-war2-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>

wsdl file not deployed in jboss eap 7

I have been trying to migrating from jboss eap 5.1 to jboss eap 7. My .war file has been deployed successfully but not my .wsdl file. I have used jboss-deployment-structure.xml with the below code:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclude-subsystems>
<subsystem name="webservices" />
</exclude-subsystems>
<exclusions>
<module name="javaee.api" />
<module name="javax.ws"/>
</exclusions>
<dependencies>
<module name="javax.jws.api" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Is there anything I have missed out?

Excluding httpclient/httpcore in jboss-deployment-structure

I recently updated apache httpclient to 4.5.1 and httpcore to 4.4.4, but for some reason my Jboss server has older versions of both (4.3.6). I'm pulling in the new versions via ivy, but they seem to be getting overwritten by the versions on the server. I've tried making my own jboss-deployment-structure.xml file, but it doesn't seem to be working and the documentation is scarce on exactly how this piece functions. At what level of specificity do I need to be blocking modules to prevent jboss loading dependencies that override ivy?
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.slf4j" />
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.apache.httpcomponents" />
</exclusions>
<dependencies>
<module name="org.codehaus.jackson.jackson-core-asl" />
<module name="org.codehaus.jackson.jackson-mapper-asl" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Progress update: looks like the application relies on jaxrs and xalan, which in turn pull in the dependencies. ugh.
From the hibernate 3 jboss-eap-quickstarts:
<exclusions>
<!-- Exclude container version of hibernate. By default its version 4, we want
bundled version 3 loaded -->
<module name="org.hibernate" slot="main" />
</exclusions>
In your build for your application in the dependencies that pull in jaxrs and xalan set the scope of httpclient and httpcore to provided.

Why does my JBoss module throw a ClassCastException?

Hi StackOverflow Community,
I have a WAR which I have deployed to a JBoss Wildfly 8.2 instance. Also in Wildfly, I have created two modules:
a third party JMS JCA adapter module,
and a model module (model.jar) that contains message classes used to communicate between the JMS broker and the WAR
The WAR has a jboss-deployment-structure.xml that declares a dependency on the JCA module:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="com.thirdparty.mq.ra" slot="main"/>
<module name="com.company.model" slot="main">
</dependencies>
</deployment>
</jboss-deployment-structure>
The WAR has the model.jar file packaged in its WEB-INF/lib folder.
The JMS module has a dependency on the model module:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.thirdparty.mq.ra">
<resources>
<resource-root path="."/>
<resource-root path="thirdparty-jms-provider.jar"/>
...
<resource-root path="thirdparty-lib.jar"/>
</resources>
<dependencies>
<module name="com.company.model"/>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.transaction.api"/>
<module name="javax.management.j2ee.api"/>
<module name="javax.resource.api"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.remote-naming" optional="true"/>
<module name="org.slf4j"/>
</dependencies>
</module>
When running, I get the following exception:
Caused by: java.lang.ClassCastException: com.company.model.web.dto.WebAuthenticationResponse cannot be cast to com.company.model.web.dto.WebAuthenticationResponse
I suspect it is a classloader issue. Is there some extra information I have to specify in the module.xml or jboss-deployment-structure.xml files?
Thanks for your help!
Assuming that your model.jar corresponds to your com.company.model module, your WAR classloader now sees the model classes twice, both from its own libraries in WEB-INF/lib and via the module dependency.
You should either import or embed a module/library, but not both.
By the way, importing a RAR module looks a bit suspicious. You should never depend on the implementation of a resource adapter. Maybe you can factor out an API module and import that.