Search code examples
javajakarta-eeservletsjavabeanswebsphere-7

Call bean of project A from servlet of project B


I have a Java EE server that calls a bean in project A from a Servlet in project B. Both projects are in the same "cell" (cluster). I would like to go through a load balancer as well. I do not want to use Message Driven Beans or Web Services.

Is there any other way to do this, and how can would that be implemented?


Solution

  • Actually after some time I found the solution:

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming
    .WsnInitialContextFactory");
    env.put(Context.PROVIDER_URL,"corbaloc::boris:9811,:natasha
    :9812");
    Context ctx = new InitialContext(env);
    TestEJBHome home = (TestEJBHome)
    PortableRemoteObject.narrow(ctx.lookup("ejb/ejbs/TestEJBHome"),
        TestEJBHome.class);
    TestEJB bean = home.create();
    

    Got it from here: http://www.ibm.com/developerworks/websphere/techjournal/0807_pape/0807_pape.html