JBoss Wildfly 10: xnio ClassCastException when calling EJB3.1 on JBoss 7 - java

I'm trying to remote call an EJB3.1 application on a JBoss 7 from a Wildfly 10 via JNDI.
Executing the code from a stand alone java client works perfectly well, deployed in the Wildfly, I receive a ClassCastException:
java.lang.ClassCastException: org.xnio.SingleOption cannot be cast to org.xnio.Option
Here are the properties I'm using:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=true
remote.connectionprovider.create.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connections=default
remote.connection.default.host=some.server
remote.connection.default.port=4647
remote.connection.default.connect.options.org.xnio.Options.SSL_ENABLED=true
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.clusters=ejbremote.cluster.ejb.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.cluster.ejb.connect.options.org.xnio.Options.SSL_ENABLED=true
remote.connection.default.username=user
remote.connection.default.password=password
org.jboss.ejb.client.scoped.context=true
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
Project has the jboss-as-ejb-client-bom dependency:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.2.0.Final</version>
<type>pom</type>
</dependency>
Lookup looks standard:
Context ctx = new InitialContext(properties);
Service service = (Service) ctx.lookup(Service.JNDI_PATH);
Any ideas?

Add an jboss-deployment-structure.xml with the following contents to the top level of your WAR:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="org.jboss.xnio"></module>
</dependencies>
</deployment>
</jboss-deployment-structure>

check how you package the application, I suppose that you include the org.xnio libraries in the deployed archives.
In this case it will be loaded by different classloaders that cause this error.

Related

NoSuchMethodError error when using JMS on Websphere 8.5

I have a Java application which is deployed on Websphere 8.5. It gets a message which I am trying to use it but this is the error I get even though I have the right JMS jars on line getBody()
Code Snippet:
if (arg0 instanceof BytesMessage)
{
byte[] payload = arg0.getBody(byte[].class);
myMessage = new String(payload);
}
Jar Files:
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
Error from Websphere logs:
Caused by: java.lang.NoSuchMethodError: javax/jms/Message.getBody(Ljava/lang/Class;)Ljava/lang/Object; (loaded from file:/opt/was_static/websphere_8.5.5.15.1/appserver/plugins/javax.j2ee.jms.jar by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader#6d5d04f3) called from class com.mycompany.myapplication.sync.mdb.myapplicationSyncOutboundMDB (loaded from file:/opt/was_static/profiles/appsrv01/installedApps/eaodr01Cell01/myapplication-ear-mydomain.com-editionmyapplication-ear-0.9.6.ear/myapplication-ejb-0.9.6.jar by
com.ibm.ws.classloader.CompoundClassLoader#19abf904[app:myapplication-ear-mydomain.com-editionmyapplication-ear-0.9.6]
Local ClassPath:
Parent: com.ibm.ws.classloader.ExtJarClassLoader#890f8480[PF][server:0]
Delegation Mode: PARENT_FIRST)
Websphere CLassloading:
Any ideas why my application, which compiles fine as it sees javax.jms.Message in the code but the Websphere can't find this?
WebSphere Application Server 8.5.5 supports Java EE 6 which includes JMS 1.1, not JMS 2.0 and the getBody(Class) method was added in JMS 2.0 which is Java EE 7 and newer.
If you want to use JMS 2.0 then you need to upgrade to WebSphere Application Server 9.0.

Jboss deployment error: class A cannot access its superclass B

I'm pretty new to JBoss and I'm trying to deploy a .war file on JBoss version 7.0.6 GA.
The .war file is created with the "export as .war file" option in Eclipse.
If I deploy the same .war file on Tomcat, it works without any error.
When I deploy on Jboss, I came across this strange error:
2017-10-20 17:29:26,803 ERROR [stderr] (ServerService Thread Pool -- 106)
Caused by: java.lang.IllegalAccessError: Failed to link
org/apache/log4j/xml/ExtXMLWatchdog (Module "deployment.
[MY_WAR_NAME].war:main" from Service Module Loader): class
org.apache.log4j.xml.ExtXMLWatchdog cannot access its superclass
org.apache.log4j.xml.XMLWatchdog
I'm using the log4j-1.2.17.jar library inside my web app; also, I'm using another custom library named util-log4j.jar.
Inside the log4j-1.2.17.jar is defined the class org.apache.log4j.xml.XMLWatchdog; inside the util-log4j.jar is defined the class
org.apache.log4j.xml.ExtXMLWatchdog.
It seems that the ExtXMLWatchdog cannot see the XMLWatchdog defined in another .jar, but why?
Thank you,
cheers!
Ok, I solved it. Sharing the solution:
inside the .war file, in the WEB-INF folder, I put a file named
jboss-deployment-structure.xml
with this content:
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
<exclude-subsystems>
<subsystem name="org.apache.log4j" />
</exclude-subsystems>
</deployment>
It seems that JBoss is equipped with some standard library, but those libraries maybe are loaded by a different ClassLoader (not sure of this, however)
With that file, essentially I'm telling to JBoss to ignore it's own org.apache.log4j library.
The result is that my log4j library is used, and problem is gone!

ClassNotFoundException in Wildfly 10 despite dependency being set

I'm running an application on WildFly 10. It contains a number of EJBs in an EAR. I have one EJB "gt" being triggered via JMS. That EJB calls another EJB "ps", resulting in an error, ultimately
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.filefilter.IOFileFilter from [Module "deployment.MyApplication.ear:main" from Service Module Loader]
My jboss-deployment-structure.xml contains this
<sub-deployment name="ps.jar">
<dependencies>
<module name="org.apache.commons.io"/>
</dependencies>
</sub-deployment>
And there is a module of name "org.apache.commons.io" under jboss\modules\system\layers\base\org\apache\commons\io\main
What am I doing wrong?
What is the significance of stuff being under jboss\modules\system\layers rather than just under jboss\modules?
Is there a way to look into the configured dependencies of a sub-deployment at runtime, e.g, via the jboss-cli?
Update:
According to https://docs.jboss.org/author/display/WFLY10/Class+Loading+in+WildFly, I would have expected the error message to say [Module "deplyoment.MyApplication.ear.ps.jar:main" ...], but it doesn't. But why would the context be the global deployment, rather than the specific sub-deployment?
The logical call stack looks like this:
general.GeneralSomeClass.getIOFileFilter()
<-- static method. return type is IOFileFilter from Commons IO.
general is just a POJO lib (MyApplication.ear/lib/general.jar)
the exception occurs on loading the GeneralSomeClass, before calling the method
ps.PsSomeClass.run()
ps.PsEJB.run()
gt.GtEJB.run()
You need to load the classes manually in that case, I have done this in the standalone.xml for our application.
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<global-modules>
<module name="com.tibco.tibjms"/>
<module name="org.apache.logging.log4j.api"/>
<module name="org.apache.logging.log4j.core"/>
<module name="org.apache.logging.log4j.web"/>
</global-modules>
We ended up using the Dependencies: option in MANIFEST.MF, getting rid of the jboss-deployment-structure.xml altogether.

Module not excluded on Wildfly

We want to exclude the modules\system\layers\base\javax\servlet\jstl\api\main\jboss-jstl-api_1.2_spec-1.1.2.Final.jar from our web application deployment (WAR file).
Hence we have the following configuration in src\main\webapp\WEB-INF\jboss-deployment-structure.xml:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="javax.servlet.jstl.api"/>
</exclusions>
<dependencies>
<module name="deployment.my-dependencies.jar"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
In the Wildfly log I see that my-dependencies.jar is added as a ModuleDependency. But when searching for javax.servlet.jstl.api I only see this:
2015-04-03 15:22:11,971 DEBUG [org.jboss.modules] (ServerService
Thread Pool -- 12) Module javax.servlet.jstl.api:main defined by local
module loader #1f7c9157 (finder: local module finder #2b29f6e7 (roots:
C:\Users\me\Documents\wildfly-8.2.0.Final\modules,C:\Users\me\Documents\wildfly-8.2.0.Final\modules\system\layers\base))
Why isn't the module excluded?
Update: It seems that modules that are part of a user dependency can not be excluded.
It seems like the mechanism doesn't work as described in the Wildfly documentation. I was not able to exclude that module.
Yep. I was trying to upgrade to Spring Framework to v4.3. It has upped some minimum dependency requirements. One such example is Jackson min version required is 2.6+
Wildfly loads jackson that comes packaged (v2.4.1 in Wildfly 8.2.1), and it won't be excluded using jboss-deployment-structure.xml.
I was trying to see if the upgrade did not involve making changes to the installed server which takes this upgrade out of source control.

SAP JBOSS issues with jar

I am trying to connect my j2ee application with SAP using ABAP function calls. When I run it as a single class in eclipse with hot coded values , it works fine. When I try to run it in JBoss server , where I am getting some values from my front end and passing it to my java class which is the same class I referred before, it shows this following exception
java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
at org.jboss.aop.ClassContainer.createMethodMap(ClassContainer.java:182)
09:35:42,326 INFO [EARDeployer] Started J2EE application: file:/F:/jboss/jboss- 4.2.3.GA/server/default/deploy/MPCS.ear
09:35:42,326 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
--- MBeans waiting for other MBeans ---
ObjectName: jboss.j2ee:service=EJB3,module=MPCS.jar
State: FAILED
Reason: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.j2ee:service=EJB3,module=MPCS.jar
State: FAILED
Reason: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
I have my sapjco3.jar in F:/jar where I also have ejb3-persistence.jar, jboss-ejb3x.jar etc and they are properly recognized. I have added the jar in build path also. But nothing helps.
I had a similar problem with the NoClassDefFoundError in JBoss EAP 6.1 when using classes from sapjco3.jar in an EJB (annotated with #Singleton and #Startup).
Besides that I also received an error saying that the native library was already loaded in another classloader when republishing to EAP or restarting the deployed module.
My solution to both problems was to include sapjco3.jar as a global JBoss module.
Step 1
I created the following structure inside EAPS's \modules folder:
com
--> sap
--> conn
--> jco
--> main
--> module.xml
--> sapjco3.jar
The contents of module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.sap.conn.jco">
<resources>
<resource-root path="sapjco3.jar"/>
</resources>
</module>
Step 2
Adding the module as a global module in standalone.xml:
<subsystem xmlns="urn:jboss:domain:ee:1.1">
...
<global-modules>
<module name="com.sap.conn.jco" />
</global-modules>
...
</subsystem>
Step 3
Create or edit file jboss-deployment-structure.xml inside EJB projects META-INF to contain the module.
My file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.sap.conn.jco" export="TRUE" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Step 4
Configure Maven dependency as scope provided, so that we can work with sapjco3.jar inside the workspace but not have it inside the deployment.
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.10</version>
<scope>provided</scope>
</dependency>
That is what I recall so far to make it work, maybe this is helpful for you or anybody else.
Besides that, could be necessary to add the dependency to the javax.api if are you using a newer version of sapjco3. This dependency is necessary to load the crypto library from Java.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.sap.conn.jco">
<resources>
<resource-root path="sapjco3.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>

Categories