5 Replies Latest reply on Aug 20, 2012 12:35 PM by splatch

    JBoss modules and CDI extension

    splatch

      Hi all,

      During my work on switchyard I've found issue with loading of CDI extension. I have three modules switchyard-component-camel -> camel-cdi -> deltaspike-core-api. The classloading works - switchyard component is started, camel-cdi sees deltaspike and deltaspike sees JSR classes. The problem is deltaspike javax.enterprise.inject.spi.Extension is not picked up and later deltaspike throws exception. I am not sure if it is configuration issue. The modules definition:

       

       

      <module xmlns="urn:jboss:module:1.0" name="org.apache.deltaspike.core-api">
      
          <resources>
              <resource-root path="deltaspike-core-api-${version.deltaspike}.jar"/>
          </resources>
      
          <dependencies>
              <module name="javax.api" />
              <module name="javax.el.api" />
              <module name="javax.enterprise.api"/>
              <module name="javax.inject.api"/>
              <module name="javax.interceptor.api"/>
          </dependencies>
      
      </module>
      

       

       

      <module xmlns="urn:jboss:module:1.0" name="org.apache.camel.cdi">
      
          <resources>
              <resource-root path="camel-cdi-${version.camel}.jar"/>
          </resources>
      
          <dependencies>
              <module name="org.slf4j"/>
              <module name="org.apache.deltaspike.core-api" services="export" export="true" />
              <module name="org.apache.camel.core"/>
          </dependencies>
      
      </module>
      

       

       

      <module xmlns="urn:jboss:module:1.0" name="org.switchyard.component.camel">
      
          <resources>
              <resource-root path="switchyard-component-camel-${project.version}.jar"/>
          </resources>
      
          <dependencies>
              <module name="javax.api"/>
              <module name="javax.enterprise.api"/>
              <module name="javax.ws.rs.api"/>
              <module name="org.apache.log4j"/>
              <module name="org.apache.camel.core" services="export" export="true"/>
              <module name="org.apache.camel.cdi" services="export" export="true" />
              <module name="org.apache.camel.spring" services="export" export="true">
              <!-- and so on... -->
      
          </dependencies>
      </module>
      
        • 1. Re: JBoss modules and CDI extension
          splatch

          I was unable to get correct module definitions with help from IRC so I put instructions how to reproduce issue.

           

          git clone https://github.com/splatch/parent.git
          cd parent
          git checkout SWITCHYARD-981
          mvn clean install
          git clone https://github.com/splatch/components.git components
          cd components
          git checkout SWITCHYARD-981
          mvn clean install
          git clone https://github.com/splatch/release.git
          cd release
          git checkout SWITCHYARD-981
          mvn clean install
          

           

          During build of release you'll find a integration tests, and if problem occurs following stack trace:

           

          14:38:01,798 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-13) MSC00001: Failed to start service jboss.deployment.unit."switchyard-quickstart-rules-camel-cbr-0.6.0-SNAPSHOT.jar".SwitchYardService: org.jboss.msc.service.StartException in service jboss.deployment.unit."switchyard-quickstart-rules-camel-cbr-0.6.0-SNAPSHOT.jar".SwitchYardService: org.switchyard.exception.SwitchYardException: Failed to create route route1: Route[[From[switchyard://RoutingService?namespace=urn%3Aswit... because of Cannot lookup: properties from registry: CdiRegistry[1539734637] with expected type: interface org.apache.camel.Component due: No org.apache.deltaspike.core.api.provider.BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts.
                    at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:79)
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [classes.jar:1.6.0_33]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [classes.jar:1.6.0_33]
                    at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_33]
          Caused by: org.switchyard.exception.SwitchYardException: Failed to create route route1: Route[[From[switchyard://RoutingService?namespace=urn%3Aswit... because of Cannot lookup: properties from registry: CdiRegistry[1539734637] with expected type: interface org.apache.camel.Component due: No org.apache.deltaspike.core.api.provider.BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts.
                    at org.switchyard.component.camel.deploy.CamelActivator.handleImplementation(CamelActivator.java:253)
                    at org.switchyard.component.camel.deploy.CamelActivator.activateService(CamelActivator.java:140)
                    at org.switchyard.deploy.internal.Deployment.deployImplementations(Deployment.java:390)
                    at org.switchyard.deploy.internal.Deployment.start(Deployment.java:140)
                    at org.switchyard.as7.extension.deployment.SwitchYardDeployment.start(SwitchYardDeployment.java:103)
                    at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:72)
                    ... 5 more
          Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route[[From[switchyard://RoutingService?namespace=urn%3Aswit... because of Cannot lookup: properties from registry: CdiRegistry[1539734637] with expected type: interface org.apache.camel.Component due: No org.apache.deltaspike.core.api.provider.BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts.
                    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:176)
                    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:712)
                    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1749)
                    at org.apache.camel.impl.DefaultCamelContext.addRouteDefinitions(DefaultCamelContext.java:656)
                    at org.apache.camel.impl.DefaultCamelContext.addRouteDefinition(DefaultCamelContext.java:661)
                    at org.switchyard.component.camel.deploy.CamelActivator.handleImplementation(CamelActivator.java:247)
                    ... 10 more
          Caused by: org.apache.camel.NoSuchBeanException: Cannot lookup: properties from registry: CdiRegistry[1539734637] with expected type: interface org.apache.camel.Component due: No org.apache.deltaspike.core.api.provider.BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts.
                    at org.apache.camel.impl.CompositeRegistry.lookup(CompositeRegistry.java:58)
                    at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookup(PropertyPlaceholderDelegateRegistry.java:62)
                    at org.apache.camel.impl.DefaultCamelContext.getPropertiesComponent(DefaultCamelContext.java:2180)
                    at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:1010)
                    at org.apache.camel.util.CamelContextHelper.parseBoolean(CamelContextHelper.java:325)
                    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:832)
                    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:171)
                    ... 15 more
          Caused by: java.lang.IllegalStateException: No org.apache.deltaspike.core.api.provider.BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts.
                    at org.apache.deltaspike.core.api.provider.BeanManagerProvider.getInstance(BeanManagerProvider.java:90)
                    at org.apache.deltaspike.core.api.provider.BeanProvider.getBeanManager(BeanProvider.java:379)
                    at org.apache.deltaspike.core.api.provider.BeanProvider.getContextualReference(BeanProvider.java:166)
                    at org.apache.camel.component.cdi.CdiBeanRegistry.lookup(CdiBeanRegistry.java:51)
                    at org.apache.camel.impl.CompositeRegistry.lookup(CompositeRegistry.java:49)
                    ... 21 more
          

           

          Module definitions are located inside release project under

          jboss-as7/modules/src/main/resources/external/apache/deltaspike/core-api

          jboss-as7/modules/src/main/resources/external/camel/cdi

          jboss-as7/modules/src/main/resources/switchyard/components/camel/resources

           

          As sugessted I've tried also to modify weld-core module definition which is located under jboss-as7/modules/src/main/resources/external/weld-core

           

          Best regards,

          Lukasz

          • 2. Re: JBoss modules and CDI extension
            jharting

            I think it's not currently possible to have a CDI extension in a module that is not part of the deployment. Nevertheless, it should be possible to implement a deployer that registers the extension such as https://github.com/jbossas/jboss-as/blob/master/jaxrs/src/main/java/org/jboss/as/jaxrs/deployment/JaxrsCdiIntegrationProcessor.java#L106

            1 of 1 people found this helpful
            • 3. Re: JBoss modules and CDI extension
              splatch

              Hey Jozef,

              Thanks for tip, will try implement that as we already have custom deployers in switchyard.

              • 4. Re: JBoss modules and CDI extension
                alesj
                1 of 1 people found this helpful
                • 5. Re: JBoss modules and CDI extension
                  splatch

                  Thanks all of you for hints. The deployment processor helped me to get CDI extension loaded during start up.

                   

                  However deltaspike is still unable to work properly because BeanManagerProvider bind BeanManager instance to classloader. Because of that for classes who load this class from other dependency path it doesn't work.

                   

                  For example my deployment unit is called "soap-proxy" and it is not CDI deployment unit (no beans.xml) - because I have two different classloaders it causes problems. BeanManager instance is bound to switchyard component class loader but it is not bound to deltaspike module classloader used later by deployment unit.

                  More over the switchyard component class loader is shared between different deployment units and if I load cdi aware deployment unit first it breaks second - non aware.