1 2 Previous Next 19 Replies Latest reply on Nov 25, 2011 3:42 PM by Riccardo Pasquini Branched to a new discussion.

    Problems with Remote EJB and related documentation

    Riccardo Pasquini Novice

      Hi people,

       

      i was trying to implement a remote client to perform an Hello World operation using the guide in the documentation (https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI).

       

      I've found some strange behaviors, in the following scenario:

       

      • latest sucessful build (AS7.1.CR1-SNAPSHOT)
      • domain configuration
      • 2 servers in the same group configured with ha-sockets

       

      here it is:

       

      • dependency jboss-ejb-client was not in the jboss maven repository, workaround is an install:install-file
      • jndiProperties requires jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory"); in addition to the Context.URL_PKG_PREFIXES
      • the previous point means that the client requires the additional dependency jboss-as-naming 7.0.2.Final
      • the EJB namespace ejb: isn't it JEE6 standard, right? is it a not implemented specification or vendors are free?

       

      Finally, the test code fails with the following exception:

       

      [WARNING] 
      java.lang.reflect.InvocationTargetException
                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.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
                at java.lang.Thread.run(Thread.java:662)
      Caused by: java.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext cannot be cast to com.hp.dragon.test.HelloWorlder
                at com.hp.dragon.test.TheApp.run(TheApp.java:63)
                at com.hp.dragon.test.TheApp.main(TheApp.java:35)
                ... 6 more
      
      

       

      attached the test code, following a quick view of TheApp.java:63

       

      HelloWorlder proxy = (HelloWorlder) context
                      .lookup("ejb:TestRemoteBean/HelloWorlderBean!com.hp.dragon.test.HelloWorlder");
      
      

       

      thank you, hope to help

       

      PS the app has been run using mvn exec:java -Dexec.mainClass, so i expect that the classpath is correct

        • 1. Re: Problems with Remote EJB and related documentation
          jaikiran pai Master

          Riccardo Pasquini wrote:

           

          here it is:

           

          • dependency jboss-ejb-client was not in the jboss maven repository, workaround is an install:install-file

          It should be available in Maven. The quickstart example in that documentation has a link which points to where the project resides. Here's the pom.xml of the client side code https://github.com/jaikiran/quickstart/blob/master/ejb-remote/client/pom.xml :

           

                 <dependency>
                     <groupId>org.jboss</groupId>
                     <artifactId>jboss-ejb-client</artifactId>
                     <version>1.0.0.Beta7</version>
                     <scope>runtime</scope>
                 </dependency>
          

           

           

           

          Riccardo Pasquini wrote:

           

          • jndiProperties requires jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory"); in addition to the Context.URL_PKG_PREFIXES
          • the previous point means that the client requires the additional dependency jboss-as-naming 7.0.2.Final

          It doesn't require the Context.INITIAL_CONTEXT_FACTORY for looking up the ejb: namespace JNDI names. If you are using that InitialContext for anything other than that namespace, then you'll have to add an appropriate INITIAL_CONTEXT_FACTORY which depends on what you are looking up. And since right now anything other than ejb: namespace isn't supported for remote clients, the INITIAL_CONTEXT_FACTORY is thus not required.

           

           

          Riccardo Pasquini wrote:

           

          • the EJB namespace ejb: isn't it JEE6 standard, right? is it a not implemented specification or vendors are free?

           

          http://community.jboss.org/thread/175129?tstart=30

           

           

          Riccardo Pasquini wrote:

           

          Finally, the test code fails with the following exception:

           

          [WARNING] 
          java.lang.reflect.InvocationTargetException
                    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.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
                    at java.lang.Thread.run(Thread.java:662)
          Caused by: java.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext cannot be cast to com.hp.dragon.test.HelloWorlder
                    at com.hp.dragon.test.TheApp.run(TheApp.java:63)
                    at com.hp.dragon.test.TheApp.main(TheApp.java:35)
                    ... 6 more
           
          

           

          attached the test code, following a quick view of TheApp.java:63

           

          HelloWorlder proxy = (HelloWorlder) context
                          .lookup("ejb:TestRemoteBean/HelloWorlderBean!com.hp.dragon.test.HelloWorlder");
           
          

           

           

           

          The JNDI name is incorrect. Like mentioned in that article, the syntax is ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully- fqualified-view-class-name> for stateless beans. So assuming you have deployed it in a TestRemoteBean.jar (without any .ear) then the JNDI name should be:

           

          HelloWorlder proxy = (HelloWorlder) context
                          .lookup("ejb:/TestRemoteBean//HelloWorlderBean!com.hp.dragon.test.HelloWorlder");
          1 of 1 people found this helpful
          • 2. Re: Problems with Remote EJB and related documentation
            Riccardo Pasquini Novice

            Thank you Jaikiran,

             

            looking at your pom, i've added the dependency management element and the dependency has been resolved (i took care about restoring the local repository before run it); contextually, the same for INITIAL_CONTEXT_FACTORY and the "naming" dependency (removed)..

             

            but

             

            the JNDI name is still not working, i'm now using:

             

            ejb:/TestRemoteBean//HelloWorlderBean!com.hp.dragon.test.HelloWorlder
            

             

            (double slashed...)

             

            and i get

             

            24-nov-2011 8.26.03 org.jboss.ejb.client.remoting.VersionReceiver handleMessage
            INFO: Received server version 1 and marshalling strategies [river, java-serial]
            24-nov-2011 8.26.03 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
            INFO: Successful version handshake completed for receiver context org.jboss.ejb.client.EJBReceiverContext@54011d95 on channel Channel ID 8af46ce1 (outbound) of Remoting connection 57004a1a to /127.0.0.1:4547
            24-nov-2011 8.26.03 org.jboss.ejb.client.remoting.VersionReceiver handleMessage
            INFO: Received server version 1 and marshalling strategies [river, java-serial]
            24-nov-2011 8.26.03 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
            INFO: Successful version handshake completed for receiver context org.jboss.ejb.client.EJBReceiverContext@51bfa303 on channel Channel ID ef7d0449 (outbound) of Remoting connection 1ac84361 to /127.0.0.1:4647
            [WARNING] 
            java.lang.reflect.InvocationTargetException
                    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.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
                    at java.lang.Thread.run(Thread.java:662)
            Caused by: java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:TestRemoteBean,distinctname:] combination
                    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:236)
                    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:95)
                    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:86)
                    at $Proxy14.sayHello(Unknown Source)
                    at com.hp.dragon.test.TheApp.run(TheApp.java:63)
                    at com.hp.dragon.test.TheApp.main(TheApp.java:35)
                    ... 6 more
            
            

             

            I'm a little bit confused... anyway, thank you for your time.

             

            Riccardo

            • 3. Re: Problems with Remote EJB and related documentation
              jaikiran pai Master

              You are missing the jboss-ejb-client.properties from your client classpath.

              • 4. Re: Problems with Remote EJB and related documentation
                Riccardo Pasquini Novice

                i disagree because logs shows the following lines:

                 

                INFO: Successful version handshake completed for receiver context org.jboss.ejb.client.EJBReceiverContext@54011d95 on channel Channel ID 8af46ce1 (outbound) of Remoting connection 57004a1a to /127.0.0.1:4547
                ....
                INFO: Successful version handshake completed for receiver context org.jboss.ejb.client.EJBReceiverContext@51bfa303 on channel Channel ID ef7d0449 (outbound) of Remoting connection 1ac84361 to /127.0.0.1:4647
                

                 

                which are the servers/ports defined in my jboss-ejb-client.properties which is in src/main/resources with the following content:

                 

                remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
                
                
                remote.connections=x1, x2
                
                
                remote.connection.x1.host=127.0.0.1
                remote.connection.x1.port = 4547
                remote.connection.x1.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
                
                
                remote.connection.x2.host=127.0.0.1
                remote.connection.x2.port = 4647
                remote.connection.x2.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
                
                

                 

                 

                EDIT the deployed bean artifact name is TestRemoteBean-0.1-SNAPSHOT.jar but runtime name is TestRemoteBean.jar

                • 5. Re: Problems with Remote EJB and related documentation
                  jaikiran pai Master

                  Ah right, i missed that log. What does the server side console logs show when the application is deployed? What JNDI names are logged?

                  • 6. Re: Problems with Remote EJB and related documentation
                    Riccardo Pasquini Novice

                    Well,

                     

                    the artifact is versioned (...-0.1-SNAPSHOT) and runtime is not versioned and this is the deployment log:

                     

                    [Host Controller] 08:36:06,743 INFO  [org.jboss.as.server.deployment.repository.impl] (HttpManagementService-threads - 11) JBAS014900: Content added at location /home/rick/Applicazioni/jboss/domain/content/7b/f90e9472c564b57584ea93e0a29d935fdb69a1/content
                    [Server:x2] 08:36:18,971 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-10) Starting deployment of "TestRemoteBean.jar"
                    [Server:x1] 08:36:18,975 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) Starting deployment of "TestRemoteBean.jar"
                    [Server:x1] 08:36:19,005 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-16) JNDI bindings for session bean named HelloWorlderBean in deployment unit deployment "TestRemoteBean.jar" are as follows:
                    [Server:x1] 
                    [Server:x1]     java:global/TestRemoteBean/HelloWorlderBean!com.hp.dragon.test.HelloWorlder
                    [Server:x1]     java:app/TestRemoteBean/HelloWorlderBean!com.hp.dragon.test.HelloWorlder
                    [Server:x1]     java:module/HelloWorlderBean!com.hp.dragon.test.HelloWorlder
                    [Server:x1]     java:global/TestRemoteBean/HelloWorlderBean
                    [Server:x1]     java:app/TestRemoteBean/HelloWorlderBean
                    [Server:x1]     java:module/HelloWorlderBean
                    [Server:x1] 
                    [Server:x2] 08:36:19,012 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named HelloWorlderBean in deployment unit deployment "TestRemoteBean.jar" are as follows:
                    [Server:x2] 
                    [Server:x2]     java:global/TestRemoteBean/HelloWorlderBean!com.hp.dragon.test.HelloWorlder
                    [Server:x2]     java:app/TestRemoteBean/HelloWorlderBean!com.hp.dragon.test.HelloWorlder
                    [Server:x2]     java:module/HelloWorlderBean!com.hp.dragon.test.HelloWorlder
                    [Server:x2]     java:global/TestRemoteBean/HelloWorlderBean
                    [Server:x2]     java:app/TestRemoteBean/HelloWorlderBean
                    [Server:x2]     java:module/HelloWorlderBean
                    [Server:x2] 
                    [Server:x1] 08:36:19,070 INFO  [org.jboss.as.server.controller] (pool-1-thread-7) Deployed "TestRemoteBean.jar"
                    [Server:x2] 08:36:19,070 INFO  [org.jboss.as.server.controller] (pool-1-thread-6) Deployed "TestRemoteBean.jar"
                    
                    
                    • 7. Re: Problems with Remote EJB and related documentation
                      jaikiran pai Master

                      I'm travelling and haven't been paying much attention to this thread, but now that I read this carefully, it appears that you are using non default EJB remoting ports:

                       

                      • 2 servers in the same group configured with ha-sockets

                      remote.connection.x1.port = 4547

                      remote.connection.x2.port = 4647

                       

                      On the server side, in the EJB3 subsystem, you have to make sure that the correct remoting port for the EJB services is being used. By default it uses 4447:

                       

                      <subsystem xmlns="urn:jboss:domain:ejb3:1.2">
                                 ...
                                  <remote connector-ref="remoting-connector" thread-pool-name="default"/>
                      ...
                              </subsystem>
                      ...
                      <subsystem xmlns="urn:jboss:domain:remoting:1.1">
                                      <connector name="remoting-connector" socket-binding="remoting"/>
                                  </subsystem>
                      

                       

                      You have to set the connector-ref appropriately to point to a connector in the remoting subsystem which uses your custom ports.

                      • 8. Re: Problems with Remote EJB and related documentation
                        jaikiran pai Master

                        Could  you post the domain.xml that you are using?

                        • 9. Re: Problems with Remote EJB and related documentation
                          Riccardo Pasquini Novice

                          mmm i quite disagree again because the 2 servers are configured in the same server group using the console with respectively port offset of 100 and 200, so if default si 4447 i expect that x1 is 4547 (port offset 100) and x2 is 4647 (port offset 200)

                           

                          In particular, they are running in the same host so... i cannot bind 4447 for both servers...

                          • 11. Re: Problems with Remote EJB and related documentation
                            jaikiran pai Master

                            Actually, I think I know what might be going on. Can you change to jboss-ejb-client.properties to include just one connection instead of 2? When there are more than one receivers (connections) involved, we wait for the module report from the server to be available (which might take a few seconds or milli seconds) to select the correct receiver. When only one receiver/connection is involved, we just pass the invocation to that receiver without waiting for the module report from the server.

                             

                            P.S: An alternate workaround (for now) would be to let there be more than 1 receivers in the jboss-ejb-client.properties  but add a Thread.sleep() for maybe a couple of seconds after the lookup but before the invocation on the proxy. Ofcourse this is a hack for now. We'll have to fix this properly.

                            • 12. Re: Problems with Remote EJB and related documentation
                              Riccardo Pasquini Novice

                              Ok! with a single remote connection in jboss-ejb-client it works properly

                               

                              but with 2 connections, there's no way even if i set 10" of sleep:

                                      HelloWorlder proxy = (HelloWorlder) context
                                              .lookup("ejb:/TestRemoteBean//HelloWorlderBean!com.hp.dragon.test.HelloWorlder");
                              try { Thread.sleep(10000);} catch(Exception e) {}
                                      String out = proxy.sayHello();
                                      System.out.println(out);
                              
                              

                               

                              my target test is to check balancing and failover,  infact next step is to put the call in a loop and check the balancing policy between x1 and x2 (round robin? configurable?) contextually stop one of the servers to see the remote client behavior...

                               

                              i mean, i'm looking at the given alternative to HA-JNDI

                              • 13. Re: Problems with Remote EJB and related documentation
                                jaikiran pai Master

                                Riccardo Pasquini wrote:

                                 

                                Ok! with a single remote connection in jboss-ejb-client it works properly

                                 

                                Good to know.

                                 

                                Riccardo Pasquini wrote:

                                 

                                 

                                but with 2 connections, there's no way even if i set 10" of sleep:

                                That's a bit strange. Could you please enable the org.jboss.as.ejb3 TRACE logs on the server side and org.jboss.ejb.client TRACE logs on the client side and attach those logs if possible.

                                 

                                I've started working on improving this multi receiver scenario a bit.

                                • 14. Re: Problems with Remote EJB and related documentation
                                  Riccardo Pasquini Novice

                                  Anyway, maybe this can help:

                                   

                                  what i see in the logs is

                                   

                                   

                                  sourcelog

                                          final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();

                                          jndiProperties.put(Context.URL_PKG_PREFIXES,

                                                  "org.jboss.ejb.client.naming");

                                          context = new InitialContext(jndiProperties);

                                   

                                          HelloWorlder proxy = (HelloWorlder) context.lookup("ejb:/TestRemoteBean//HelloWorlderBean!com.hp.dragon.test.HelloWorlder");

                                  24-nov-2011 13.50.20 org.jboss.ejb.client.EJBClient <clinit>

                                  INFO: JBoss EJB Client version 1.0.0.Beta7

                                  try { Thread.sleep(10000);} catch(Exception e) {}
                                  String out = proxy.sayHello();

                                  24-nov-2011 13.50.30 org.xnio.Xnio <clinit>

                                  INFO: XNIO Version 3.0.0.CR4

                                  24-nov-2011 13.50.30 org.xnio.nio.NioXnio <clinit>

                                  INFO: XNIO NIO Implementation Version 3.0.0.CR4

                                  24-nov-2011 13.50.30 org.jboss.remoting3.EndpointImpl <clinit>

                                  INFO: JBoss Remoting version 3.2.0.CR3

                                  24-nov-2011 13.50.30 org.jboss.ejb.client.remoting.VersionReceiver handleMessage

                                  INFO: Received server version 1 and marshalling strategies [river, java-serial]

                                  24-nov-2011 13.50.30 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

                                  INFO: Successful version handshake completed for receiver context org.jboss.ejb.client.EJBReceiverContext@c9021e3 on channel Channel ID eada49cb (outbound) of Remoting connection 6cb1cb25 to /127.0.0.1:4547

                                  24-nov-2011 13.50.30 org.jboss.ejb.client.remoting.VersionReceiver handleMessage

                                  INFO: Received server version 1 and marshalling strategies [river, java-serial]

                                  24-nov-2011 13.50.30 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

                                  INFO: Successful version handshake completed for receiver context org.jboss.ejb.client.EJBReceiverContext@1adbbe8b on channel Channel ID c792872f (outbound) of Remoting connection 7aaf8b32 to /127.0.0.1:4647

                                   

                                   

                                  It seems to me that the thread sleep is ineffective to separate the 2 receiverse, do you agree?

                                   

                                  Logging FINEST server side is silent, not yet done client side... doing... baby allowing

                                  1 2 Previous Next