9 Replies Latest reply on Jun 17, 2013 11:51 AM by thinksteep thinksteep

    JBoss7.1.1Final remote EJB Initiacontext issue

    thinksteep thinksteep Novice

      Hi Community,

       

      I am having strange issue while creating "remote" intial context for EJB lookup.

       

      I have standalone client (with multi threading). Each thread does lookup & call a method of EJB.

       

      Skeleton code I have is:

       

      public class EJBContextClient {

         private static Context context;

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

                  if (context == null) {

                      createContext();

                  }

                  BeanRemote beanRemote = (BeanRemote) context.lookup("ejb:appName/ModuleName/BeamName!fullBeanPath");

                  long retVal = beanRemote.someMethod(somelongvalue);

        }

        private static void getContext() throws NamingException {

              Properties props = new Properties();

              props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

              props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

              props.put(Context.PROVIDER_URL, "remote://remoteIP:4447");

              props.put("jboss.naming.client.ejb.context", true);

              props.put(Context.SECURITY_PRINCIPAL, "username");

              props.put(Context.SECURITY_CREDENTIALS, "password");

              context = new InitialContext(props);

          }

        }

       

      As soon as new InitialContext(props); executed, I am seeing following entries in my client log:  It is creating InitialContext for mylocal as well as remote machine (Not sure whether it is problem are not).

       

      17:11:45,902 INFO  XNIO Version 3.0.3.GA

      17:11:45,926 INFO  XNIO NIO Implementation Version 3.0.3.GA

      17:11:45,975 INFO  JBoss Remoting version 3.2.3.GA

      17:11:46,600 INFO  Received server version 1 and marshalling strategies [river]

      17:11:46,646 INFO  Successful version handshake completed for receiver context E

      JBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@2226344d,

      receiver=Remoting connection EJB receiver [connection=Remoting connection <36187

      647>,channel=jboss.ejb,nodename=clientmachinename]} on channel Channel ID 9ff6a2ed (outbound

      ) of Remoting connection 1fa2fc5f to localhost/127.0.0.1:4447

      17:11:46,647 WARN  Unsupported message received with header 0xffffffff

      17:11:46,661 INFO  Received server version 1 and marshalling strategies [river]

      17:11:46,663 INFO  Successful version handshake completed for receiver context E

      JBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@258167fd,

      receiver=Remoting connection EJB receiver [connection=Remoting connection <32fdb

      eda>,channel=jboss.ejb,nodename=remoteMachineName]} on channel Channel ID 9b9da375 (o

      utbound) of Remoting connection 0ec1011b to /remoteIP:4447

      17:11:46,664 WARN  Unsupported message received with header 0xffffffff

      ----------------------------------------------------------------------

      After this, one call to bean is succesful, but subsequent calls (second call onwards) are throwing follwoing error:

       

      Caused by: java.lang.IllegalStateException: No EJB receiver available for handli

      ng [appName:myAppName,modulename:myModuleName,distinctname:] combination for

      invocation context org.jboss.ejb.client.EJBClientInvocationContext@6183d3b9

              at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(MyClientClassName.java:584)

       

      MORE INFO ON ENVIRONMENT IS:

       

      I have JBoss7.1.1Final and Standalone Client on Machine A

       

      Machine B has JBoss 7.1.1Final and JMS/EJB application.

       

      Standalone client on Machine A does lookup for JMS/EJB on Machine B

       

      If client is on same machine (Machine B) as JMS/EJB. This is not an issue.


      Any input would be really appreciated.

       

      Thanks for your time and help.

        • 1. Re: JBoss7.1.1Final remote EJB Initiacontext issue
          Wolf-Dieter Fink Master

          From the InitialContext you use the remote-naming. But the lookup with the ejb: prefix requires a ejb-client initialization, i.e. by having a jboss-ejb-client.properties file and set props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming") for the context as the only attribute.

           

          So drop the ejb: prefix should work.

           

          See the following links:

           

          https://docs.jboss.org/author/display/AS72/EJB+invocations+from+a+remote+client+using+JNDI

          https://docs.jboss.org/author/display/AS72/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

          • 2. Re: JBoss7.1.1Final remote EJB Initiacontext issue
            thinksteep thinksteep Novice

            Hi Wolf-Dieter,

             

            Thanks for your input on this. I followed these links while doing my initial setup.

             

            1) "So drop the ejb: prefix should work."

            As per https://docs.jboss.org/author/display/AS72/EJB+invocations+from+a+remote+client+using+JNDI

            The ejb: namespace identifies it as a EJB lookup and is a constant (i.e. doesn't change) for doing EJB lookups

             

            I am confused which statement is correct.

             

            NOTE: I just tested by removing ejb prefix and only PKG_PREFIXES entry(and no ejb-client-properties file), got following exception (Trying localhost even though in context creation I have remoteIP):

             

            Jun 11, 2013 9:48:30 AM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers

            WARN: Could not register a EJB receiver for connection to remote://localhost:4447

            java.lang.RuntimeException: Operation failed with status WAITING

                      at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:93)

                      at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:121)

                      at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:78)

                      at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:77)

                      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)

                      at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

                      at $Proxy0.getLatestTimestamp(Unknown Source)

             

            2) In one of the threads I read that, when we have  props.put("jboss.naming.client.ejb.context", true); in context creation, we don't need jboss-ejb-client.properties file.

             

            Can you please help me with which approach is correct?

             

            Thanks for your time and help.


            • 3. Re: JBoss7.1.1Final remote EJB Initiacontext issue
              Wolf-Dieter Fink Master

              If you look to [1] this is the remote-naming project approach.

              with the property "jboss.naming.client.ejb.context" to true you configure that the connection is handled by the remote-naming.

              Therefore you do not need a jboss-ejb-client.properties.

              But you should not use the ejb: prefix for lookup!

              If you scroll down a bit of [1] there is a an example, headline "Remote EJB invocations backed by the remote-naming project"

              where you find the related code.

               

              Remember with that project there is not everything possible and supported.

               

              If you use the ejb-client direct there are more options:

              - use jboss-ejb-client.propeties

              - use the programatic API

              - use the scoped-context, where properties are passed to the IC. Available since EAP6.1 or AS7.2

              Here you have to use the ejb: prefix as describe in [2]

               

              hope that explain the differences.

               

              [1] https://docs.jboss.org/author/display/AS72/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

              [2] https://docs.jboss.org/author/display/AS72/EJB+invocations+from+a+remote+client+using+JNDI

              • 4. Re: JBoss7.1.1Final remote EJB Initiacontext issue
                thinksteep thinksteep Novice

                Hi Wolf-Dieter,

                 

                Thanks! that clarifies my confusion. Can you please help me with why still remote is looking for "localhost"?

                 

                My sample code is:

                 

                package ejbcontextclient;

                import mypackage.ejb.MyBeanRemote;

                import java.util.Properties;

                import java.util.concurrent.ExecutorService;

                import java.util.concurrent.Executors;

                import javax.naming.Context;

                import javax.naming.InitialContext;

                import javax.naming.NamingException;

                 

                public class EJBContextClient {

                      private static Context context;

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

                     for (int i = 1; i < 3; i++) {

                            executeTask();

                        }

                    }

                 

                    private static void executeTask() {

                        Runnable worker = new Runnable() {

                             public void run() {

                                try {

                                    if (context == null) {

                                        getContext();

                                    }

                                    MyBeanRemote beanRem = (MyBeanRemote) context.lookup("MyAppName/ModuleName/MyBean!FullPathofBeanRemote");

                                    long retVal = beanRem.someMethod(4);

                                    System.out.println(retVal);

                                } //end of run()

                                catch (Exception ex) {//log the exception, and the host and datasource it occurred on.

                                    ex.printStackTrace();

                                }

                            }//end of run()

                        };

                        ExecutorService executor = Executors.newFixedThreadPool(15, Executors.defaultThreadFactory());

                        executor.execute(worker);

                        executor.shutdown();

                    }

                      private static void getContext() throws NamingException {

                        Properties props = new Properties();

                        props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

                        props.put(Context.PROVIDER_URL, "remote://remoteIP:4447");

                        props.put("jboss.naming.client.ejb.context", true);

                        props.put(Context.SECURITY_PRINCIPAL, "username");

                        props.put(Context.SECURITY_CREDENTIALS, "pwd");

                        context = new InitialContext(props);

                    }

                }

                 

                And the output I am getting is: (Not sure why it is looking for localhost?)

                NOTE: No jboss.ejb.properties in classpath, because  I want to use "remote-naming" to take of the stuff. I can't really go for "ejb-client direct" approach at this moment.

                 

                Jun 11, 2013 12:42:19 PM org.xnio.Xnio <clinit>

                INFO: XNIO Version 3.0.3.GA

                Jun 11, 2013 12:42:19 PM org.xnio.nio.NioXnio <clinit>

                INFO: XNIO NIO Implementation Version 3.0.3.GA

                Jun 11, 2013 12:42:19 PM org.jboss.remoting3.EndpointImpl <clinit>

                INFO: JBoss Remoting version 3.2.3.GA

                Jun 11, 2013 12:42:24 PM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers

                WARN: Could not register a EJB receiver for connection to remote://localhost:4447

                java.lang.RuntimeException: Operation failed with status WAITING

                          at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:93)

                          at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:121)

                          at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:78)

                          at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:77)

                          at org.jboss.naming.remote.client.ejb.RemoteNamingEjbClientContextSelector.setupSelector(RemoteNamingEjbClientContextSelector.java:18)

                          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.jboss.naming.remote.client.InitialContextFactory.setupEjbContext(InitialContextFactory.java:420)

                          at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:115)

                          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)

                          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)

                          at javax.naming.InitialContext.init(InitialContext.java:242)

                          at javax.naming.InitialContext.<init>(InitialContext.java:216)

                          at ejbcontextclient.EJBContextClient.getContext(EJBContextClient.java:63)

                          at ejbcontextclient.EJBContextClient.access$100(EJBContextClient.java:19)

                          at ejbcontextclient.EJBContextClient$1.run(EJBContextClient.java:39)

                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

                          at java.lang.Thread.run(Thread.java:722)

                 

                 

                Jun 11, 2013 12:42:24 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

                INFO: Received server version 1 and marshalling strategies [river]

                Jun 11, 2013 12:42:24 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

                INFO: Received server version 1 and marshalling strategies [river]

                Jun 11, 2013 12:42:24 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

                INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@69960c9e, receiver=Remoting connection EJB receiver [connection=Remoting connection <61a243f1>,channel=jboss.ejb,nodename=remoteMachineName]} on channel Channel ID c7760e93 (outbound) of Remoting connection 350385f1 to /remoteIP:4447

                Jun 11, 2013 12:42:24 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

                INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@659a1fae, receiver=Remoting connection EJB receiver [connection=Remoting connection <61a243f1>,channel=jboss.ejb,nodename=remoteMachineName]} on channel Channel ID d12927b1 (outbound) of Remoting connection 350385f1 to /remoteIP:4447

                Jun 11, 2013 12:42:24 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

                WARN: Unsupported message received with header 0xffffffff

                Jun 11, 2013 12:42:24 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

                WARN: Unsupported message received with header 0xffffffff

                0

                0

                 

                Last two ZEROs at end are response from remote EJB, but the part I am worried is, why "localhost" lookup is happening and throwing error? how can I avoid this?

                 

                Any help would be appreciated.

                 

                Thanks for your time and help.

                • 5. Re: JBoss7.1.1Final remote EJB Initiacontext issue
                  thinksteep thinksteep Novice

                  Hi Team,

                   

                  Any suggestions on this issue?

                   

                  Thank you,

                  • 6. Re: JBoss7.1.1Final remote EJB Initiacontext issue
                    Wolf-Dieter Fink Master

                    Not sure at the moment.

                    Do you have a jndi.properties in the classpath?

                    What if you execute the same code in the current thread instead of using a new thread?

                    • 7. Re: JBoss7.1.1Final remote EJB Initiacontext issue
                      thinksteep thinksteep Novice

                      Hi Wolf-Dieter,

                       

                      I am sure jndi.properties is in classpath. Inside my client program I am doing System.out for "java.class.path" and this output does include jndi.properties folder path. Is there any other way we can confirm this?

                       

                      I tried using it in current thread, then also, "localhost" lookup happening. I am getting same message:

                       

                      WARN: Could not register a EJB receiver for connection to remote://localhost:4447

                      java.lang.RuntimeException: Operation failed with status WAITING

                                at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:93)

                                at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:121)

                                at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:78)

                                at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:77)

                                at

                       

                      Any suggestions?

                       

                      Thanks for your time and help.

                      • 8. Re: JBoss7.1.1Final remote EJB Initiacontext issue
                        Wolf-Dieter Fink Master

                        For me this properties are working:

                         

                                Properties props = new Properties();

                                props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

                                props.put(Context.PROVIDER_URL, "remote://localhost:4447");

                                props.put("jboss.naming.client.ejb.context", true);

                                props.put(Context.SECURITY_PRINCIPAL, "username");

                                props.put(Context.SECURITY_CREDENTIALS, "pwd");

                                context = new InitialContext(props);

                         

                        Maybe the jndi.properies are included and set something wrong, could you remove it and test again?

                        • 9. Re: JBoss7.1.1Final remote EJB Initiacontext issue
                          thinksteep thinksteep Novice

                          I am confused now. When we do remote lookup (JBoss on other machine), PROVIDER_URL should point to remote machine IP isn't it?

                           

                            props.put(Context.PROVIDER_URL, "remote://localhost:4447");

                           

                          should be

                           

                            props.put(Context.PROVIDER_URL, "remote://remoteIP:4447");

                           

                          Isn't it?

                           

                          And in my case, with remoteIP, new InitialContext(), trying to establish initialContext, both for remoteIP and localhost.

                           

                          I did test by removing jndi.properties from the classpath, still same issue.

                           

                          One more question is, should the remote jboss binded to IP (or) 0.0.0.0?  In my case I have -b reomoteMachineIP is this correct or not?

                           

                          Thanks for your time and help.