Q
Problem solve Get help with specific problems with your technologies, process and projects.

How can I communicate to EJB in another server?

I want to communicate to an EJB in another server. Since this EJB to EJB call is between servers, it is showing an error at the time of look up. My server is JBoss. I am stuck with this problem -- any advice? One difference between accessing EJBs from local clients vs. remote clients is in the construction of the InitialContext for the bean. Remote clients typically obtain an InitialContext via an InitialContext factory, with server-specific credentials and URL, as in the following example: Internal clients of an EJB, such as servlets, can simply create an InitialContext using the default constructor, as shown here:
   Properties props = new Properties();
   props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
             "weblogic.jndi.WLInitialContextFactory");
   props.put(javax.naming.Context.PROVIDER_URL, "t3://myhost:7001");
   props.put(javax.naming.Context.SECURITY_PRINCIPAL, "jdoe");
   props.put(javax.naming.Context.SECURITY_CREDENTIALS, "foobar");
   javax.naming.Context context =
      new javax.naming.InitialContext(props);
   Object homeObject = context.lookup("java:comp/env/myejb");
  
   MyEJBHome home = null;

   if (usingIIOP == true)
   {
      home = (MyEJBHome)PortableRemoteObject.narrow(homeObject,
                                                    MyEJBHome.class);
   }
   else
   {
      home = (MyEJBHome)homeObject;
   }

   MyEJB myEJB = MyEJBHome.create();
   javax.naming.Context context =
      new javax.naming.InitialContext();
   Object homeObject = context.lookup("java:comp/env/myejb");
   MyEJBHome home = (MyEJBHome)homeObject;
   MyEJB myEJB = MyEJBHome.create();

Dig Deeper on Topics Archive

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

SearchSoftwareQuality

SearchAWS

SearchCloudComputing

TheServerSide.com

Close