Q

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:
   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();
Internal clients of an EJB, such as servlets, can simply create an InitialContext using the default constructor, as shown here:
   javax.naming.Context context =
      new javax.naming.InitialContext();
   Object homeObject = context.lookup("java:comp/env/myejb");
   MyEJBHome home = (MyEJBHome)homeObject;
   MyEJB myEJB = MyEJBHome.create();

This was last published in April 2004

Dig Deeper on Java Web Services

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close