5 Replies Latest reply on Jan 22, 2014 3:20 PM by Wolf-Dieter Fink

    Jboss 7.1 EJB remote-naming lookup (w/ jndi) and no application realm security

    mr.elusiv Newbie

      Hi, although I visit these forums from time to time, this is my first post.

      We are currently migrating an app from Jboss 5 --> Jboss 7 and would like to avoid CDI until we have stabilized our current application.

       

      What we do not want at this time:

      • ejb-client.properties
      • application security (as we are running other security layers and routing)
      • ejb client api usage (we only want JNDI)

       

      What I am trying to do:

      1. Dynamically make calls to various Jboss App servers via programmatically set properties
      2. Lookup a Stateful EJB on local OR remote server with a Pojo client application via Jndi and jboss-remote-naming (NOT ejb client API)
      3. Remove all application-realm security, by stripping out the application-realm from standalone.xml configuration

      See this article if you are unsure: https://community.jboss.org/thread/213470

       

      Note:

      I do not have an ejb-client.xml in my app server.

      I have managed to get this project working correctly using jboss-ejb-client.properties and EJB Naming previously.

       

       

       

      Client Code (Pojo project with jboss 7 libraries):


      private static final String DEFAULT_HOST ="1.2.3.4";

      private static final String DEFAULT_REMOTING_PORT="4447";

      private static final String DEFAULT_USER= "admin";

      private static final String DEFAULT_PASSWORD= "password";

      private static final String CONTEXT_PROVIDER_URL = "remote://" + DEFAULT_HOST + ":" + DEFAULT_REMOTING_PORT;

       

      //THE CODE

      Properties prop = new Properties();

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

      prop.setProperty(Context.PROVIDER_URL, CONTEXT_PROVIDER_URL);

      //        prop.setProperty(Context.SECURITY_PRINCIPAL, DEFAULT_USER);

      //        prop.setProperty(Context.SECURITY_CREDENTIALS, DEFAULT_PASSWORD);

      //        prop.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");

      //        prop.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");

       

      Properties ejbProp = new Properties();

      ejbProp.put("remote.connections", "default");

      ejbProp.put("remote.connection.default.host",DEFAULT_HOST);

      ejbProp.put("remote.connection.default.port",DEFAULT_REMOTING_PORT);

      ejbProp.put("remote.connection.default.username", DEFAULT_USER);

      ejbProp.put("remote.connection.default.password", DEFAULT_PASSWORD);

      //        ejbProp.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");

      ejbProp.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");

       

       

      final PropertiesBasedEJBClientConfiguration configuration = new PropertiesBasedEJBClientConfiguration(ejbProp);

      final ContextSelector <EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(configuration);

      EJBClientContext.setSelector(ejbClientContextSelector);

       

      MyEJBInterface mei = null;

       

        try{

         Context context = new InitialContext(prop);

       

         String lookupName = "MyEAR/MyEJB/MyInterface!co.org.MyInterfaceRemote";

       

         ResponseObject responseObj;  

         responseObj = (MyInterfaceRemote) context.lookup(lookupName);

          try{

              responseObj = mei.doWork();

       

              if (responseObj !=null){

                 System.out.println("responseObj Received");

              }

              else{

                 System.out.println("Null responseObj.");

              }

          }catch(OtherException oe){ // throw by

              System.err.println("Other Exception occurred. ");

              oe.printStackTrace();

         }

       

        }catch (NamingException ne){

            ne.printStackTrace();

        }

       

       

      On the App server, I can see the started EJB services:

       

         java:global/MyEAR/MyEJB/MyInterface!co.org.MyInterfaceLocal

         java:app/MyEJB/MyInterface!co.org.MyInterfaceLocal

         java:module/MyInterface!co.org.MyInterfaceLocal

         java:global/MyEAR/MyEJB/MyInterface!co.org.MyInterfaceRemote

         java:app/MyEJB/MyInterface!co.org.MyInterfaceRemote

         java:module/MyInterface!co.org.MyInterfaceRemote

         java:jboss/exported/MyEAR/MyEJB/MyInterface!co.org.MyInterfaceRemote

       

      On my client Pojo  the strack-trace is:

       

      org.xnio.Xnio <clinit>

      INFO: XNIO Version 3.0.3.GA

      org.xnio.nio.NioXnio <clinit>

      INFO: XNIO NIO Implementation Version 3.0.3.GA

      org.jboss.remoting3.EndpointImpl <clinit>

      INFO: JBoss Remoting version 3.2.2.GA

      org.jboss.ejb.client.remoting.VersionReceiver handleMessage

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

      org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

      INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@48074a, receiver=Remoting connection EJB receiver [connection=Remoting connection <24bef5>,channel=jboss.ejb,nodename=somepersonallyidentifiableinfo]} on channel Channel ID e5261bed (outbound) of Remoting connection 00275b35 to /1.2.3.4:4447

      org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

      WARN: Unsupported message received with header 0xffffffff

      javax.naming.NamingException: java.lang.IllegalStateException: No EJB client context is available [Root exception is java.lang.RuntimeException: java.lang.IllegalStateException: No EJB client context is available]

          at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:135)

          at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74)

          at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)

          at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:124)

          at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:70)

          at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

          at java.lang.Thread.run(Unknown Source)

      Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: No EJB client context is available

          at org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:91)

          at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:133)

          ... 7 more

      Caused by: java.lang.IllegalStateException: No EJB client context is available

          at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:233)

          at org.jboss.ejb.client.EJBClient.createSession(EJBClient.java:160)

          at org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:89)

          ... 8 more

       

      On my Jboss 7.1 app server I see the following error:

       

      ERROR [org.jboss.remoting.remote.connection] (Remoting "somepersonallyidentifiableinfo" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

      INFO  [org.jboss.as.naming] (Remoting "somepersonallyidentifiableinfo" task-4) JBAS011806: Channel end notification received, closing channel Channel ID 5d21f931 (inbound) of Remoting connection 01ab4788 to null

       

      Note: node name is obviously not "somepersonallyidentifiableinfo", but has been set to my local computing device's name.

       

      Concluding Questions:

      Am I using the jboss remote naming lookup correctly in this case?

      I expect from the errors that this is somehow related to the EJBClientContext, am I missing something in passing this to the initialContext?

       

      Finally I would appreciate it if you do not simply paste other articles here with similar issues, as I have investigated for 10 working days online for solutions and am in need of a bit of guidance if possible.


      Any help or direction here is appreciated - if you would like to see additional code or trace-level output, I will provide it.

        • 1. Re: Jboss 7.1 EJB remote-naming lookup (w/ jndi) and no application realm security
          Wolf-Dieter Fink Master

          You are mixing the programatic use of the ejb-client API (EJBClientContext and lookup("ejb:app/module....") ) and the remote-naming (PROVIDER_URL=remote: and lookup(app/module...").

           

          You should read the article [1] and [2] and decide which way you want to use, recommended is [1].

           

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

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

          • 2. Re: Jboss 7.1 EJB remote-naming lookup (w/ jndi) and no application realm security
            mr.elusiv Newbie

            Thanks for your quick response Wolf-Dieter, however I don't think you read my original post completely.

             

            Two considerations:

            [A] We are trying to avoid the use of any static content such as "jboss-ejb-client.properties" and article [1] requires the use of this file, no?

            [B] I understand you are probably extremely busy, but I did specifically ask not to simply post links to articles.

             

            I am testing article [2]'s approach and will respond with results shortly.

             

            Thanks

            • 3. Re: Jboss 7.1 EJB remote-naming lookup (w/ jndi) and no application realm security
              mr.elusiv Newbie

              Hi Wolf-Dieter,

               

              Using article [2]'s approach.

               

              My Java Client now looks as follows:


              Properties jndiProps = new Properties();

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

              jndiProps.put(Context.PROVIDER_URL, "remote://1.2.3.4:4447");

               

                 try{

                    Context context = new InitialContext(jndiProps);

                    String lookupName = "MyEAR/MyEJB/MyBean!co.org.MyInterfaceRemote";

                    ResponseObject responseObj; 

                    responseObj = (MyInterfaceRemote) context.lookup(lookupName);

                    try{

                     responseObj = mei.doWork();

                        if (responseObj !=null){

                          System.out.println("responseObj Received");

                        }

                        else{

                          System.out.println("Null responseObj.");

                        }

                    }catch(OtherException oe){ // throw by

                       System.err.println("Other Exception occurred. ");

                       oe.printStackTrace();

                    }

                  }catch (NamingException ne){

                     ne.printStackTrace();

                  }

               

              When I execute the client code, the stacktrace is:


              org.xnio.Xnio <clinit>

              INFO: XNIO Version 3.0.3.GA

              org.xnio.nio.NioXnio <clinit>

              INFO: XNIO NIO Implementation Version 3.0.3.GA

              org.jboss.remoting3.EndpointImpl <clinit>

              INFO: JBoss Remoting version 3.2.2.GA

              javax.naming.NamingException: java.lang.IllegalStateException: No EJB client context is available [Root exception is java.lang.RuntimeException: java.lang.IllegalStateException: No EJB client context is available]

                   at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:135)

                   at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74)

                   at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)

                   at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:124)

                   at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:70)

                   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                   at java.lang.Thread.run(Unknown Source)

              Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: No EJB client context is available

                   at org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:91)

                   at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:133)

                   ... 7 more

              Caused by: java.lang.IllegalStateException: No EJB client context is available

                   at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:233)

                   at org.jboss.ejb.client.EJBClient.createSession(EJBClient.java:160)

                   at org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:89)

                   ... 8 more

               

              The Jboss 7.1 server registers the following:


              ERROR [org.jboss.remoting.remote.connection] (Remoting "somepersonallyidentifiableinfo" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

              INFO  [org.jboss.as.naming] (Remoting "somepersonallyidentifiableinfo" task-1) JBAS011806: Channel end notification received, closing channel Channel ID 3d68eab3 (inbound) of Remoting connection 002772ba to /10.50.213.148:63224

               

               

              Some additional things to consider:

              The EJB structure on the server is using EJB 3.0 spec, not 3.1 yet.

              I am not explicitly closing the context yet in this Pojo client code.

               

              Sanity Check

              As a sanity check I also tried to mess up the naming on my Pojo client to see what happens, so I added the "?stateful" to the end, which I know is used in the ejb-naming lookup method.

               

              The stacktrace gave me the following error:

               

              org.xnio.Xnio <clinit>

              INFO: XNIO Version 3.0.3.GA

              org.xnio.nio.NioXnio <clinit>

              INFO: XNIO NIO Implementation Version 3.0.3.GA

              org.jboss.remoting3.EndpointImpl <clinit>

              INFO: JBoss Remoting version 3.2.2.GA

              javax.naming.NameNotFoundException: MyEAR/MyEJB/MyBean!co.org.MyInterfaceRemote?stateful -- service jboss.naming.context.java.jboss.exported.MyEAR.MyEJB."MyBean!co.org.MyInterfaceRemote?stateful"

                   at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

                   at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)

                   at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:124)

                   at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:70)

                   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                   at java.lang.Thread.run(Unknown Source)

               

              This tells me that my naming is correct, as per the exported service on the app server and perhaps the issue is to do specifically with EJB lookup context on the client?

               

              Again, any help is appreciated.

              If more information is required, I will gladly provide it.

               

              Thank you.

              • 4. Re: Jboss 7.1 EJB remote-naming lookup (w/ jndi) and no application realm security
                Dan Holder Newbie

                Hi,

                Did you manage to resolve this issue? I'm experiencing something similar, whilst migrating from JBoss 4.2.3 to 7.1

                 

                Regards

                Dan

                • 5. Re: Jboss 7.1 EJB remote-naming lookup (w/ jndi) and no application realm security
                  Wolf-Dieter Fink Master

                  You might have a look to the documentation I liked before.

                  If that dosn't help you should create a new thread with the appropriate informations.