Not able to access Remote EJB from the client (Junit ) .LookUp is failing

734 views Asked by At

I am new to EJB as well as Geronimo server. I want to create Junit POC for EJB on Geronimo Server. But on Lookup to Stateless Session bean its giving me this error.

Please find the exception below

javax.naming.NamingException: Cannot lookup '/MyStatelessSessionBeanRemote'. [Root exception is java.rmi.RemoteException: Cannot read the response from the server. The class for an object being returned is not located in this system:; nested exception is:
java.lang.ClassNotFoundException: sampleear.RemoteBusinessInterface]
at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:240)
at javax.naming.InitialContext.lookup(InitialContext.java:363)
at test.SampleTest.setUp(SampleTest.java:44)
at junit.framework.TestSuite.runTest(TestSuite.java:208)

I am using Geronimo server 2.1 and I have also deployed the EAR file in geronimo server. EAR file gets successfully deployed showing on the Geronimo server.

Please find the Logs below

2019-07-01 14:39:46,221 INFO  [config] Configuring Service(id=Default BMP Container, type=Container, provider-id=Default BMP Container)
2019-07-01 14:39:46,222 INFO  [config] Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
2019-07-01 14:39:46,222 INFO  [config] Configuring app: sampleear/sample-ejb/1.0/ejb
2019-07-01 14:39:46,269 INFO  [OpenEJB] Auto-deploying ejb MyStatelessSessionBean: EjbDeployment(deployment-id=sample-ejb/MyStatelessSessionBean)
2019-07-01 14:39:46,277 INFO  [config] Loaded Module: sampleear/sample-ejb/1.0/ejb
2019-07-01 14:39:46,555 INFO  [startup] Assembling app: /tmp/geronimo-deployer1011310413181662917.tmpdir/SampleEJB.jar
2019-07-01 14:39:46,557 ERROR [startup] Jndi(name=MyStatelessSessionBeanRemote) cannot be bound to Ejb(deployment-id=sample-ejb/MyStatelessSessionBean).  Name already taken by Ejb(deployment-id=SampleEJB.jar/MyStatelessSessionBean)
2019-07-01 14:39:46,557 INFO  [startup] Created Ejb(deployment-id=sample-ejb/MyStatelessSessionBean, ejb-name=MyStatelessSessionBean, container=Default Stateless Container)
2019-07-01 14:39:46,558 INFO  [startup] Deployed Application(path=/tmp/geronimo-deployer1011310413181662917.tmpdir/SampleEJB.jar)
2019-07-01 14:39:46,673 INFO  [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
2019-07-01 14:39:46,676 INFO  [XSRFHandler] Updated HTML content with XSRF JavaScript for requestURI=/console/portal//Applications/Deploy%20New

Junit - Client

public class SampleTest extends TestCase {

  protected MyStatelessSessionBean remoteBusinessIntf;


  public void setUp() throws Exception {
    super.setUp();
    Properties prop = new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
    prop.put("java.naming.provider.url", "ejbd://127.0.0.1:4201");
//    prop.put("openejb.authentication.realmName","geronimo-admin");
//    prop.put("java.naming.security.principal","system");
//    prop.put("java.naming.security.credentials","manager");
    Context context = new InitialContext(prop);
    remoteBusinessIntf = (MyStatelessSessionBean) context.lookup("MyStatelessSessionBeanRemote"); // Giving error on this.

}

public void testSaveBook() {
        System.out.println("ok");
        remoteBusinessIntf.sayHello("EJB");
    }

}

Stateless Session Bean

package sampleear;
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
public class MyStatelessSessionBean implements RemoteBusinessInterface {
    public String sayHello(String name) {
        return getClass().getName() + " says hello to "+ name + ".";
    }
}

Remote Interface

package sampleear;

import javax.ejb.Remote;

@Remote
public interface RemoteBusinessInterface {
    public String sayHello(String name);
}

Deployed EJB Application

 Component Name      State  Commands
 org.apache.geronimo.configs/mejb/2.1.4/car      running     Stop    Restart     Uninstall 
 org.apache.geronimo.plugins/agent/2.1.4/car     running     Stop    Restart     Uninstall 
 sampleear/sample-ejb/1.0/ejb    running     Stop    Restart     Uninstall 

Geronimo v2.1.4

No Modifications to port.Default Port is used.


Port Details of Geronimo

Startup completed in 31.119s seconds
  Listening on Ports:
    1050 0.0.0.0 CORBA Naming Service
    1099 0.0.0.0 RMI Naming
    1527 0.0.0.0 Derby Connector
    2001 0.0.0.0 OpenEJB ORB Adapter
    4201 0.0.0.0 OpenEJB Daemon
    6882 0.0.0.0 OpenEJB ORB Adapter
    8009 0.0.0.0 Tomcat Connector AJP AJP
    8080 0.0.0.0 Tomcat Connector HTTP BIO HTTP
    8443 0.0.0.0 Tomcat Connector HTTPS BIO HTTPS
    9999 0.0.0.0 JMX Remoting Connector
   61613 0.0.0.0 ActiveMQ Transport Connector
   61616 0.0.0.0 ActiveMQ Transport Connector

I have again created the fresh Geronimo server and deployed the EJB Application.This time haven't got any deployment error. Please find the logs below.

2019-07-02 10:28:18,242 INFO  [config] Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
2019-07-02 10:28:18,242 INFO  [config] Configuring Service(id=Default BMP Container, type=Container, provider-id=Default BMP Container)
2019-07-02 10:28:18,242 INFO  [config] Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
2019-07-02 10:28:18,243 INFO  [config] Configuring app: sampleear/sample-ejb/1.0/ejb
2019-07-02 10:28:18,275 INFO  [OpenEJB] Auto-deploying ejb MyStatelessSessionBean: EjbDeployment(deployment-id=sample-ejb/MyStatelessSessionBean)
2019-07-02 10:28:18,281 INFO  [config] Loaded Module: sampleear/sample-ejb/1.0/ejb
2019-07-02 10:28:18,555 INFO  [startup] Assembling app: /tmp/geronimo-deployer7186189966556040174.tmpdir/SampleEJB.jar
2019-07-02 10:28:18,558 INFO  [startup] Jndi(name=MyStatelessSessionBeanRemote) --> Ejb(deployment-id=sample-ejb/MyStatelessSessionBean)
2019-07-02 10:28:18,558 INFO  [startup] Created Ejb(deployment-id=sample-ejb/MyStatelessSessionBean, ejb-name=MyStatelessSessionBean, container=Default Stateless Container)
2019-07-02 10:28:18,558 INFO  [startup] Deployed Application(path=/tmp/geronimo-deployer7186189966556040174.tmpdir/SampleEJB.jar)
2019-07-02 10:28:18,669 INFO  [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
2019-07-02 10:28:18,673 INFO  [XSRFHandler] Updated HTML content with XSRF JavaScript for requestURI=/console/portal//Applications/Deploy%20New
0

There are 0 answers