Skip to main content

javax.naming.NamingException: Lookup failed

1 reply [Last post]
N_J
Offline
Joined: 2012-12-23
Points: 0

Hi,

This is not a Web Application. It is about Application Client Container (ACC). I am trying to access EJB from a remote location. Server and client are not in the same machine.

There is a tutorial at Netbeans website where the Application Client and Enterprise Application both are in a server.

http://netbeans.org/kb/docs/javaee/entappclient.html

It is a very small tutorial. This JEE project just prints a single line.

I am trying to make the Application Client access the EJB from a remote location. Hence, I have modified the client code. I have also created jndi.properties file.

        
try {
           
            Properties props = new Properties();
           
            InputStream is =
                Main.class.getResourceAsStream("jndi.properties");
           
            props.load(is);
           
            InitialContext ctx = new InitialContext(props);
           
            MySessionRemote mySession = (MySessionRemote) ctx.lookup("stateless.MySessionRemote");
           
            System.err.println("result = " + mySession.getResult());
           
        } catch (NamingException nex) {
            nex.printStackTrace();
        }       

This is my jndi.properties file

java.naming.factory.initial = com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs = com.sun.enterprise.naming
java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
#optional.  Defaults to localhost.  Only needed if web server is running
#on a different host than the appserver
org.omg.CORBA.ORBInitialHost = localhost
#optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
org.omg.CORBA.ORBInitialPort = 3700

On this line below in client side code

MySessionRemote mySession = (MySessionRemote) ctx.lookup("stateless.MySessionRemote");

I have error

javax.naming.NamingException: Lookup failed for 'stateless.MySessionRemote' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.MySessionRemote not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at entappclient.Main.main(Main.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:438)
at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:165)
Caused by: javax.naming.NameNotFoundException: stateless.MySessionRemote not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:144)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:174)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1486)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:990)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:742)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

It works, instead of jndi.properties, if I use

@EJB
private static MySessionRemote mySession;

The problem is, as far as I know, @EJB annotation is applicable when the Application Client resides in the same machine with the EJB.

What is/are my mistake/s?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ron_Peng
Offline
Joined: 2012-12-26
Points: 0

Hello

You say "Server and client are not in the same machine".

And why you use "org.omg.CORBA.ORBInitialHost = localhost"?

I think this is why you have the eror