I have an JAX-RS integration test that works locally, both in IntelliJ (using Gradle to run the test) and Gradle command line .
But when I run the test in Jenkins, the test fails, with some issue during the Undertow deployment.
This is how I start the container :
public static void startContainer() throws ServletException {
System.setProperty("org.jboss.resteasy.port", "8085");
server = new UndertowJaxrsServer().start();
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setInjectorFactoryClass("org.jboss.resteasy.cdi.CdiInjectorFactory");
deployment.setApplicationClass(MyApp.class.getName());
DeploymentInfo di = server.undertowDeployment(deployment);
di.setClassLoader(Server.class.getClassLoader());
di.setResourceManager(new ClassPathResourceManager(Server.class.getClassLoader()));
di.setContextPath("/vincent-service");
di.setDeploymentName("DI");
di.addListeners(Servlets.listener(org.jboss.weld.environment.servlet.Listener.class));
server.deploy(di);
}
When the test runs in Jenkins, I get a NullPointerException :
java.lang.RuntimeException: java.lang.NullPointerException at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:254) at org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer.deploy(UndertowJaxrsServer.java:266)
...
Caused by: java.lang.NullPointerException at org.jboss.weld.module.web.servlet.WeldInitialListener.contextInitialized(WeldInitialListener.java:94) at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextInitialized(ForwardingServletListener.java:34) at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:121) at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187) at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:217) at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:186) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:252)
Looking in Weld source code (in weld-web-3.1.2.Final), it seems the exception is thrown from the last line here :
@Override
public void contextInitialized(ServletContextEvent sce) {
final ServletContext ctx = sce.getServletContext();
// First try to use the context id obtained from the servlet context (OSGi, Servlet containers, etc.)
if (beanManager == null) {
String contextId = ctx.getInitParameter(Container.CONTEXT_ID_KEY);
if (contextId != null) {
List<BeanManagerImpl> managers = new ArrayList<BeanManagerImpl>(Container.instance(contextId).beanDeploymentArchives().values());
Collections.sort(managers, BeanManagers.ID_COMPARATOR);
beanManager = managers.get(0);
}
}
// servlet containers may not be able to inject fields in a servlet listener
if (beanManager == null) {
beanManager = BeanManagerProxy.unwrap(CDI.current().getBeanManager());
}
Part of the test is running though, as I can see these logs :
[2021-10-06T08:44:16.016Z] [io.undertow.Undertow] [Test worker] [117] [INFO ] starting server: Undertow - 2.1.3.Final
[2021-10-06T08:44:16.016Z] [org.xnio.Xnio] [Test worker] [95] [INFO ] XNIO version 3.8.0.Final
[2021-10-06T08:44:16.016Z] [org.xnio.nio.NioXnio] [Test worker] [59] [INFO ] XNIO NIO Implementation Version 3.8.0.Final
[2021-10-06T08:44:16.016Z] [org.jboss.threads.Version] [Test worker] [52] [INFO ] JBoss Threads version 3.1.0.Final
[2021-10-06T08:44:17.017Z] [org.jboss.weld.environment.servlet.Listener] [Test worker] [115] [INFO ] WELD-ENV-001007: Initialize Weld using ServletContextListener
[2021-10-06T08:44:17.017Z] [org.jboss.weld.bootstrap.WeldStartup] [Test worker] [231] [INFO ] WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
[2021-10-06T08:44:17.017Z] [org.jboss.weld.event.ExtensionObserverMethodImpl] [Test worker] [86] [INFO ] WELD-000411: Observer method [BackedAnnotatedMethod] protected org.apache.deltaspike.core.impl.exclude.extension.ExcludeExtension.vetoBeans(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
[2021-10-06T08:44:17.017Z] [org.jboss.weld.event.ExtensionObserverMethodImpl] [Test worker] [86] [INFO ] WELD-000411: Observer method [BackedAnnotatedMethod] public org.apache.deltaspike.core.impl.interceptor.interdyn.InterDynExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
[2021-10-06T08:44:17.017Z] [org.jboss.weld.event.ExtensionObserverMethodImpl] [Test worker] [86] [INFO ] WELD-000411: Observer method [BackedAnnotatedMethod] protected org.apache.deltaspike.core.impl.message.MessageBundleExtension.detectInterfaces(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
[2021-10-06T08:44:17.017Z] [org.jboss.weld.event.ExtensionObserverMethodImpl] [Test worker] [86] [INFO ] WELD-000411: Observer method [BackedAnnotatedMethod] protected org.apache.deltaspike.core.impl.interceptor.GlobalInterceptorExtension.promoteInterceptors(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
[2021-10-06T08:44:17.017Z] [org.jboss.weld.event.ExtensionObserverMethodImpl] [Test worker] [86] [INFO ] WELD-000411: Observer method [BackedAnnotatedMethod] public org.apache.deltaspike.core.impl.config.ConfigurationExtension.findDynamicConfigurationBeans(@Observes ProcessAnnotatedType<?>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
[2021-10-06T08:44:18.018Z] [org.jboss.weld.logging.ValidatorLogger] [Test worker] [59] [WARN ] WELD-001478: Interceptor class org.apache.deltaspike.core.impl.throttling.ThrottledInterceptor is enabled for the application and for the bean archive /tankkarte-service_/var/jenkins_home/.gradle/caches/modules-2/files-2.1/org.apache.deltaspike.core/deltaspike-core-impl/1.9.4/709e0b27bb80e52fcd6a886a216ca3f9c2b8c28/deltaspike-core-impl-1.9.4.jar. It will only be invoked in the @Priority part of the chain.
[2021-10-06T08:44:18.018Z] [org.jboss.weld.logging.ValidatorLogger] [Test worker] [59] [WARN ] WELD-001478: Interceptor class org.apache.deltaspike.core.impl.lock.LockedInterceptor is enabled for the application and for the bean archive /tankkarte-service_/var/jenkins_home/.gradle/caches/modules-2/files-2.1/org.apache.deltaspike.core/deltaspike-core-impl/1.9.4/709e0b27bb80e52fcd6a886a216ca3f9c2b8c28/deltaspike-core-impl-1.9.4.jar. It will only be invoked in the @Priority part of the chain.
[2021-10-06T08:44:18.018Z] [org.jboss.weld.logging.ValidatorLogger] [Test worker] [59] [WARN ] WELD-001478: Interceptor class org.apache.deltaspike.core.impl.future.FutureableInterceptor is enabled for the application and for the bean archive /tankkarte-service_/var/jenkins_home/.gradle/caches/modules-2/files-2.1/org.apache.deltaspike.core/deltaspike-core-impl/1.9.4/709e0b27bb80e52fcd6a886a216ca3f9c2b8c28/deltaspike-core-impl-1.9.4.jar. It will only be invoked in the @Priority part of the chain.
[2021-10-06T08:44:18.018Z] [org.jboss.weld.logging.ValidatorLogger] [Test worker] [59] [WARN ] WELD-001478: Interceptor class org.apache.deltaspike.core.impl.monitoring.InvocationMonitorInterceptor is enabled for the application and for the bean archive /tankkarte-service_/var/jenkins_home/.gradle/caches/modules-2/files-2.1/org.apache.deltaspike.core/deltaspike-core-impl/1.9.4/709e0b27bb80e52fcd6a886a216ca3f9c2b8c28/deltaspike-core-impl-1.9.4.jar. It will only be invoked in the @Priority part of the chain.
[2021-10-06T08:44:18.018Z] [org.jboss.weld.environment.undertow.UndertowContainer] [Test worker] [39] [INFO ] WELD-ENV-001302: Undertow detected, CDI injection will be available in Servlets, Filters and Listeners.
[2021-10-06T08:44:19.019Z] [org.jboss.weld.bootstrap.Validator] [weld-worker-1] [200] [WARN ] WELD-001473: javax.enterprise.inject.spi.Bean implementation liquibase.integration.cdi.CDIBootstrap$1@7c73f99b declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
[2021-10-06T08:44:20.020Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] Booting Liquibase 3.6.2 [2021-10-06T08:44:20.020Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] SELECT COUNT() FROM PUBLIC.DATABASECHANGELOGLOCK [2021-10-06T08:44:20.020Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] SELECT COUNT() FROM PUBLIC.DATABASECHANGELOGLOCK
[2021-10-06T08:44:20.020Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] SELECT LOCKED FROM PUBLIC.DATABASECHANGELOGLOCK WHERE ID=1
[2021-10-06T08:44:20.020Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] Successfully acquired change log lock
[2021-10-06T08:44:21.021Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] SELECT MD5SUM FROM PUBLIC.DATABASECHANGELOG WHERE MD5SUM IS NOT NULL
[2021-10-06T08:44:21.021Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOG
[2021-10-06T08:44:21.021Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] Reading from PUBLIC.DATABASECHANGELOG
[2021-10-06T08:44:21.021Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] SELECT * FROM PUBLIC.DATABASECHANGELOG ORDER BY DATEEXECUTED ASC, ORDEREXECUTED ASC
[2021-10-06T08:44:21.021Z] [liquibase.logging.core.Slf4jLogger] [Test worker] [42] [INFO ] Successfully released change log lock
[2021-10-06T08:44:21.021Z] [io.undertow.Undertow] [Test worker] [252] [INFO ] stopping server: Undertow - 2.1.3.Final
But at some point, the exception is thrown..
Any idea of what I could check to understand why this fails only in my Jenkins environment ?
I am using org.jboss.resteasy 3.12.1.Final libraries.