9 Replies Latest reply on Jul 30, 2013 4:07 AM by Wolf-Dieter Fink

    JNDI Lookup from host to host

    s.horn Newbie

      Hello,

       

      i have a question about ejb invocation from an other host.

       

      with jboss6 it was possible to define the lookup url of the destination server via Properties in the InitialContext (provider url).

       

      We use the following code in our ejb for looking up to the remote interface on destination server:

       

      Properties env = new Properties();

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

      env.put(Context.PROVIDER_URL, "remote://<destination>:4447");

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

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

      env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", false);

      env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");

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

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

       

      Context ctx = new InitialContext(env);

      RemoteInterface remote = (RemoteInterface)ctx.lookup("ear/jar/...");

       

      The following exception occures:

       

      15:03:59,131 ERROR [stderr] (http--0.0.0.0-8080-2) javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "application-DEV.war:main" from Service Module Loader
      15:03:59,147 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
      15:03:59,162 ERROR [stderr] (http--0.0.0.0-8080-2)     at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)
      15:03:59,162 ERROR [stderr] (http--0.0.0.0-8080-2)     at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
      15:03:59,162 ERROR [stderr] (http--0.0.0.0-8080-2)     at javax.naming.InitialContext.init(InitialContext.java:242)
      15:03:59,178 ERROR [stderr] (http--0.0.0.0-8080-2)     at javax.naming.InitialContext.<init>(InitialContext.java:216)
      15:03:59,178 ERROR [stderr] (http--0.0.0.0-8080-2)     at de.procar.timemanagement.bdeimpl.ecaros2.Ecaros2BDE.login(Ecaros2BDE.java:216)
      15:03:59,194 ERROR [stderr] (http--0.0.0.0-8080-2)     at de.procar.timemanagement.bdeimpl.ecaros2.Ecaros2BDE.login(Ecaros2BDE.java:122)
      15:03:59,194 ERROR [stderr] (http--0.0.0.0-8080-2)     at de.procar.timemanagement.client.struts2.container.LoginAction.execute(LoginAction.java:74)
      15:03:59,209 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
      15:03:59,225 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
      15:03:59,225 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      15:03:59,225 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
      15:03:59,241 ERROR [stderr] (http--0.0.0.0-8080-2)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
      15:03:59,241 ERROR [stderr] (http--0.0.0.0-8080-2)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
      15:03:59,241 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
      15:03:59,256 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      15:03:59,256 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
      15:03:59,256 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
      15:03:59,272 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
      15:03:59,272 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
      15:03:59,287 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      15:03:59,287 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      15:03:59,287 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
      15:03:59,287 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
      15:03:59,303 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
      15:03:59,319 ERROR [stderr] (http--0.0.0.0-8080-2)     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
      15:03:59,319 ERROR [stderr] (http--0.0.0.0-8080-2)     at java.lang.Thread.run(Thread.java:724)

       

      What is wrong with this code?

       

      Thanks in advance.

       

      Sascha

        • 1. Re: JNDI Lookup from host to host
          Wolf-Dieter Fink Master

          with as7 it ist not possible Top use  that approach. Have a look Top the quickstarts, i.e. ejb-Multi-Server.Also  you might have a look to the documentation and look for remote outbound connections or scoped context .

          • 2. Re: JNDI Lookup from host to host
            Wolf-Dieter Fink Master

            Here a bit more details and links,

            You will find details for remote-outbound-connection in the documentation here, there is also a chapter about scoped-context.

            A full example with both approaches you will find in the ejb-multi-server quickstart which can be cloned from git here https://github.com/jboss-jdf/jboss-as-quickstart

            • 3. Re: JNDI Lookup from host to host
              s.horn Newbie

              Hello Wolf-Dieter,

               

              thank your for your hints.

               

              i think scoped-context could be the solution.

              Is it neccessary for scoped context usage to define outbound-remote-connection, also (Jboss to jboss lookup)?

               

              Currenty we use jboss-7.1.1.Final (standalone) for our migration tests, but i think this version does not support scoped-context.

               

              I will check this with Version 7.2.0 (EAP6.1.0), in this version it shoud be support!?

              • 4. Re: JNDI Lookup from host to host
                Wolf-Dieter Fink Master

                If you use scoped-context there is no need to define outbound-remote-connection. (Only if you still use it somewhere else)

                 

                The scoped-context was introduces with 7.2.0 which is EAP.6.1.Alpha so any version after that will have this feature. If you use it with versions before the properties are not evaluated.

                • 5. Re: JNDI Lookup from host to host
                  s.horn Newbie

                  Hello,

                   

                  i am missing something.

                  i configured two Jboss eap 6.1 on two machines.

                   

                  Server1 should do an ejb lookup on a bean in server 2 using scoped context.

                   

                  Therefor the Servlet in server1 use the following code:

                      

                              Properties env = new Properties();
                              env.put("org.jboss.ejb.client.scoped.context", true);
                              env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
                              env.put("endpoint.name", "endpoint-client");
                              String connection = "server2";
                              env.put("remote.connections", connection);
                              env.put("remote.connection." + connection + ".host", "<server2>");
                              env.put("remote.connection." + connection + ".port", "4447");
                              env.put("remote.connection." + connection + ".connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
                              env.put("remote.connection." + connection + ".connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "true");
                              env.put("remote.connection." + connection + ".username", "user");
                              env.put("remote.connection." + connection + ".password", "password");
                              env.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");

                   

                              Context ctx = new InitialContext(env);

                   

                              EcarosSessionRemote remote = (EcarosSessionRemote)ctx.lookup("ejb:ecaros2-server-application/ecaros2-server/EcarosSessionRemote!de.procar.ecaros2.server.EcarosSessionRemote");

                   

                  Now, what happens.

                  I see an successfull handshake on both servers, but after that :

                   

                  11:02:38,843 ERROR [stderr] (http-/0.0.0.0:8080-1) java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:ecaros2-server-application, moduleName:ecaros2-server, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@7f43d1 11:02:38,843

                   

                  The server1 seams to lookup on localhost instead of the server2 IP.

                  if i deploy the bean on server1, it invoces the bean localhost.

                   

                  Any ideas, why the scoped context is not used for invocation, but for handshake?

                  • 6. Re: JNDI Lookup from host to host
                    s.horn Newbie

                    I found out the problem,

                     

                    everytime the invocation context is garbagecollected server1 switch to use the local ejb client context.

                     

                    So the first methods are called on server2,

                     

                    then the garbage collection

                     

                    and the last methods are called on server1 (localhost)

                    • 7. Re: JNDI Lookup from host to host
                      Wolf-Dieter Fink Master

                      Do you keep a reference to the Context ctx? Or is it a (method)local variable?

                      The proxy 'remote' is tight to the scoped-context, but if it is GCed the connection is closed and the proxy might fallback to local invocation.

                      • 8. Re: JNDI Lookup from host to host
                        s.horn Newbie

                        Scoped Context was the right hint.

                         

                        Now everything works, thank you.

                         

                        What's a little bit disturbing, is the fact, that the lookup via JNDI Context is not threadsafe anymore.

                         

                        So it is impossible to use scoped context for the client side lookups, too.

                        Using Jboss classes in our sourcecode is not optimal, but it works.

                        • 9. Re: JNDI Lookup from host to host
                          Wolf-Dieter Fink Master

                          What's a little bit disturbing, is the fact, that the lookup via JNDI Context is not threadsafe anymore.

                          I don't understand why you think it will be not thread save. You can access the IC and the proxies concurrent.

                          The difference is that, if you use scoped-context, you will be responsible to control the connection  and therefore you need to keep the IC (maybe in a Singleton) to keep the connections opened as long you need a proxy looked up by this IC.