5 Replies Latest reply: Jan 13, 2012 3:12 AM by Christos Vasilakis RSS

Access EJB

Christos Vasilakis Newbie

Hi there,


I have defined a Singleton EJB as





public class Routing {

private HashMap<String, HashMap<String, NE>> routing;



public void init() {



routing  =  new HashMap<String, HashMap<String, NE>>();




public void cleanup() {





public void addRouteFromRegistrationCommandMsg(RegistrationCommandMessage message) {




On my RouteBuilder I


       .unmarshal().json(JsonLibrary.Jackson, gr.forthnet.nms.svcrrd.service.messages.RegistrationCommandMessage.class)

           .bean(Routing.class, "addRouteFromRegistrationCommandMsg(gr.forthnet.nms.svcrrd.service.messages.RegistrationCommandMessage)")                       

       .log("registration completed");


The bean is successfully called together with json unmarshalling. The problem is that routing instance variable is NULL and I get a NullPointerException so probably it is not the EJB but a new bean instance. I thought because the bean is exposed as CDI I could have access to it.


The other method is to use camel-ejb component. I tried it too (and installed the camel-ejb component on the jboss instance) but I couldn't get access to it. Something is wrong with the JNDI name and the way I call it.


Any tips on how to proper access the EJB through the route?




  • 1. Re: Access EJB
    Keith Babo Master

    Is there a reason why this needs to be an EJB?  The bean() call you're making now will create the bean instance in Camel vs. calling an existing bean reference.  If you wanted to handle with a CDI bean within the application, you can do that and refer to it by name within the route.


    One other comment, you can use the declarative transformation support in SwitchYard to handle the JSON unmarshalling instead of declaring that explicitly in your route.  It will certainly work as you have it here, so I'm just pointing it out as an alternative (preferred in my mind) option.  If you're interested in going that direction, here's an example of what that looks like:




    ~ keith

  • 3. Re: Access EJB
    Christos Vasilakis Newbie

    Hi Keith


    adding "bean:Routing?method=addRouteFromRegistrationCommandMsg" worked flawlessly, it uses the EJB Component not a new bean instance.


    Basically what I am trying to accomplish is this. I have many distributed clients that submit registration messages through JMS to a main server. I use an EJB there first for shared singleton state (basically the hashmap) between invocations and second for the concurrency reasons. Probably later use a persistent context entiymanager to store the state in a db instance and need transactions... Or probably I missing the big picture here ..


    I tried adding the transform.json tags and removing the unmarsal code from the route but I got an exception from camel that it couldn't find the type converter.



  • 4. Re: Access EJB
    Keith Babo Master

    Hmm ... that's interesting about the type converter error.  The JSON transformer route should definitely work, so if you want to pursue it further, just attach an application that I can use to reproduce the problem and we'll fix it up.

  • 5. Re: Access EJB
    Christos Vasilakis Newbie

    Hi Keith


    you can find the app to test on github




    on the parent folder just do


    mvn clean install -Dmaven.test.skip=true


    Then copy the resulting jars to the jboss7 deployments directory. First the model and then the service

    cp svc-rrd-model/target/svc-rrd-model-1.0-SNAPSHOT.jar  /jboss-as-7.1.0.CR1b/standalone/deployments/

    cp svc-rrd-service/target/svc-rrd-service-1.0-SNAPSHOT.jar  jboss-as-7.1.0.CR1b/standalone/deployments/


    Afther they are deployed:

    cd svc-rrd-service

    mvn test


    This will send a JMS message to the server containing the JSON payload. At the server console you will get an exception

    Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.String to the required type: gr.forthnet.nms.svcrrd.service.messages.RegistrationCommandMessage ....


    Let me know if you need more information