TomEE: calling a remote EJB from different machines

580 Views Asked by At

I have two TomEE instances (currently different containers) and I want to get Remote EJB working between them. However, I'm having issues doing this.

First I enabled remote EJB support on the TomEE instances. I added the following to the system.properties file. Based on this thread Remote EJB lookup using OpenEJB in Tomee

tomee.remote.support = true
tomee.serialization.class.blacklist = -
tomee.serialization.class.whitelist = *
openejb.system.apps = true
openejb.servicemanager.enabled = true

My Server TomEE Ear is deployed successfully and I can see the JNDI names of my Remote Ejbs.

INFO: Extracting jar: /usr/local/tomee/apps/simpleEJB-ear-1.0.ear
INFO: Extracted path: /usr/local/tomee/apps/simpleEJB-ear-1.0
INFO: Found EjbModule in classpath: /usr/local/tomee/apps/simpleEJB-ear-1.0/simpleEJB-ejbs-1.0.jar
INFO: Configuring enterprise application: /usr/local/tomee/apps/simpleEJB-ear-1.0
INFO: Enterprise application "/usr/local/tomee/apps/simpleEJB-ear-1.0" loaded.
INFO: Creating dedicated application classloader for simpleEJB-ear-1.0
INFO: Assembling app: /usr/local/tomee/apps/simpleEJB-ear-1.0
INFO: Jndi(name=global/simpleEJB-ear-1.0/simpleEJB-ejbs-1.0/HelloImpl!com.wk.Hello) --> Ejb(deployment-id=HelloImpl)
INFO: Jndi(name=global/simpleEJB-ear-1.0/simpleEJB-ejbs-1.0/HelloImpl) --> Ejb(deployment-id=HelloImpl)
INFO: Deployed Application(path=/usr/local/tomee/apps/simpleEJB-ear-1.0)

Now when I do a lookup from another TomEE instance I get RemoteEJBExceptions. Below is my client code that's deployed on TomEE that looks up said Remote EJB:

@PostConstruct
public void init() {
Properties props = new Properties();
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
p.put(Context.PROVIDER_URL, "http://172.17.0.2:8080/tomee/ejb");

InitialContext ic = new InitialContext(props);
//hello = (com.wk.Hello) ic.lookup("com.wk.Hello");
hello = (com.wk.Hello) ic.lookup("com.wk.Hello");
}

However, the lookup fails with the following exception:

Caused by: javax.ejb.EJBException: javax.naming.NameNotFoundException: Name [com.wk.Hello] is not bound in this Context. Unable to find [com.wk.Hello].

What am I missing to get this working? My goal is to move some of our JavaEE applications off of glassfish and onto TomEE so I'm working on a POC to see how certain JavaEE functionalities will work under TomEE.

Any help would be greatly appreciated. Thanks!

1

There are 1 best solutions below

0
Gerb On

I actually figured out what I did wrong and I now have Remote EJB talking to each other on different TomEE instances. Two things, one I had the wrong JDNI name. The com.wk.Hello style JDNI name lookup seem to be a Glassfish Specific way and not a true JavaEE standard way. So I changed the JDNI name to HelloImplRemote. If you grep the catalina logs for JNDI you will see the various ways that you can lookup the JNDI resource.

The other issue is I had two different instances of Properties.

Properties props = new Properties();
Properties p = new Properties();

One is props which is empty and another is p that sets the context factory and provider URL, however, I was mistakenly using empty props when initializing the InitialContext object and not the correct properties instance that correctly set everything.

Anyways after fixing those two things everything seem to be working!