Details
-
Enhancement
-
Resolution: Done
-
Major
-
jboss-fuse-6.2.1
-
None
-
%
-
6.3 Sprint 4 (Mar 28 - Apr 29)
Description
- `@BeanInject` camel annotation does not work
@Named("TestBean") public class TestBean { private static final Logger LOG = LoggerFactory.getLogger(Route.class); public String getMessage() { System.out.println("Invoked the getMessage ...."); LOG.info("Message from TestBean"); return "Message from TestBean"; } } /** * @author Viral Gohel */ public class Route extends RouteBuilder { /** * The Camel route is configured via this method. The from endpoint is * required to be a SwitchYard service. */ private static final Logger LOG = LoggerFactory.getLogger(Route.class); @BeanInject("b") // does not inject TestBean b; public void configure() { b.getMessage(); // Retrieving the bean from the camel context // Object o = getContext().getRegistry().lookupByName("TestBean"); // LOG.info(o.getClass().toString()); LOG.info("Before"); // Trying to call a method of the injected bean LOG.info(b.getMessage()); LOG.info("After"); from("switchyard://Inbound").log("Received message for 'Inbound' : ${body}") // Refer to the bean inside the route .beanRef("TestBean", "getMessage()"); }
- Using Fuse on EAP, and when i deploy the attached example, i get the NPE exception as below,
Caused by: org.switchyard.SwitchYardException: SWITCHYARD033003: Failed to initialize Java DSL class com.example.switchyard.switchyard_injection_test.Route
at org.switchyard.component.camel.RouteFactory.createRoute(RouteFactory.java:201)
at org.switchyard.component.camel.RouteFactory.createRoute(RouteFactory.java:166)
at org.switchyard.component.camel.RouteFactory.getRoutes(RouteFactory.java:77)
at org.switchyard.component.camel.deploy.CamelActivator.getRouteDefinition(CamelActivator.java:177)
at org.switchyard.component.camel.deploy.CamelActivator.handleImplementation(CamelActivator.java:93)
... 10 more
Caused by: java.lang.NullPointerException
at com.example.switchyard.switchyard_injection_test.Route.configure(Route.java:26)
at org.switchyard.component.camel.RouteFactory.createRoute(RouteFactory.java:194)
... 14 more
- To my understanding, CDI Bean Manager is integrated with Camel Bean Registry to allow you to reference CDI Beans in your Camel routes. User cannot access CamelContext directly in SwitchYard or configure via spring application context.
- I don't get the NPE, when i use camel spring xml file, component service definition.
Looking here, http://camel.apache.org/cdi.html, i would believe this should work.