JBoss EAP 6.4 Jackson module classloading - jboss

I made a small project which looks like this
playboss.ear
lib
commonlib.jar
JsonDeserializer.class
testlib.jar
JsonMessage.class
Version.class
jackson-1.9.4.jar
playboss_ejb.jar
MessageTimer.class
JsonMessage has a member: *private Class msgVersion = Version.V0.class;
MessageTimer is just a Bean with a timeout which does nothing but deserializes an example String of JsonMessage using JsonDeserializer.
Everything works fine, i.e. the String is converted to JsonMessage!
Now I add a dependency to my project containing a JAX-RS API and model objects such that lib is extended.
lib
SomeAPI.jar
javax.ws.rs-api-2.0.jar
Now when I start the JBoss EAP 6.4 I get the following exception:
Caused by: java.lang.ClassNotFoundException: playground.testlib.Version$V0 from [Module "org.codehaus.jackson.jackson-mapper-asl:main" from local module loader #9e89d68
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.7.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.7.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.7.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.7.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.7.Final-redhat-1]
at java.lang.Class.forName0(Native Method) [rt.jar:1.8.0_66]
at java.lang.Class.forName(Class.java:264) [rt.jar:1.8.0_66]
at org.codehaus.jackson.map.deser.std.ClassDeserializer.deserialize(ClassDeserializer.java:42) [jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]
I figure that due to https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments the jax-rs module dependency is triggered and jackson gets loaded from modules.
My questions:
1) What is the recommended / best way to get my deserialization working again
2) I would like to understand how object mapping is done with jax-rs if the module classloader does obviously not see my model classes.

Related

Broadleaf Jboss Setup ClassNoFound

When trying to do a broadleaf Jboss setup, I am getting the below error
I have checked the source code com.broadleafcommerce.customersegment.admin.dataimport.persistence.CustomerSegmentRecordPersistencePreProcessor is available in broadleaf-merchandising-group-1.2.1-GA.jar but strangely the class com.broadleafcommerce.dataimport.service.RecordPersistencePreProcessor is no where found, please help.
2018-01-02 21:51:54,565 WARN [org.jboss.modules] (MSC service thread 1-7) Failed to define class com.broadleafcommerce.customersegment.admin.dataimport.persistence.CustomerSegmentRecordPersistencePreProcessor in Module "deployment.admin.war" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link com/broadleafcommerce/customersegment/admin/dataimport/persistence/CustomerSegmentRecordPersistencePreProcessor (Module "deployment.admin.war" from Service Module Loader): com/broadleafcommerce/dataimport/service/RecordPersistencePreProcessor
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
at org.jboss.modules.Module.loadModuleClass(Module.java:713)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.loadClassInfoSet(ServletContainerInitializerDeploymentProcessor.java:259)
at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.deploy(ServletContainerInitializerDeploymentProcessor.java:169)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2018-01-02 21:51:54,565 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."admin.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."admin.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "admin.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:172)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: Failed to link com/broadleafcommerce/customersegment/admin/dataimport/persistence/CustomerSegmentRecordPersistencePreProcessor (Module "deployment.admin.war" from Service Module Loader): com/broadleafcommerce/dataimport/service/RecordPersistencePreProcessor
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
at org.jboss.modules.Module.loadModuleClass(Module.java:713)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.loadClassInfoSet(ServletContainerInitializerDeploymentProcessor.java:259)
at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.deploy(ServletContainerInitializerDeploymentProcessor.java:169)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165)
... 5 more
The issue that you are running into is the ServletContextInitializer scanning in Servlet 3.0+ containers. In Tomcat, you can control this with this guide: https://wiki.apache.org/tomcat/HowTo/FasterStartUp#JAR_scanning. Jboss is utilizing its class loader to check for ServletContextInitializer classes, and in some of the Broadleaf jars we link in at compile time some conditional classes that may not be available at runtime.
Are you using the Spring Boot project based on Broadleaf 5.2.x? You can try adding a web.xml that has an empty <absolute-ordering />: https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/using-a-web.xml
I would also question the use of Jboss at all. There is almost zero reason to ever use a full-blown JEE application server within a Spring application and frankly, you are asking for more issues as time goes on. You are trying to combine a fat .war (a Spring application built with Maven) with a fat application server (jboss). You should instead pair a fat .war file with a light servlet container (like Tomcat) or a light .war file (a JEE application) with a JEE application server.

JBoss7 and Beans - required jars appear not to be used

We are trying to create a functional example with Hibernate, JBoss7, Beans and Servlets using Eclipse as an IDE.
In other example project we were able to make functional Servlets, and we were able to use Hibernate.
We created two eclipse projects:
A Dynamic web project, an Enterprise Java Beans (EJB) project and a EAR project connecting both.
Running a simple test.java file which uses hibernate (and worked on other projects), we the get errors:
Initial SessionFactory creation failed.org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
Exception in thread "main" java.lang.ExceptionInInitializerError
at exercicio.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:20)
at exercicio.DataBaseInterface.<init>(DataBaseInterface.java:17)
at exercicio.Test.main(Test.java:9)
Caused by: org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:156)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:303)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at exercicio.SessionFactoryUtil.configureSessionFactory(SessionFactoryUtil.java:32)
at exercicio.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:17)
... 2 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.validator.util.LoggerFactory.make(LoggerFactory.java:29)
at org.hibernate.validator.util.Version.<clinit>(Version.java:24)
at org.hibernate.validator.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:59)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:445)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 19 more
The problem now seems to be around the jars that we included using project Properties > Java Build Path > Add External Jars for the EJB project:
We added the slf4j-jdk14-1.7.5.jar and hibernate jars but the exception log appears to be indicating that we are still missing some jar.
If we remove the jars from the Java Build Path, the exception log is the same. So we think that the jars are not being deployed correctly, or some extra configuration is required... even thought they appear in the /lib folder inside the EJB project deployment folder.
Is there any procedure we are missing, or any probable causes to investigate? I'll add more info if needed. Thanks.
When using JBoss7 not all Jars are available to the application by default (for example slf4j). You have to specify which modules should be included in the classpath of the application by putting this information into a file in your application.
I always do it by adding jboss-deployment-structure.xml into my application (the EAR in your case).
Here's how https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7.
(The name of the module in your case would be org.slf4j)
Throwing slf4j jar in the libs folder can create a conflict with the slf4j module already included in JB7 by default... you have to add the dependency to your jboss-deployment-structure.xml
But if your hibernate jars are in the libs folder, they could fail resolve the dependency as well too... the way to go in JB7 would be to make a module for Hibernate too, the Nightie builds of JB7 already include an hibernate module, you could just copy the module from there, then add it to your jboss-deployment-structure.xml

ClassCastException: MyFilter cannot be cast to javax.servlet.Filter

I'm migrating an application to JBoss 7, where all dependencies were in "JBOSS_HOME/server/default/lib" (JBoss 4). I included the lib "servlet.jar" (javax.servlet. *), however, after setting a Global Module for JBoss 7 (modules.xml, standalone.xml, jboss-deployment-structure.xml in war files), libraries are loaded normally by JBoss.
When JBoss 7 tries to start the filters, I get following exception:
15:09:15,222 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/RegistrarValorDolar]] (MSC service thread 1-2) Exception starting filter cripto: java.lang.ClassCastException: cenpra.com.sigtec.business.utilities.SessionFilter cannot be cast to javax.servlet.Filter
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_15]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_15]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_15]
Trying to remove the library "servlet.jar" from Global Modules, in a try that the server loads it's own classes using an internal jar, I got a ClassNotFoundExceptionof javax.servlet.Filter class.
I want to use global modules, since I need to reuse a lot of libraries.
Your classpath is polluted with multiple different versioned javax.servlet.Filter classes. A class which is loaded by classloader X (e.g. the one responsible for container's internal classes) is not the same class when it's loaded by classloader Y (e.g. the one responsible for webapp's classes).
I included the lib "servlet.jar" (javax.servlet.)
This does at least not sound right. This is supposed to be already provided by the target servletcontainer (which is JBoss in your case). You should absolutely not provide servletcontainer-specific libraries along with the webapp in its /WEB-INF/lib folder. This would only end up in runtime classpath disaster because they get classloading precedence over the ones provided by the servletcontainer itself and thus conflicts with servletcontainer's internal classes which are in turn using servletcontainer's own classes.
Get rid of servletcontainer-specific libraries in /WEB-INF/lib folder.
This is a common starter's mistake in a careless attempt to fix/circumvent compilation errors on javax.servlet API which they face in their IDE. It should have been solved differently. To the point, you need to tell the IDE to associate the web project with the given target container. The IDE will then automatically do the necessary build path magic.
See also:
How do I import the javax.servlet API in my Eclipse project?

JBoss&Hibernate

I'm using JBoss AS 7.1 and Hibernate in Eclipse 3.7.2 to build a Dynamic Web Project using Java and JSP. All of the proper JAR files are in the WAR (I checked), but I'm getting this error:
java.lang.ClassNotFoundException: org.hibernate.cfg.EJB3DTDEntityResolver from [Module "deployment.MyProject.war:main" from Service Module Loader]
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
org.hibernate.cfg.Configuration.reset(Configuration.java:326)
org.hibernate.cfg.Configuration.<init>(Configuration.java:265)
org.hibernate.cfg.Configuration.<init>(Configuration.java:269)
my.project.MyManager.<init>(MyManager.java:79)
org.apache.jsp.index_jsp._jspService(index_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
The relavent line of the manager class is Configuration cfg = new Configuration();. Everything works perfectly in a standalone eclipse project. It only breaks when I try to make a JBoss Page.
Make sure the hibernate-annotations.jar is properly setup in your WAR file. It's probably missing.
So, apparently the problem was trying to include hibernate jars at all. JBoss AS 7.1.1 has hibernate built in. You have to add Dependencies: org.hibernate, org.hibernate.envers to MANIFEST.MF.

deploying gwt web application on jetty

Hi I am deploying my web application created in Gwt on the jetty.
I have used mongodb as my database.After starting the server it starts deploying the weapp.war
and gives following error -
694 [main] INFO org.mortbay.log - Extract /usr/share/jetty/webapps/myapp.war to /tmp/Jetty_0_0_0_0_8090_myapp.war__myapp__n6yltk/webapp
3567 [main] WARN org.mortbay.log - failed Startup: java.lang.LinkageError: loader constraint violation: loader (instance of org/mortbay/jetty/webapp/WebAppClassLoader) previously initiated loading for a different type with name "javax/management/MBeanServer"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:392)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:363)
at com.mongodb.DBPortPool$Holder.get(DBPortPool.java:58)
at com.mongodb.DBTCPConnector._set(DBTCPConnector.java:458)
at com.mongodb.DBTCPConnector.<init>(DBTCPConnector.java:46)
at com.mongodb.Mongo.<init>(Mongo.java:137)
at com.mongodb.Mongo.<init>(Mongo.java:123)
one of the jar in your classpath contains javax/management/MBeanServer. That is why you have got this exception. For example jboss-jmx.jar contains this class, if this jar is included in your classpath,you should remove it.
That is a class loading issue between the web class loader and the system class loader.
You might want to check this great speech about ClassLoader out.
http://www.zeroturnaround.com/blog/video-do-you-really-get-class-loaders-a-jazoon-talk-by-jevgeni-kabanov/
Check if you have log4j dependency in your pom.xml. The log4j has a dependency to jmxri which needs to be excluded.
Once you exclude this, the error gets resolved