3

I am using Netbeans and am experimenting with EJBs.

I have two projects (2 separate applications)

1- A Java ME Project called EnterpriseApp

2- A standard Java SE Project called Test

Now here is what I did - in EnterpriseApp I generated a stateless EJB called TestEJB with both local and remote interfaces. For the remote project selection I selected the Test App. In short the bean code looks like this

@Stateless
public class TestEjb implements TestEjbRemote, TestEjbLocal 
{
    @Override
    public String Try() 
    {
        return "Hello World";
    } 
}

And in the Java SE client Project here is my main class through which I am trying to access the bean:

public class Main 
{
    public static void main(String[] args) 
    {
        try 
        {
                Properties props = new Properties();
                props.load(new FileInputStream("jndi.properties"));
                InitialContext ctx = new InitialContext(props);
                TestEjbRemote testEJB = (TestEjbRemote) ctx.lookup("stateless.TestEjbRemote");
                System.out.println(testEJB.Try());
        } 
        catch (NamingException nex) 
        {
                nex.printStackTrace();
        } 
        catch (FileNotFoundException fnfex) 
        {
                fnfex.printStackTrace();
        } 
        catch (IOException ioex) 
        {
                ioex.printStackTrace();
        }
    }


}

This is the contents of 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

And I get this error at

 TestEjbRemote testEJB = (TestEjbRemote) ctx.lookup("stateless.TestEjbRemote");

javax.naming.NamingException: Lookup failed for 'stateless.TestEjbRemote' 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.TestEjbRemote 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:392)
    at Main.main(Main.java:19)
Caused by: javax.naming.NameNotFoundException: stateless.TestEjbRemote 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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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)

Any suggestions on how I may resolve this issue ?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Murphy316
  • 766
  • 3
  • 13
  • 29
  • Did you try taking the stateless off the front of the string in your lookup? Try to use just "TestEjb" in the lookup. I'm not sure what server you are using, but if you can get to the server console and look at the jndi values, you can find the name of the remote interface listed in jndi. That is usually the value you pass in the lookup. – Logan Jul 15 '12 at 01:22

1 Answers1

1

conceptually you did everything right. So this should be some 'wrong-name' related issue.

Good news that you can check it :)

EJB once got recognized by the application server is deployed. This means that the stubs are created and put by the AS into the JNDI tree. This means that once the server is started, you can go to JNDI tree viewer (usually its supplied with the aplpication server) and see what's got deployed where. I believe, given you've set up your jars properly this should work.

Hope this helps

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97