12 Replies Latest reply on Jul 12, 2013 3:53 PM by wolfgangknauf

    lookup for remote bean - failure (only from eclipse)

    reyaron

      Hi,
      My problem is that for some reason, the path to my remote bean is being duplicated by the InitialContext as you can see also in the exception:
      /my-app-ear-name/GeneralDao/my-app-ear-name/GeneralDao/remote

      It happens only when I run unit-test from eclipse.
      If this test run with maven, it works OK.

      why is that happening?
      How can I avoid this?
      I work with jboss-5.1.0.GA , java 6.0.12

      The way I do the lookup:

      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      properties.put(Context.PROVIDER_URL, "127.0.0.1:1099");
      context = new InitialContext(properties);
      Object bean = context.lookup("my-app-ear-name/GeneralDao/remote");

       

      The exeption: 
      javax.naming.NamingException: Could not dereference object [Root exception is java.lang.RuntimeException: Exception while trying to locate proxy factory in JNDI, at key ProxyFactory/my-app-ear-name/GeneralDao/my-app-ear-name/GeneralDao/remote]
          at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1508)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:824)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
          at javax.naming.InitialContext.lookup(InitialContext.java:392)
          at com.mycompany.util.TestServiceLocator.getRemote(TestServiceLocator.java:47)
          at com.mycompany.util.TestServiceLocator.getRemoteBean(TestServiceLocator.java:60)
          at com.mycompany.GeneralDaoTest.testMergeFindRemove(GeneralDaoTest.java:17)
          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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
          at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
          at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Caused by: java.lang.RuntimeException: Exception while trying to locate proxy factory in JNDI, at key ProxyFactory/my-app-ear-name/GeneralDao/my-app-ear-name/GeneralDao/remote
          at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getProxyFactoryFromJNDI(ProxyObjectFactory.java:249)
          at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:157)
          at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
          at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1483)
          at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1500)
          ... 28 more
      Caused by: javax.naming.NameNotFoundException: ProxyFactory not bound
          at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
          at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
          at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
          at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
          at sun.reflect.GeneratedMethodAccessor280.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
          at sun.rmi.transport.Transport$1.run(Transport.java:159)
          at java.security.AccessController.doPrivileged(Native Method)
          at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
          at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
          at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
          at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
          at java.lang.Thread.run(Thread.java:619)
          at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
          at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
          at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
          at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
          at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getProxyFactoryFromJNDI(ProxyObjectFactory.java:240)

       

       

       

      my remote bean declaration:


      @Stateless
      public class GeneralDao implements GeneralDaoIfc, GeneralDaoIfcRemote{
      ....
      }

       

       


      GeneralDaoIfcRemote:


      @Remote
      public interface GeneralDaoIfcRemote {
      ...
      }

        • 1. Re: lookup for remote bean - failure (only from eclipse)
          wolfgangknauf

          Hi,

           

          I think for an application client, you need this value for the URL_PKG_PREFIXES property:

           

          {code}

          props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");{code}

           

          If this does not work: anything special in your unit test setup? I have a small unit test sample without problems (but I lookup the bean in the ENC, not by global name)

           

          Hope this helps

           

          Wolfgang

          • 2. Re: lookup for remote bean - failure (only from eclipse)
            reyaron

            Hi,

            Thanks for responding.

            The following advice didn't help me:
            props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");

            I also tried the ENC JNDI lookup way without success.

            to my opinion: its a bug in eclipse/jboss or somewhere else.

            1. The interesting isue is that it works fine also from eclipse if I change the jboss version from jboss-5.1.0.GA to jboss-6.0.0.M1

            2. I found some workaround also in jboss-5.1.0.GA: do the lookup without the suffix: "/remote".

            this solution populates my client stub successfully.I still don't understand how it works and how exactly the JNDI lookup guesses whether I want the remote or the local EJB.

             

            Thanks

            Yaron

            • 3. Re: lookup for remote bean - failure (only from eclipse)
              jaikiran

              When you are running against AS 5.1.0, do you have the JBOSS_HOME/server/client/jbossall-client.jar file in your classpath through Eclipse?

              • 4. Re: lookup for remote bean - failure (only from eclipse)
                reyaron

                Hi,

                It seems that after I swiched to jboss 5 from jboss 6 I forgot to do "maven eclipse:clean eclipse:eclipse" in order to update the ".classpath".

                I used the jbossall-client.jar of the wrong JBOSS.

                That is the reason for that my junit test passed in maven and failed in eclipse.

                Thanks a lot!!!

                Yaron

                • 5. Re: lookup for remote bean - failure (only from eclipse)
                  jnjnc

                  Hi,

                   

                  I got exactly same issue when running same kind of remote EJB lookup from a unit test or from a simple java client with classpath correctly setup to include JBOSS_HOME/client/jbossall-client.jar.

                   

                    

                   

                   

                  10:24:11,528 INFO [ServerImpl] Starting JBoss (Microcontainer)...

                  10:24:11,528 INFO [ServerImpl] Release ID: JBoss [The Oracle] 5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221634)

                   

                   

                  public static void main(String[] args) throws NamingException {

                   

                  Properties properties = new Properties();
                  properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                  properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
                  properties.put(Context.PROVIDER_URL, "localhost:1099");
                  context = new InitialContext(properties);
                  Object bean = context.lookup("my-app-ear-name/myBean/remote");

                  }

                   

                  Exception in thread "main" javax.naming.NamingException: Could not dereference object [Root exception is java.lang.RuntimeException: ...

                          at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1504)
                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)
                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
                          at javax.naming.InitialContext.lookup(InitialContext.java:392)

                  ....

                  Caused by: java.lang.RuntimeException: Exception while trying to locate proxy factory in JNDI, at key ProxyFactory/....
                          at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getProxyFactoryFromJNDI(ProxyObjectFactory.java:
                          at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:157)
                          at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
                          at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)
                          at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)
                          ... 4 more

                  Caused by: javax.naming.NameNotFoundException: ProxyFactory not bound
                          at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
                          at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
                          at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
                          at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                  A wrong classpath setup would give

                   

                  Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [
                  aces.NamingContextFactory]
                          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
                          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
                          at javax.naming.InitialContext.init(InitialContext.java:223)
                          at javax.naming.InitialContext.<init>(InitialContext.java:197)
                          at com.temenos.tafj.tools.jmsinjector.EJBRemoteInvoker.main(EJBRemoteInvoker.java:23)
                  Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory

                  Do you have any suggestion ?

                  Thanks and regards.

                  • 6. Re: lookup for remote bean - failure (only from eclipse)
                    wolfgangknauf

                    Hi,

                     

                    as far as I know, the "PROVIDER_URL" should be "jnp://localhost:1099" for JBoss 5.

                     

                    The rest should work.

                     

                    Did you check what is bound in JNDI using JNDIView? https://community.jboss.org/wiki/DisplayTheJDNITreeWithTheJMXConsole

                     

                    If this does not help, please provide more details about your application.

                     

                    Best regards

                     

                    Wolfgang

                    • 7. Re: lookup for remote bean - failure (only from eclipse)
                      jnjnc

                      Hi,

                       

                      Thanks for your answer.

                       

                      You  are right I did a wrong copy of my provider URL, but it's not the issue.

                      My EJB seems to be found as if I make a mistake in the name in the lookup I will get a "NameNotFoundException: bean not bound".

                       

                      This is a simple ear file containing 2 jars file one containing EJB calling business code and other one containing MDB to receive message and call the EJBs.

                      It works fine in JBoss 5.1, I can make it work when accessing the application through my web client application or when sending a message to the MDB within my unit test after a lookup to the connection factory and destination queue.

                       

                      Note that this EJB lookup test is working fine with Jboss 4.2.3 and related client libraries (same ear file except header in jboss.xml in my jar files).

                       

                      I'm really wondering about a configuration that I could have miss to do a remote invocation with JBoss 5.1 client libraries.

                      • 8. Re: lookup for remote bean - failure (only from eclipse)
                        wolfgangknauf

                        Hi,

                         

                        I see that you posted the question also here: https://community.jboss.org/message/531485

                         

                        There are two things that come to my mind:

                        1) some wrong jboss client JAR, which is not matching the server version, is referenced

                        2) you wrote that you have two jar files, one with EJBs and the other with MDBs. Both are bundled in an EAR file, are they? Maybe this causes trouble. Could you try to combine those two files?

                         

                        And maybe it is a strange configuration issue. So post as many details (code/config snippets) as possible.

                         

                        I found another thread with the same error message. Maybe the logging hints in this thread help further: https://community.jboss.org/message/410897

                         

                        Best regards

                         

                        Wolfgang

                        • 9. Re: lookup for remote bean - failure (only from eclipse)
                          jnjnc

                          Hi,

                           

                          Sorry for the late reply, I did some more tests. I only have in my test classpath jbossall-client.jar coming from the server I used.

                           

                          Here is my server log regarding my EJB deployment:

                           

                          2013-07-10 09:19:01,940 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) Created KernelDeployment for: MY_JAR.jar

                          2013-07-10 09:19:01,941 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) installing bean: jboss.j2ee:ear=MY_EAR.ear,jar=MY_JAR.jar,name=CallAtProcessingBean,service=EJB3

                          2013-07-10 09:19:01,941 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)   with dependencies:

                          2013-07-10 09:19:01,941 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)   and demands:

                          2013-07-10 09:19:01,941 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)           jboss.ejb:service=EJBTimerService

                          2013-07-10 09:19:01,942 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)   and supplies:

                          2013-07-10 09:19:01,942 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)           jndi:MY_EAR/CallAtProcessingBean/local-com.mycomp.myorg.sb.OFSProcessingBeanLocal

                          2013-07-10 09:19:01,942 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)           Class:com.mycomp.myorg.sb.OFSProcessingBeanRemote

                          2013-07-10 09:19:01,942 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)           jndi:MY_EAR/CallAtProcessingBean/local

                          2013-07-10 09:19:01,942 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)           Class:com.mycomp.myorg.sb.OFSProcessingBeanLocal

                          2013-07-10 09:19:01,943 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)           jndi:MY_EAR/CallAtProcessingBean/remote

                          2013-07-10 09:19:01,943 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)           jndi:MY_EAR/CallAtProcessingBean/remote-com.mycomp.myorg.sb.OFSProcessingBeanRemote

                          2013-07-10 09:19:01,943 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) Added bean(jboss.j2ee:ear=MY_EAR.ear,jar=MY_JAR.jar,name=CallAtProcessingBean,service=EJB3) to KernelDeployment of: MY_JAR.jar

                           

                          I don't know whether the mapping is correct or not, I supposed it is as it works when invoked from the server, but I could see from that trace that the sequence between local JNDI name and class name is "weird".

                           

                          As I said as this test is working like a charm in 4.2, thus given the stacktrace:

                           

                          Caused by: javax.naming.NameNotFoundException: ProxyFactory not bound

                                  at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)

                           

                          I tried to replace the jnpclient.jar with former version with no luck.

                           

                          Then given the stacktrace

                           

                          Caused by: java.lang.RuntimeException: Exception while trying to locate proxy factory in JNDI, at key ProxyFactory/....

                                  at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getProxyFactoryFromJNDI(ProxyObjectFactory.java:

                                  at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:157)

                           

                          I get rid of jboss-ejb3-proxy-impl-client.jar in my client libraries.

                           

                          My test is going a bit further, it's not crashing anymore on the lookup but second assert fails.

                           

                                  Object object = initialContext.lookup("MY_EAR/CallAtProcessingBean/remote");

                                  assertNotNull(object);

                                  assertTrue(object instanceof OFSProcessingBeanRemote);

                           

                          Here is a debug view of "object", thus it seems mapping is correct.

                           

                          org.jboss.ejb3.proxy.impl.objectfactory.session.stateless.StatelessSessionProxyObjectFactory

                           

                          Reference Class Name: Proxy for: com.mycomp.myorg.sb.OFSProcessingBeanRemote

                          Type: ProxyFactoryKey

                          Content: ProxyFactory/MY_EAR/CallAtProcessingBean/MY_EAR/CallAtProcessingBean/remote

                          Type: EJB Container Name

                          Content: jboss.j2ee:ear=MY_EAR.ear,jar=MY_JAR.jar,name=CallAtProcessingBean,service=EJB3

                          Type: Proxy Factory is Local

                          Content: false

                          Type: Remote Business Interface

                          Content: com.mycomp.myorg.sb.OFSProcessingBeanRemote

                          Type: Remoting Host URL

                          Content: socket://127.0.0.1:3873/

                           

                           

                          If I try to do the cast to my expected type I got the following exception, which I guess is expected without the proxy jar.

                           

                          java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.mycomp.myorg.sb.OFSProcessingBeanRemote

                           

                          Any thought about that ?

                           

                          Best regards,

                          Jean-Noel

                          • 10. Re: lookup for remote bean - failure (only from eclipse)
                            wolfgangknauf

                            Hi Jean-Noel,

                             

                            sorry, I have no idea.

                             

                            1) How do you start the simple app/unit test? Do you use Eclipse/Maven?

                             

                            2) Is there any chance to post the EAR file?

                             

                            3) could you test it with JBoss 7/8 (WildFly)?

                             

                            Best regards

                             

                            Wolfgang

                            • 11. Re: lookup for remote bean - failure (only from eclipse)
                              jnjnc

                              Thanks for your prompt answer Wolfgang.

                               

                              Good news today, my test is working in 5.2. I didn't know that we were using this version.

                               

                              The test is both failing in 5.1 within eclipse and from a maven build.

                               

                              I will try to build a very simple ear file as soon as I have a chance.

                               

                              But I think something must have been fixed between 5.1 and 5.2.

                               

                              Best regards,

                              Jean-Noel

                              • 12. Re: lookup for remote bean - failure (only from eclipse)
                                wolfgangknauf

                                Well, if it works now I don't think there is much need for further research ;-).

                                 

                                Best regards

                                 

                                Wolfgang