10 Replies Latest reply on Apr 25, 2016 3:43 AM by csaba.sarkadi

    CDI interceptors with Wildfly 10 in multi module maven projects

    csaba.sarkadi

      Hi,

       

      I am having problems with using CDI interceptors in a multi module maven project.

      I have created a minimalistic project, showing what I am trying to accomplish. I may have a misunderstanding on how should I writer the interceptors or maybe I have found another wildfly 10 bug?

       

      Long story short: I want to create an api module in my bigger maven project. I need a generic interceptor that should do the logging, when calling an EJB method (the EJB is injected via @Inject).

       

      So:

      1. Root pom (test-interceptor)

      1.1 interceptor-api module : this one contains the interceptor (EJBInterceptor.java) and the annotation (@InterceptedLogging.java)

      1.2 interceptor-ejb module: and ejb jar module, containing a single @Stateless EJB (InterceptedEJB.java)

      1.3 test-web module: simple web module, containing a @WebServlet, that has the above EJB injected via @Inject

       

      I have attached the sample project.

       

      Thanks everyone for the help!

       

       

       

      Error message from Wildfly 10 console (after trying to deploy the test-web module):

       

      19:37:48,035 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) WFLYDS0004: Found test-web.war in deployment directory. To trigger deployment create a file called test-web.war.dodeploy

      19:37:48,067 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0028: Stopped deployment test-web.war (runtime-name: test-web.war) in 15ms

      19:37:48,071 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "test-web.war" (runtime-name: "test-web.war")

      19:37:48,525 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."test-web.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."test-web.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "test-web.war"

          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

          at java.lang.Thread.run(Thread.java:745)

      Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class org.test.web.InterceptingWebServlet with ClassLoader ModuleClassLoader for Module "deployment.test-web.war:main" from Service Module Loader

          at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)

          at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)

          at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:106)

          at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:91)

          at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:76)

          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)

          ... 5 more

      Caused by: java.lang.NoClassDefFoundError: Ltest/ejb/InterceptedEJB;

          at java.lang.Class.getDeclaredFields0(Native Method)

          at java.lang.Class.privateGetDeclaredFields(Class.java:2583)

          at java.lang.Class.getDeclaredFields(Class.java:1916)

          at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:72)

          at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)

          ... 10 more

      Caused by: java.lang.ClassNotFoundException: test.ejb.InterceptedEJB from [Module "deployment.test-web.war:main" from Service Module Loader]

          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)

          ... 15 more

       

      19:37:48,526 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"test-web.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test-web.war\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"test-web.war\"

          Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class org.test.web.InterceptingWebServlet with ClassLoader ModuleClassLoader for Module \"deployment.test-web.war:main\" from Service Module Loader

          Caused by: java.lang.NoClassDefFoundError: Ltest/ejb/InterceptedEJB;

          Caused by: java.lang.ClassNotFoundException: test.ejb.InterceptedEJB from [Module \"deployment.test-web.war:main\" from Service Module Loader]"}}

      19:37:48,551 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0016: Replaced deployment "test-web.war" with deployment "test-web.war"

      19:37:48,552 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 1) WFLYCTL0183: Service status report

      WFLYCTL0186:   Services which failed to start:      service jboss.deployment.unit."test-web.war".POST_MODULE

            service jboss.deployment.unit."test-web.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."test-web.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "test-web.war"

        • 1. Re: CDI interceptors with Wildfly 10 in multi module maven projects
          tremes

          Hi Csaba,

          I've tried your reproducer and when I made org.test.web.InterceptingWebServlet extend HttpServlet then I was able to deploy your app to WildFly 10.0.0.Final. The problem with EJBInterceptor is that it's not enabled (with @Priority neither in beans.xml). So when I add @Priority(2500) to this class then everything works as expected.

          • 2. Re: CDI interceptors with Wildfly 10 in multi module maven projects
            csaba.sarkadi

            Ok, I will check into it this evening.

            Strange is that I haven't encountered the @Priority in tutorials (I mean neither of them stated it should be required, not even the Oracle official guide ).

             

            Thanks!

            • 3. Re: CDI interceptors with Wildfly 10 in multi module maven projects
              manovotn

              Hi Csaba,

               

              there is a section in Weld doc regarding interceptor enablement -> Weld 2.3.3.Final - CDI Reference Implementation

              • 4. Re: CDI interceptors with Wildfly 10 in multi module maven projects
                csaba.sarkadi

                Hi,

                 

                You are true about the deployment. But the deployment won't work from the eclipse plugin, just the admin interface of wildfly! The error is the same.

                Also: the application is deployed correctly, but when the servlet is accessed, the following error message is found on the console

                (this is the same error, but with a slightly different message):

                 

                 

                ERROR [io.undertow.request] (default task-4) UT005023: Exception handling request to /test-web-0.0.1-SNAPSHOT/test: java.lang.Error: Unresolved compilation problems:

                    The import org.interceptor.api.EJBInterceptor cannot be resolved

                    The import org.interceptor.api.InterceptedLogging cannot be resolved

                    InterceptedLogging cannot be resolved to a type

                 

                    at test.ejb.InterceptedEJB.<init>(InterceptedEJB.java:6)

                    at test.ejb.InterceptedEJB$Proxy$_$$_Weld$EnterpriseProxy$.<init>(Unknown Source)

                    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 java.lang.Class.newInstance(Class.java:442)

                    at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)

                    at java.security.AccessController.doPrivileged(Native Method)

                    at org.jboss.weld.injection.producer.ejb.SessionBeanProxyInstantiator.newInstance(SessionBeanProxyInstantiator.java:57)

                    at org.jboss.weld.bean.SessionBean.create(SessionBean.java:149)

                    at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:70)

                    at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)

                    at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)

                    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)

                    at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:842)

                    at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)

                    at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:378)

                    at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:389)

                    at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:71)

                    at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)

                    at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:73)

                    at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)

                    at org.jboss.as.weld.injection.WeldInjectionContext.inject(WeldInjectionContext.java:39)

                    at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:51)

                    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

                    at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)

                    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

                    at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)

                    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

                    at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)

                    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

                    at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)

                    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

                    at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)

                    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

                    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)

                    at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)

                    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

                    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

                    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)

                    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:134)

                    at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)

                    at org.jboss.as.ee.component.ComponentRegistry$ComponentManagedReferenceFactory.getReference(ComponentRegistry.java:149)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$6.createInstance(UndertowDeploymentInfoService.java:1366)

                    at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:226)

                    at io.undertow.servlet.core.ManagedServlet.getServlet(ManagedServlet.java:170)

                    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:84)

                    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

                    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

                    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

                    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

                    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

                    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

                    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

                    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

                    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

                    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

                    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

                    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

                    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)

                    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)

                    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)

                    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)

                    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)

                    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)

                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

                    at java.lang.Thread.run(Thread.java:745)

                • 5. Re: CDI interceptors with Wildfly 10 in multi module maven projects
                  tremes

                  Which Eclipse plugin? Do you mean JBoss Tool plugin for CDI? Can you please describe in more details the steps you do to deploy your app? What is actually really deployed on the server in this case?

                  Thank's

                  • 6. Re: CDI interceptors with Wildfly 10 in multi module maven projects
                    csaba.sarkadi

                    Hi,

                     

                    I mean the eclipse plugin, that lets me control the wildfly server from eclipse.

                    So the steps:

                    (After I have added the wildfly at the servers tab, and used maven clean+install on the project):

                    1. Right click on wildfly server -> start

                    2. After startup, right click on the server -> Add and remove

                    3. From the list I select test-web, add and ok

                    4. After that, on the wildfly console I see the error messages

                    • 7. Re: CDI interceptors with Wildfly 10 in multi module maven projects
                      tremes

                      Hm I just downloaded Eclipse for Java EE, setup server and imported your project as Maven project and then followed your steps and everything was ok.

                      • 8. Re: CDI interceptors with Wildfly 10 in multi module maven projects
                        csaba.sarkadi

                        Hi,

                         

                        Which version of eclipse are you using? I think this issue is very much related to my current eclipse installation.

                        I have tried the same project/code from netbeans 8.1, and it works, when I deploy from the IDE.

                         

                        I will check with another eclipse version to see if this issue is really related with it.

                        • 9. Re: CDI interceptors with Wildfly 10 in multi module maven projects
                          tremes

                          I was using following version:

                          Version: Mars.2 Release (4.5.2)

                          Build id: 20160218-0600

                          • 10. Re: CDI interceptors with Wildfly 10 in multi module maven projects
                            csaba.sarkadi

                            Finally I have found my problem: I was using Eclipse Mars 2 Java EE for Birt developers, that has deployment issues (it couldn't deploy the dependencies of the war file).

                            Switching to simple Eclipse for EE developers made my code / deployments work.