2

I am trying to access an EJB via JSE Standalone application.

I was struggling a lot with JNDI Names not being found during lookup.

After some research without any solution I found in the Glassfish server log after a deploy a message stating something like:

"[glassfish 4.1] [INFO] [AS-EJB-00054] [javax.enterprise.ejb.container] [tid: _ThreadID=47 _ThreadName=admin-listener(4)] [timeMillis: 1424811833554] [levelValue: 800] [[ Portable JNDI names for EJB HelloBean:java:global/ponteWS/HelloBean!br.com.pontews.HelloRemote, java:global/ponteWS/HelloBean!br.com.pontews.HelloBean]]] "

I tried the remote name and voilá!!! It works.

I tried the other name and did not work.

Here comes the questions:

1-Why the JNDI name is so weird???? Is there something I can do in order to avoid the package name in front of the name of the bean? 2-What is the error I get when acessing the bean directly instead the HelloRemote Interface?

Here is the HelloRemote:

package br.com.pontews;

import javax.ejb.Remote;

@Remote
public interface HelloRemote {

    public String sayHello(String name);
}

Here is the Bean:

package br.com.pontews;
import java.io.Serializable;
import javax.ejb.LocalBean;
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless(name="HelloBean")
@LocalBean
@Remote
public class HelloBean implements HelloRemote, Serializable {

    /**
     * 
     */
    private static final long   serialVersionUID    = 1L;

    /**
     * Default constructor.
     */
    public HelloBean() {
    }

    public String sayHello(String name) {
        return "Hello," + name + ".!" ;
    }

}

Here is the call that works:

Object lookup = 
ctx.lookup("java:global/ponteWS/HelloBean!br.com.pontews.HelloRemote");

Here is the call that does not works:

Object lookup = 
ctx.lookup("java:global/ponteWS/HelloBean!br.com.pontews.HelloBean");

And finally the error I get with call that does not work:

Exception in thread "main" javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.rmi.RemoteException: CORBA NO_IMPLEMENT 1398079489 Maybe; nested exception is: org.omg.CORBA.NO_IMPLEMENT: ----------BEGIN server-side stack trace---------- org.omg.CORBA.NO_IMPLEMENT: WARNING: 01000001: Missing local value implementation vmcid: SUN minor code: 1 completed: Maybe : : : Caused by: java.lang.ClassNotFoundException: br.com.pontews.EJB31_Generated__HelloBean__Intf____Bean (no security manager: RMI class loader disabled)

Thanks

mrossini
  • 378
  • 3
  • 10

1 Answers1

0

The name you are using to lookup () has the format as specified by the EJB specification.

In case of glassfish it should also be possible to use the fully qualified name of the remote business interface to lookup the bean (https://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment). In your case this would be

br.com.pontews.HelloRemote

If you still have problems on the lookup the instructions here might help: (from https://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB)

Step 1. Use the no-arg InitialContext() constructor in your code.

The most common problem developers run into is passing specific JNDI bootstrapping properties to InitialContext(args). Some other vendors require this step but GlassFish does not. Instead, use the no-arg InitialContext() constructor.

Step 2. Pass the global JNDI name of the Remote EJB to InitialContext.lookup()

Stand-alone java clients do not have access to a component naming environment (java:comp/env) or to the @EJB annotation, so they must explicitly use the global JNDI name to lookup the Remote EJB. (See here for more information on how global JNDI names are assigned to EJB components) Assuming the global JNDI name of the Remote EJB is "FooEJB" :

For Beans with a 3.x Remote Business interface :

Foo foo = (Foo) new InitialContext().lookup("FooEJB");

Note that in the EJB 3.x case the result of the lookup can be directly cast to the remote business interface type without using PortableRemoteObject.narrow().

For EJB 2.1 and earlier session/entity beans :

Object homeObj = new InitialContext().lookup("FooEJB");

FooHome fooHome = (FooHome) PortableRemoteObject.narrow(homeObj,FooHome.class);

Foo foo = fooHome.create(...) Step 3. Include the appropriate GlassFish .jars in the java client's classpath.

For GlassFish 3.

Include $GLASSFISH_HOME/glassfish/lib/gf-client.jar in the client's classpath.

E.g., assuming the application classes are in /home/user1/myclasses and the main client class is acme.MyClient :

java -classpath $GLASSFISH_HOME/glassfish/lib/gf-client.jar:/home/user1/myclasses acme.MyClient

Note that the Java EE 6 API classes are automatically included by gf-client.jar so there is no need to explicitly add javaee.jar to the classpath. gf-client.jar refers to many other .jars from the GlassFish installation directory so it is best to refer to it from within the installation directory itself rather than copying it(and all the other .jars) to another location.

Note: gf-client.jar is located in $GLASSFISH_HOME/modules/gf-client.jar in GlassFish v3.

wumbrath
  • 59
  • 3
  • Thanks. Understood and solved my problem. Just added mappedName attribute in Stateless annotation and works like I was thinking it should do. – mrossini Feb 26 '15 at 21:42