Ask the Expert

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?

    Requires Free Membership to View

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.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,
      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 first published in April 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: