9 Replies Latest reply on Sep 12, 2013 11:39 AM by kcbabo

    Inject SY service into @Named bean

    l.sroka

      Hello

       

      I was trying to test CDI in simple app. I have one SY service which i want to inject into CDI bean and use it in JSF(richfaces) application.

       

      During deplyoment i have got following stacktrace.

       

      4:16:46,209 INFO  [org.switchyard] (MSC service thread 1-7) Deploying SwitchYard application 'hellosy.war'

      14:16:46,218 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016008: Starting weld service for deployment hellosy.war

      14:16:46,525 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.deployment.unit."hellosy.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."hellosy.war".WeldService: Failed to start service

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]

          at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]

      Caused by: java.lang.IncompatibleClassChangeError: org.apache.deltaspike.core.util.ClassUtils and org.apache.deltaspike.core.util.ClassUtils$GetClassLoaderAction disagree on InnerClasses attribute

          at java.lang.Class.getDeclaringClass(Native Method) [rt.jar:1.7.0_25]

          at java.lang.Class.getEnclosingClass(Class.java:1127) [rt.jar:1.7.0_25]

          at java.lang.Class.getSimpleBinaryName(Class.java:1267) [rt.jar:1.7.0_25]

          at java.lang.Class.isMemberClass(Class.java:1257) [rt.jar:1.7.0_25]

          at org.jboss.weld.util.reflection.Reflections.isNonStaticInnerClass(Reflections.java:141)

          at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:78)

          at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:123)

          at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:184)

          at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:349)

          at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82)

          at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)

          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]

          ... 3 more

       

      14:16:46,532 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015951: Admin console listening on http://127.0.0.1:9990

      14:16:46,532 ERROR [org.jboss.as] (MSC service thread 1-6) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 3567ms - Started 197 of 300 services (25 services failed or missing dependencies, 76 services are passive or on-demand)

      14:16:46,734 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "hellosy.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"hellosy.war\".WeldService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"hellosy.war\".WeldService: Failed to start service"}}

      14:16:46,769 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015877: Stopped deployment hellosy.war in 34ms

      14:16:46,771 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

      JBAS014777:   Services which failed to start:      service jboss.deployment.unit."hellosy.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."hellosy.war".WeldService: Failed to start service

       

      14:16:46,772 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"hellosy.war\".WeldService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"hellosy.war\".WeldService: Failed to start service"}}}}

       

      I attached sources.

      I'am using eclipse kepler and switchyard-as7-0.8.0.Final.zip

       

      Please help with this.
      Thanks.

        • 1. Re: Inject SY service into @Named bean
          kcbabo

          The switchyard.xml that's packaged in your WAR is empty in classes/META-INF/switchyard.xml.  Try putting the switchyard.xml in src/main/resources in your project and using a pom config like this:

           

          https://github.com/jboss-switchyard/quickstarts/blob/master/demos/helpdesk/pom.xml#L141

          • 2. Re: Inject SY service into @Named bean
            kcbabo

            Rob and I had a quick discussion on IRC about this and he brought up an important correction. Your switchyard.xml can be included in the WAR in one of the following two locations:

             

            - WEB-INF/switchyard.xml

            - META-INF/switchyard.xml

             

            The version in WEB-INF/classes/META-INF/switchyard.xml is ignored.

             

            I played around with your app a bit more and was able to keep the switchyard.xml in src/main/webapp, so that doesn't have to move.  I think your issue might be the fact that the current pom configuration bundles the dependencies in WEB-INF/lib.  Add an exclusion similar to the one in the pom I linked to or mark the associated dependencies as provided.

            • 3. Re: Inject SY service into @Named bean
              rcernich

              You may want to look at one of the quickstarts that are packaged as war, e.g.: demos/orders or demos/helpdesk

               

              These quickstarts keep switchyard.xml in src/main/resources/META-INF, which is where the tooling will look for the file.  I'm not sure how well the SwitchYard tools will work if the file is located in src/main/webapp/.

               

              Something to consider.

              1 of 1 people found this helpful
              • 4. Re: Inject SY service into @Named bean
                dward

                In the helpdesk quickstart pom.xml, you can see that the build moves the switchyard.xml into the right place:

                 

                <plugin>    
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <packagingExcludes>
                            WEB-INF/lib/*.jar,
                            WEB-INF/classes/META-INF/switchyard.xml
                         </packagingExcludes>
                        <webResources>
                            <resource>
                                <directory>target/classes/META-INF</directory>
                                <targetPath>WEB-INF</targetPath>
                                <includes>
                                    <include>switchyard.xml</include>
                                </includes>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
                
                • 5. Re: Inject SY service into @Named bean
                  l.sroka

                  Thanks a lot for all.

                  This part of pom solved all my problems.

                  It works perfect.

                  • 6. Re: Inject SY service into @Named bean
                    l.sroka

                    Hello again, let me continue in this topic.
                    This time i'm really stuck with injection. Let me introduce what is the problem: To my test app hellosy.war i am traying to inject service from another SY project, lets name it switchyard-example.

                    In hellosy app i have switchyard.xml like this.

                                    

                    <?xml version="1.0" encoding="UTF-8"?>

                    <switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:bean="urn:switchyard-component-bean:config:1.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="hellosy" targetNamespace="urn:com.example.hellosy:hellosy:1.0.0-SNAPSHOT">

                      <sca:composite name="hellosy" targetNamespace="urn:com.example.hellosy:hellosy:1.0.0-SNAPSHOT">

                        <sca:component name="InternalTestServiceBean">

                          <bean:implementation.bean class="com.example.hellosy.InternalTestServiceBean"/>

                          <sca:service name="InternalTestService">

                            <sca:interface.java interface="com.example.hellosy.InternalTestService"/>

                          </sca:service>

                          <sca:reference name="ExternalTestService">

                            <sca:interface.java interface="com.example.switchyard.switchyard_example.ExternalTestService"/>

                          </sca:reference>

                        </sca:component>

                        <sca:service name="InternalTestService" promote="InternalTestServiceBean/InternalTestService">

                          <sca:interface.java interface="com.example.hellosy.InternalTestService"/>

                        </sca:service>

                        <sca:reference name="ExternalTestService" multiplicity="0..1" promote="InternalTestServiceBean/ExternalTestService">

                          <sca:interface.java interface="com.example.switchyard.switchyard_example.ExternalTestService"/>

                        </sca:reference>

                      </sca:composite>

                    </switchyard>

                                                                                         

                    Like you see in switchyard example i have service  ExternalService which is injecting into InternalService form hellosy.war app

                     

                    When i want to deploy this 2 projects (war and jar) i have following error.

                    16:36:40,299 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "hellosy.war"

                    16:36:40,299 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015876: Starting deployment of "switchyard-example.jar"

                    16:36:40,529 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016002: Processing weld deployment hellosy.war

                    16:36:40,577 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016005: Starting Services for CDI deployment: hellosy.war

                    16:36:40,597 INFO  [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900 1.1.10 (Final)

                    16:36:40,630 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016008: Starting weld service for deployment hellosy.war

                    16:36:40,829 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."hellosy.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."hellosy.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [ExternalTestService] with qualifiers [@Default] at injection point [[field] @Inject com.example.hellosy.InternalTestServiceBean.extTestService]

                        at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)

                        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.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]

                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]

                        at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]

                    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [ExternalTestService] with qualifiers [@Default] at injection point [[field] @Inject com.example.hellosy.InternalTestServiceBean.extTestService]

                        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:311)

                        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:280)

                        at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:143)

                        at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:163)

                        at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:382)

                        at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:367)

                        at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:379)

                        at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)

                        at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)

                        ... 5 more

                     

                    16:36:40,837 INFO  [org.jboss.as] (MSC service thread 1-8) JBAS015951: Admin console listening on http://127.0.0.1:9990

                    16:36:40,838 ERROR [org.jboss.as] (MSC service thread 1-8) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 2573ms - Started 210 of 305 services (21 services failed or missing dependencies, 71 services are passive or on-demand)

                    16:36:41,042 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015871: Deploy of deployment "hellosy.war" was rolled back with no failure message

                    16:36:41,043 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "switchyard-example.jar" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.module.service.\"deployment.switchyard-example.jar\".mainjboss.module.spec.service.\"deployment.switchyard-excluded.jar\".mainMissing[jboss.module.service.\"deployment.switchyard-example.jar\".mainjboss.module.spec.service.\"deployment.switchyard-excluded.jar\".main]"]}

                    16:36:41,064 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015877: Stopped deployment hellosy.war in 21ms

                    16:36:41,064 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015877: Stopped deployment switchyard-example.jar in 20ms

                    16:36:41,065 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

                    JBAS014775:    New missing/unsatisfied dependencies:

                          service jboss.module.spec.service."deployment.switchyard-excluded.jar".main (missing) dependents: [service jboss.module.service."deployment.switchyard-example.jar".main]

                    JBAS014777:   Services which failed to start:      service jboss.deployment.unit."hellosy.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."hellosy.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [ExternalTestService] with qualifiers [@Default] at injection point [[field] @Inject com.example.hellosy.InternalTestServiceBean.extTestService]

                     

                    16:36:41,068 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.module.service.\"deployment.switchyard-example.jar\".mainjboss.module.spec.service.\"deployment.switchyard-excluded.jar\".mainMissing[jboss.module.service.\"deployment.switchyard-example.jar\".mainjboss.module.spec.service.\"deployment.switchyard-excluded.jar\".main]"]}}}

                    16:36:41,070 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS014654: Composite operation was rolled back

                    I have atached this 2 projects.

                    Thanks for any help.

                    Or maybe this is not posible to inject service from another project into other web project.

                    • 7. Re: Inject SY service into @Named bean
                      dward

                      You can only wire services between applications with a binding (either a service or reference binding).  If you know both applications are both deployed side-by-side, you can use binding.sca to allow for in-memory message passing between them.  Please check out quickstarts/demos/multiApp as an example.

                       

                      Aside, in the future, please start new forum threads for new questions, rather than "piggy-backing" on an existing thread.  Thanks!

                      • 8. Re: Inject SY service into @Named bean
                        synclpz

                        Hi David, sorry for interventing the thread. You said

                        you can use binding.sca to allow for in-memory message passing between them

                        but AFAIK, sca-binding use HTTP as a transfer layer, doesn't it? Or you've already changed something in latest release?

                        • 9. Re: Inject SY service into @Named bean
                          kcbabo

                          There are two scenarios where HTTP is used for communication with binding.sca:

                           

                          1) Using the RemoteInvoker client to speak to a service with binding.sca.

                          2) When clustering is enabled on a binding.sca reference to speak to a service located on another instance with binding.sca on a service (also with clustering enabled).

                           

                          When clustering is not enabled and the applications communicating with binding.sca are located in the same instance, then all communication is in-process/memory.  Here's an example application which uses binding.sca between multiple apps package in an EAR which will not involve any out-of-process communication via HTTP:

                          https://github.com/jboss-switchyard/quickstarts/tree/master/ear-deployment