6 Replies Latest reply on Mar 18, 2009 8:04 AM by ia96herz

    EJB3 Bean Access

      Hi JBoss Users

      I was not sure if I should place this question within the JNDI or EJB3 part.

      I am currently moving from Weblogic/Spring1/EJB2 to JBoss4/EJB3/Spring2.

      I have created a small application which I will deploy on JBoss. The application consits a stateless bean:

      @Stateless(name = "ExperimentServiceEJB")
      public class ExperimentServiceEJB implements ExperimentService {
      ...
      }
      
      


      After the deployment I have the following entry in the JNDI View of JBoss:

      +- project (class: org.jnp.interfaces.NamingContext)
       | +- ExperimentServiceEJB (class: org.jnp.interfaces.NamingContext)
       | | +- remote (proxy: $Proxy68 implements interface com.roche.research.theraps.service.ExperimentService,interface org.jboss.ejb3.JBossProxy)
      


      Now I would like to access the EJB with a small client application:

      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.PROVIDER_URL,
       "jnp://hostname:port");
      properties.put(Context.URL_PKG_PREFIXES,
       "org.jboss.naming:org.jnp.interfaces");
      try {
       InitialContext ctx = new InitialContext(properties);
       ExperimentService service = (ExperimentService)
       ctx.lookup("projects/ExperimentServiceEJB/remote");
      }
      


      I tried many things but I always get a javax.naming.NameNotFoundException. Does anybody of you have some ideas what is going wrong? Is this the right way to implement such an application? Do I have to add something?

      Many thanks in advance.

      Dave

        • 1. Re: EJB3 Bean Access
          hanyshafik

          it seems u have a misspelled projects instead of project according to ur jndi view.

          ctx.lookup("project/ExperimentServiceEJB/remote");

          • 2. Re: EJB3 Bean Access

            Hi, thanks for your answer.

            I have checked this in my code again. There it is correct (i just substituted the name project for this post).

            I have tried to access other resources listed in the JNDI tree. This is working without any problem. But the access on my ExperimentService is not working.

            any other ideas?

            regards,

            Dave

            • 3. Re: EJB3 Bean Access
              jaikiran

              Post the entire exception stacktrace

              • 4. Re: EJB3 Bean Access

                Here ist the exception stacktrace:

                javax.naming.NameNotFoundException: project/ExperimentServiceEJB/remote
                 at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.java:242)
                 at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:155)
                 at sun.reflect.GeneratedMethodAccessor308.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.ha.framework.server.HARMIServerImpl.invoke(HARMIServerImpl.java:209)
                 at sun.reflect.GeneratedMethodAccessor307.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
                 at sun.rmi.transport.Transport$1.run(Transport.java:153)
                 at java.security.AccessController.doPrivileged(Native Method)
                 at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
                 at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
                 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
                 at java.lang.Thread.run(Thread.java:595)
                 at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
                 at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
                 at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
                 at org.jboss.ha.framework.server.HARMIServerImpl_Stub.invoke(Unknown Source)
                 at org.jboss.ha.framework.interfaces.HARMIClient.invokeRemote(HARMIClient.java:219)
                 at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:321)
                 at $Proxy0.lookup(Unknown Source)
                 at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
                 at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
                 at javax.naming.InitialContext.lookup(InitialContext.java:351)
                 at com.roche.research.theraps.rmi.RmiTest.testRmi(RmiTest.java:72)
                 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:585)
                 at junit.framework.TestCase.runTest(TestCase.java:168)
                 at junit.framework.TestCase.runBare(TestCase.java:134)
                 at junit.framework.TestResult$1.protect(TestResult.java:110)
                 at junit.framework.TestResult.runProtected(TestResult.java:128)
                 at junit.framework.TestResult.run(TestResult.java:113)
                 at junit.framework.TestCase.run(TestCase.java:124)
                 at junit.framework.TestSuite.runTest(TestSuite.java:232)
                 at junit.framework.TestSuite.run(TestSuite.java:227)
                 at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
                 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
                 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
                
                


                • 5. Re: EJB3 Bean Access
                  jaikiran

                   

                  javax.naming.NameNotFoundException: project/ExperimentServiceEJB/remote
                  at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.java:242)
                  at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:155)


                  Looks like its picking up HAJNDI (=clustering). What are the hostname and port that you are passing for the lookup? And how do you start the server what parameters do you use with run.sh/run.bat

                  • 6. Re: EJB3 Bean Access

                    Hi

                    The URL is:

                    properties.put(Context.PROVIDER_URL,"jnp://rbals72:10380");
                    


                    The JBoss4.2.3 is started with the followign command:


                    run.sh -c INSTANCE_NAME -b rbals72 &