Discussions

EJB design: EB-EJB communications on different machines

  1. Hi,

    what do I have to do if I want to let EJB A call a method on EJB B,
    that resides on another machine. Till now I only know Client-EJB
    comm and and EJB-EJB comm on the same machine.
    What do I have to take into account, if I want to develop EJB A
    and EJB B on the same machine and move EJB B to another
    machine later. How can I reassure that comm from A to B
    on the single machine is location-transparen already?
    I want to simulate that the beans are located on different machines on one machineso they can be distributed easily.

    TIA
    Frank

    TIA
    Frank

  2. Hi,

    You can do this using jndi.When retrieving the home object for EJB B pass the javax.naming.Context.PROVIDER_URL with the value for the server hosting EJB B.
  3. Hi,
    Use JNDI.Pass the javax.naming.Context.PROVIDER_URL with the value of the server hosting EJB B

    Bye
  4. Ok, I did like you said

    Properties props = new Properties();
    props.put javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");
    props.put(javax.naming.Context.PROVIDER_URL,"iiop://oleander:1050");
    Context jndi = new javax.naming.InitialContext(props);
    InitialContext initial = new javax.naming.InitialContext(props);
    MySession2Home home =
    (MySession2Home)javax.rmi.PortableRemoteObject.narrow(initial.lookup("java:c
    omp/env/ejb/MySession2"), MySession2Home.class);
      }
      catch (Exception e) {e.printStackTrace();}
     }

    But I get this exception:
    javax.naming.NameNotFoundException: No object bound to name
    java:comp/env/ejb/MySession2

    I deployed bean B on my machine using a JNDI name 'MySession2'. Doesn't it
    get bound to
    java:comp/env/ejb/MySession2 automatically?

    TIA
    Frank


  5. Hi Frank,

    Check whether u can get a reference to MySession2Home on the m/c where the EJB is deployed(In this case create a client on oleander and try getting the reference)