0
votes

Hi i am Working with openEJB in Tomee jaxrs(1.7.4) server, i have a Web project and a EJB project running on the same TomEE sever.

I have deployed the EJB project in the webapps folder of the TomEE server and can see the EJB's are starting when the server starts.

 INFO: Enterprise application "C:\Apache_Software\OPEN_EJB\Server\webapps\OpenEjbServer" loaded.
Sep 08, 2016 10:08:39 AM org.apache.openejb.assembler.classic.Assembler createApplication
INFO: Assembling app: C:\Apache_Software\OPEN_EJB\Server\webapps\OpenEjbServer
Sep 08, 2016 10:08:39 AM org.apache.openejb.assembler.classic.JndiBuilder bind
INFO: Jndi(name=calcRemote) --> Ejb(deployment-id=calc)
Sep 08, 2016 10:08:39 AM org.apache.openejb.assembler.classic.JndiBuilder bind
INFO: Jndi(name=global/OpenEjbServer/calc!org.superbiz.stateless.basic.CalculatorBeanRemote) --> Ejb(deployment-id=calc)
Sep 08, 2016 10:08:39 AM org.apache.openejb.assembler.classic.JndiBuilder bind
INFO: Jndi(name=global/OpenEjbServer/calc) --> Ejb(deployment-id=calc)
Sep 08, 2016 10:08:39 AM org.apache.openejb.cdi.CdiBuilder initSingleton

Below is one of the @Stateless beans in the EJB project

 @Remote
 public interface CalculatorBeanRemote {
   public int add(int a, int b);
 }

 @Stateless
 public class CalculatorBean implements CalculatorBeanRemote {
  @Override
   public int add(int a, int b) {
      return a + b;
   }
 }

from EJB project using servlet I can do the JNDI Lookup using the following code.

Properties p = new Properties();
p.put("java.naming.factory.initial","org.apache.openejb.client.LocalInitialContextFactory");
p.put("java.naming.provider.url", "ejbd://localhost:4201");
Context remoteContext = new InitialContext(p);
    try {
        Object ojb = remoteContext.lookup("calcRemote");
    }catch(Exception e){}

When trying to do the same call when the EJB is deploy separately I get

javax.naming.NameNotFoundException: Name "calcRemote" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:197)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.ContextWrapper.lookup(ContextWrapper.java:115)
at javax.naming.InitialContext.lookup(InitialContext.java:392)

How can I do a local or remote JNDI Lookup from Web project to the EJB when it is deployed on the same TomEE server or different TomEE Server?

What could be cause of this error? Appreciate any help

1

1 Answers

0
votes

you use a Local for a remote bean so it doesnt work, instead of LocalInitialContextFactory switch to remote one, check http://tomee.apache.org/clients.html for the detail