users@glassfish.java.net

Glassfish EJB 3 lookup from a client on another machine

From: <glassfish_at_javadesktop.org>
Date: Sun, 07 Feb 2010 13:36:36 PST

Hello,
    I am very confused on how a client on another machine can use an EJB deployed on a server using Glassfish. I am also rather surprised that for such topic I couldn't find a clear answer. It should be the purpose of the whole JavaEE and in particular EJB to provide service on a server and clients from other computers should be able to use that service.
I have dug around for weeks, bought several books, and made many many tests with simple applications, no way. I always get errors and , the more I look into it the more confusing and frustrating becomes. The answers I have found around are contraddictory and basically none worked.
I have almost decided to give up Glassfish and use JBoss (it seems that there is more documentation about this issue) or go back to RMI, but before doing that, I would like to see if someone in this forum is capable to give me some help on this subject.

Just to be clear: I have no problems to use injection on a single machine as long as the client application is in the same directory of the ejb (the same Netbeans project). But when I try to use lookup the confusion starts even on the same machine.

I have created an Enterprise Java Application using Netbeans 6.8 with also a client application (no web application)

Here is my simple ejb I am trying to use:
@Stateful
public class PlcServiceBean implements ModelService { ... }

@Remote
public interface ModelService { ... }

When I run the whole application, everything works fine. Namely the client-application does what it is supposed to do.

In Glassfish the deployed Module Name is SCADA-ejb.jar, and the Component name is PlcServiceBean.
I have tried the following in the local machine:

InitialContext ic = new InitialContext();
     ModelService mdl = (ModelService) ic.lookup("java:comp/env/SCADA-ejb/PlcServiceBean");

and many other variations, no way. The error I get is :

javax.naming.NamingException: Lookup failed for 'java:comp/env/PlcServiceBean' in SerialContext targetHost=localhost,targetPort=33835 [Root exception is javax.naming.NameNotFoundException: No object bound to name java:comp/env/PlcServiceBean]


I have tried the fully qualified name (the directory structure is model.sessionbeans)
ModelService mdl = (ModelService) ic.lookup("java:comp/env/model.sessionbeans.PlcServiceBean");

the error I get is similar:
javax.naming.NamingException: Lookup failed for 'java:comp/env/model.sessionbeans.PlcServiceBean' in SerialContext targetHost=localhost,targetPort=33835 [Root exception is javax.naming.NameNotFoundException: No object bound to name java:comp/env/model.sessionbeans.PlcServiceBean]


I have created a standalone POJO Client similar to the previous one (importing all the necessary libraries, JavaEE, Glassfish) and tried to connect using the following:

       Properties props = new Properties();
        props.setProperty("java.naming.factory.initial",
                "com.sun.enterprise.naming.SerialInitContextFactory");
        props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
        props.setProperty("org.omg.CORBA.ORBInitialPort","33878");

        InitialContext ic = new InitialContext(props);
        ModelService mdl = (ModelService) ic.lookup("java:comp/env/PlcServiceBean");

The error I get is the following:
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:comp/env/PlcServiceBean' in SerialContext targetHost=localhost,targetPort=33878 [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]

I have looked into the ports configuration of my Glassfish under Netbeans and I have the following ports:
HTTP ports: 33846 ,33879 ,33878
IIOP ports: 33836 ,33835 ,33837

I have tried all of them without success.
I have installed another instance of Glassfish from scratch (outside NetBeans), looked into the ports configuration and tried the same tests, with the same results.

From the Glassfish administration panel I couldn't find any information to what is the correct way to connect a client. I have run the asadmin list-jndi-entries and the only port that gives some information is the administration port 33846 which is a HTTP port. I have expected to see some "life" from the other ports IIOP.
 
Also the list I have got is rather confusing. I can see model.sessionbeans.ModelService in the list but never the beans name PlcServiceBean , why ???

Well this is it, I don't know what to do next. I have dug in the Glassfish documentation with no use.
I am really surprised that the lookup receives so poor attention in the official documentation since it is the only way to use the EJB from a remote client (injection cannot be used unfortunately).

So any help to solve this mistery will be very welcome.
Thank You,
Walter
[Message sent by forum member 'diwa130' (w_diurno_at_yahoo.com)]

http://forums.java.net/jive/thread.jspa?messageID=385330