@BeanInject does not work in switchyard camel implementation

Solution Verified - Updated -

Issue

  • Trying to inject a bean into a camel route using the annotation @BeanInject. This annotation should be available from Camel 2.13 and it is also explained in the Fuse 6.2.1 Apache camel development guide from RedHat that this is possible.

  • We have created a test project to illustrate the issue. The test project consists of a camel route where we try to inject TestBean using BeanInject and then call the method getMessage() during deployment of the camel route. The Testbean is annotated with the @Named annotation and the bean.xml file is present (which should be enough to enable CDI)

  • When we deploy the switchyard application we get a nullpointerexception when we call the getMessage method of the injected bean (it seems that the bean is not injected). One thing we tried is to access the bean through the method beanRef inside the route. That works well (but if we use the name of a bean that does not exist it will fail during deploy). We interpret that as verification that the bean is in the registry.

  • We want to inject a bean into the Routebuilder that we can access not only during the route but also at deploy, and thus the .beanRef is not feasible in this situation as that is only executed when a message arrives and not during deploy.

  • We have also tried to retrieve the bean through the camel context using getContext().getRegistry().lookupByName("TestBean"); but without any luck

  • We get the below exception in the logs,

22:59:34,090 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "beaninjection.jar" (runtime-name: "beaninjection.jar")
22:59:34,118 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016002: Processing weld deployment beaninjection.jar
22:59:34,141 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."beaninjection.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."beaninjection.jar".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment "beaninjection.jar"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_91]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_91]
Caused by: java.lang.NullPointerException
    at org.switchyard.as7.extension.deployment.SwitchYardConfigProcessor$JBossPropertyResolver.set(SwitchYardConfigProcessor.java:106)
    at org.switchyard.as7.extension.deployment.SwitchYardConfigProcessor$JBossPropertyResolver.access$000(SwitchYardConfigProcessor.java:87)
    at org.switchyard.as7.extension.deployment.SwitchYardConfigProcessor.deploy(SwitchYardConfigProcessor.java:60)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120) [jboss-as-server-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10]
    ... 5 more

22:59:34,148 ERROR [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS015870: Deploy of deployment "beaninjection.jar" was rolled back with the following failure message: 
{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"beaninjection.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"beaninjection.jar\".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment \"beaninjection.jar\"
    Caused by: java.lang.NullPointerException"}}
22:59:34,154 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015877: Stopped deployment beaninjection.jar (runtime-name: beaninjection.jar) in 6ms
23:01:04,274 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "switchyard-example.jar" (runtime-name: "switchyard-example.jar")

Environment

  • Red Hat JBoss Fuse
    • 6.2.x
  • Switchyard

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content