ArrayIndexOutOfBoundsException deploying to GlassFish 4.1.1 with no web.xml Jersey - deployment

I got this strange error deploying my Jersey server (with no web.xml) to GlassFish 4.1.1 using Maven glassfish plugin (in fact, I had switched my (Maven) build from embedded Grizzly to GlassFish, updating standard Jersey dependencies from compile to provided):
[ERROR] remote failure: Error occurred during deployment: Exception
while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.apache.catalina.LifecycleException:
java.lang.ArrayIndexOutOfBoundsException: 0. Please see server.log for
more details
The deployment was successful when I didn't declare the #ApplicationPath in my ResourceConfig implementation. But then, I got a 404 error when trying to consume the service. According to Jersey documentation, the #ApplicationPath is needed for no web.xml deployment (Example 4.3).
The deployment error log is extracted below:
[2015-12-28T09:33:40.826+0800] [glassfish 4.1] [SEVERE] []
[javax.enterprise.web] [tid: _ThreadID=123
_ThreadName=admin-listener(6)] [timeMillis: 1451266420826] [levelValue: 1000] [[
WebModule[/BBQuay-Entertainment-1.0-SNAPSHOT]StandardWrapper.Throwable
java.lang.ArrayIndexOutOfBoundsException: 0 at
org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:505)
at
org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:182)
at
org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:348)
at
org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:345)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at
org.glassfish.jersey.internal.Errors.process(Errors.java:297) at
org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
at
org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:345)
at
org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:390)
at
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:362)
at javax.servlet.GenericServlet.init(GenericServlet.java:244) at
org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
.....

It turned out to be a Maven configuration. Since I was testing with Grizzly before, when switching to GlassFish, I left the two dependencies jersey-weld2-se and jersey-cdi1x default Maven scope. The latter is fine but the first is provided by GlassFish container. Corrected as following helps solve the problem (though the deployment error was really not helpful..)
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x</artifactId>
</dependency>

The following is sufficient on Glassfish 4.1.1 (without web.xml):
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
#ApplicationPath("rest")
public class ApplicationConfig extends ResourceConfig {
}
And an example class:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
#Path("info")
public class InfoStub {
#GET
public String getInfo() {
return "hello sir";
}
}
You can access it under http://localhost:8080/YOUR_PROJECT_NAME/rest/info
Make sure that you set your standard Jersey dependencies in your pom.xml to provided.

Related

Ojdbc8 jars upgrade to 21.1.0.0 throws Nosuchmethod exception UCPservletContextListener init

Ojdbc8, ons, ucp jars are upgraded to 21.1.0.0 version. When trying to start the app on tomcat server, it's throwing Nosuchmethod exception. Logged in the Tomcat's localhost.log file. Application tries to establish DB connection during startup itself.
01-Jun-2021 15:59:56.641 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 3 Spring WebApplication Initializers detected on classpath
01-Jun-2021 16:00:05.365 INFO localhost-startStop-1 org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
01-Jun-2021 16:00:19.397 SEVERE localhost-startStop-1 org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class [oracle.ucp.jdbc.UCPServletContextListener]
java.lang.NoSuchMethodException: oracle.ucp.jdbc.UCPServletContextListener.init
at java.lang.class.getConstructor(Unknown Source)
This is a known issue with ucp.jar in 21.1. It will be fixed in 21.3 when it's released. In the meantime, you can remove this class from the ucp.jar:
oracle/ucp/jdbc/UCPServletContextListener.class
From my experience, if you put jdbc/ucp jars to Tomcat's lib (which is recommended for productive system) and set provided scope for them in Maven, the problem will disappear.
Another option could be setting metadata-complete="true" in web.xml (read more here and here)
if you are using spring boot then you can use
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
this dependency or update your maven project.

Deploying Apache Isis on WildFly

I'm trying to deploy an Apache Isis project on a WildFly server.
The project is just the simpleapp-archetype-1.10.0 and it starts and works well with mvn antrun:run -P self-host and mvn jetty:run-war.
For the jetty part, I added configuration to the org.eclipse.jetty plugin of the parent pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.2.v20150730</version>
<configuration>
<war>${project.basedir}/webapp/target/simpleapp.war</war>
</configuration>
</plugin>
Now I wanted to deploy this on a WildFly server, but I get the following error:
Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"simpleapp.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"simpleapp.war\".WeldStartService: Failed to start service Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type IsisJdoSupport with qualifiers #Default at injection point [BackedAnnotatedField] #Inject org.apache.isis.objectstore.jdo.datanucleus.service.support.TimestampService.isisJdoSupport at org.apache.isis.objectstore.jdo.datanucleus.service.support.TimestampService.isisJdoSupport(TimestampService.java:0) "}}
How can I fix this error, and why does jetty bypass this error?
I got an answer via the Apache Isis Mailing List.
The error says that WildFly tries to do CDI work. Jetty is just a web server and doesn't support Java EE stuff like CDI. Try to disable CDI support for this application (I have no idea how exactly).
http://isis.markmail.org/message/d3coq6qus3rca7kx
To fix this error:
Add the file jboss-all.xml to Simple App Webapp/Web Pages/WEB-INF with the following code:
<jboss xmlns="urn:jboss:1.0">
<weld xmlns="urn:jboss:weld:1.0" require-bean-descriptor="true"/>
</jboss>
https://docs.jboss.org/author/display/WFLY8/CDI+Reference
Credits to Martin Grigorov though.

javax.persistence jar is not loaded into tomcat

I'm trying to run JPA servlet on Tomcat 8.
From my servlet I call method of a class named QueryDB.class located in another Eclipse project (JPA project, not WEB project).
But tomcat throws
SEVERE: Servlet.service() for servlet [MyRESTService] in context with path [/AutomationWeb] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: javax/persistence/Persistence] with root cause
java.lang.ClassNotFoundException: javax.persistence.Persistence
at java.net.URLClassLoader$1.run(Unknown Source)
...
Exception is thrown at line EntityManagerFactory emf = Persistence.createEntityManagerFactory( "AutomationDB_JPA" ); in QueryDB.class
I'm using Eclipse Mars with Maven. I have EclipseLink in my pom.xml defined:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.1</version>
</dependency>
I have following jars in my Application's WEB-INF/lib:
eclipselink-2.6.1.jar
javax.persistence-2.1.0.jar , it has javax/persistence/Persistence.class inside
There is no other SEVERE messages in the tomcat log.
What's wrong with this setup?
I also tried adding the persistence jar to apache-tomcat-8.0.28\lib , but got the same error.
Update: I moved Persistence.createEntityManagerFactory call to the servlet itself and got no classloader exception. So the question changes: why classloader used for QueryDB.class is different from servlet's classloader? Also, why classloader used in QueryDB.class does not see the Persistence.class, which is seen by the servlet's classloader?
Ok I've found a solution.
Excluded my JPA project from tomcat VM classpath
Converted my JPA project to the Utility project
Modified Deployment Assembly in my Web project properties so that it
will accept JPA project as .jar archive into WEB-INF/lib
I have no classloader exception anymore.

Spring boot jackson auto configuration linkage error wildfly

A.war -> Is a simple spring boot REST app using version 1.2.6.RELEASE ( internally using spring 4.1.7 RELEASE, jackson 2.4.6 )
B.jar -> Is a wildfly9 shared module (stored in wildfly/modules) which is packaged using maven shaded plugin containing spring framework (without spring boot meaning using the old way of adding spring projects dependencies) and jackson classes of same version as above. (Its shaded because non-spring and non-container projects can just add this jar in their class-path and use it - it works)
A.war has maven dependency scope <provided> on B.jar and has jboss-deployment-structure.xml with <dependencies> <module name = "B"> </dependencies>
A.war deployment fails with below error.
Note: A.war deploys perfectly fine when i remove B.jar jboss dependency. So adding B.jar is causing this issue. And If i don't use spring boot in A.war (meaning if i use simple spring webmvc and context dependencies directly) with B.jar jboss dependency, A.war deploys perfectly too
Can anyone explain me what the error below says and how can i investigate more ?
As far as my understanding on wildlfy classloading, A.war and B.jar should be loaded in different module class loaders, Is A.war complaining about jackson classes of B.jar here in the error ?
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method
"org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.modulesToInstall([Lcom/fasterxml/jackson/databind/Module;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder;"
the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class,
org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration,
and the class loader (instance of org/jboss/modules/ModuleClassLoader) for resolved class,
org/springframework/http/converter/json/Jackson2ObjectMapperBuilder,
have different Class objects for the type der used in the signature
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.configureModules(JacksonAutoConfiguration.java:259)
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.jacksonObjectMapperBuilder(JacksonAutoConfiguration.java:186)
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$EnhancerBySpringCGLIB$$b993caa0.CGLIB$jacksonObjectMapperBuilder$1()
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$EnhancerBySpringCGLIB$$b993caa0$$FastClassBySpringCGLIB$$5262bf2.invoke()
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318)
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$EnhancerBySpringCGLIB$$b993caa0.jacksonObjectMapperBuilder()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ... 108 more
After investigating more jboss classloading behavior, jackson classes inside B.jar are conflicting with same jackson classes from jboss restesay module.
so after excluding them in jboss-deployment-structure.xml as below this problem is fixed..
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
<module name="org.jboss.resteasy.resteasy-jackson2-provider"/>
</exclusions>

Errors when deploying Tomcat7 webapp

I'm trying to deploy a simple Resteasy application using Java7 to Tomcat7.
I get these errors on startup:
SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
java.lang.NoClassDefFoundError: org/scannotation/AnnotationDB$CrossReferenceException
SEVERE: Exception sending context destroyed event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
java.lang.NullPointerException
I'm using apache maven for the dependencies which is retrieving from
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository>
The web.xml can be found at http://pastebin.com/Nsuh71ES.
Any help is appreciated.
After examining the maven cache, the jboss resteasy library hadn't been fully downloaded.
The problem was due to the fact that org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap could not be accessed