1 2 Previous Next 19 Replies Latest reply on Apr 12, 2012 4:34 PM by Wolfgang Knauf

    Application Client and ENC in AS7.1

    Wolfgang Knauf Master

      Hi,

       

      I try to find out how a JNDI lookup in an application client might work, when the EJB is not looked up in global JNDI, but in the Environment Naming Context (ENC).

       

      Unfortunately the application client tutorial at https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI ends before this information ;-).

       

      In JBoss 6 and before, I had to to those steps (I already tried to port it to AS7, so e.g. the JNDI name is no longer AS6 style):

       

      Declare the ejb ref in "application-client.xml":

      {code:xml}

      <?xml version="1.0" encoding="UTF-8"?>

      <application-client id="Application-client_ID" version="6"

          xmlns="http://java.sun.com/xml/ns/javaee"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application-client_6.xsd">

          ...

          <ejb-ref>

              <ejb-ref-name>ejb/GeometricModel</ejb-ref-name>

              <ejb-ref-type>Session</ejb-ref-type>

              <remote>de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote</remote>

          </ejb-ref>

         

      </application-client>

      {code}

       

      Connect the EJB ref to a JNDI name in "jboss-client.xml":

       

      {code:xml}

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE jboss-client PUBLIC

          "-//JBoss//DTD Application Client 5.0//EN"

          "http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd">

      <jboss-client>

          <jndi-name>StatelessClient</jndi-name>

          <ejb-ref>

              <ejb-ref-name>ejb/GeometricModel</ejb-ref-name>

              <jndi-name>ejb:Stateless/StatelessEJB/GeometricModelBean!de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote</jndi-name>

          </ejb-ref>

       

      </jboss-client>

      {code}

       

      Perform a lookup... Following are a few fragments, which all don't work (besides the lookup in global JNDI):

       

      {code}

      Properties props = new Properties();

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

       

      InitialContext initialContext = new InitialContext(props);

      Object objRemote = initialContext.lookup("java:comp/env/ejb/GeometricModel");

      //Object objRemote = initialContext.lookup("ejb/GeometricModel");

      //Object objRemote = initialContext.lookup("ejb:Stateless/StatelessEJB/GeometricModelBean!de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote");

      //GeometricModelRemote geometricModel = (GeometricModelRemote) PortableRemoteObject.narrow(objRemote, GeometricModelRemote.class);

      GeometricModelRemote geometricModel = (GeometricModelRemote) objRemote;

      {code}

       

      All lookups (besides the global lookup) result in this exception:

       

      {code}

      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

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

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

          at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)

          at javax.naming.InitialContext.lookup(InitialContext.java:392)

          at de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient.main(GeometricModelApplicationClient.java:49)

      {code}

       

       

      Is the ENC supported in AS7 for application clients? If yes: what is necessary to use it ;-)?

       

      Best regards

       

      Wolfgang

        • 1. Re: Application Client and ENC in AS7.1
          Wolfgang Knauf Master

          Anybody with a hint for me?

           

          Best regards

           

          Wolfgang

          • 2. Re: Application Client and ENC in AS7.1
            Stuart Douglas Master

            If you don't pass the properties into the InitialContext it should work. Appclient sets that for you automatically so it is not nessesary.

            • 3. Re: Application Client and ENC in AS7.1
              Wolfgang Knauf Master

              I followed the tutorial at https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI, and this tutorial sets the "Context.URL_PKG_PREFIXES".

               

              So you mean that by not setting this property, an ENC lookup should work?

               

              Best regards

               

              Wolfgang

              • 4. Re: Application Client and ENC in AS7.1
                Wolfgang Knauf Master

                Hi,

                 

                I still need help with this.

                 

                I could work around the "NoInitialContextException" of my initial post by using those properties:

                 

                 


                {code}
                       props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
                      props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                      props.setProperty(Context.PROVIDER_URL, "remote://localhost:4447");
                      props.setProperty(Context.SECURITY_PRINCIPAL, "myuser");
                      props.setProperty(Context.SECURITY_CREDENTIALS, "mypassword");
                {code}

                 

                But when doing a lookup for "java:comp/env", I see this exception:

                 

                 



                07.03.2012 22:25:09 org.xnio.Xnio <clinit>
                INFO: XNIO Version 3.0.3.GA
                07.03.2012 22:25:09 org.xnio.nio.NioXnio <clinit>
                INFO: XNIO NIO Implementation Version 3.0.3.GA
                07.03.2012 22:25:09 org.jboss.remoting3.EndpointImpl <clinit>
                INFO: JBoss Remoting version 3.2.2.GA
                javax.naming.NameNotFoundException: comp/env/ejb/GeometricModel -- service jboss.naming.context.java.jboss.exported.comp.env.ejb.GeometricModel
                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$Worker.runTask(ThreadPoolExecutor.java:886)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
                at java.lang.Thread.run(Thread.java:662)

                 

                Does anybody have an idea?

                 

                When using the ENC in a servlet, it works fine (declaring the ejb ref in "web.xml").

                 

                Best regards

                 

                Wolfgang

                • 5. Re: Application Client and ENC in AS7.1
                  Stuart Douglas Master

                  In the application client you just use "new InitialContext()" to be able to lookup the ENC.

                   

                  Using remote naming like you are using only lets you lookup the java:jboss/exported server namespace.

                  • 6. Re: Application Client and ENC in AS7.1
                    Wolfgang Knauf Master

                    Hi Stuart (or anyone else),

                     

                    I attach an EAR file with a sample project. Maybe you find the time to look at it. It is easier than discussing just code snippets ;-).

                     

                    To run it: import it in Eclipse (best using the JBoss Tools plugin with a JBoss 7.1 server runtime declared).

                    In the app client project, add "%JBOSS_HOME%\bin\client\jboss-client-7.1.0.Final.jar" to the Java Build Path. Then run it as a simple java application.

                     

                    My initial error message "javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file" should be shown in console.

                     

                    For a web app, the ENC works fine (browse to http://localhost:8080/StatelessWeb/servlet/GeometricModelServlet after deployment to see a small servlet).

                     

                    In previous JBoss version, I saw an error message when the "ejb-ref/jndi-name" in "jboss-client.xml" pointed to an invalid JNDI name. But in AS7 I don't see this error. So: is "jboss-client.xml" the proper way to declare an ENC ejb ref? Or is the ENC not supported for app clients?

                     

                    Best regards

                    Wolfgang

                    • 7. Re: Application Client and ENC in AS7.1
                      Wolfgang Knauf Master

                      Hi Stuart,

                       

                      just wanted to bring back your attention to this question ;-). Sorry to be so annoying, but I maintain a bunch of (German) JBoss tutorials, and I try to port my AS5 samples to AS7.x. And I am stuck with my first simple sample, which shows just a stateless bean with all kinds of usage :-(.

                      The JavaDoc at http://docs.jboss.org/ejbclient/1.0.5.Final/ unfortunately did not bring me further clarification.

                       

                      Best regards

                       

                      Wolfgang

                      • 8. Re: Application Client and ENC in AS7.1
                        Stuart Douglas Master

                        I deployed your application and it appears to work fine against upstream, I don't see any errors in the console.

                        • 9. Re: Application Client and ENC in AS7.1
                          Wolfgang Knauf Master

                          How did you start the client? I still see the error.

                           

                          To check that it is no Eclipse problems, I tried a batch file today (should have tried this before ;-)).

                           

                          Steps to reproduce:

                          1) deploy "Stateless.ear" to the server

                          2) extract "StatelessEJB.jar" and "StatelessClient.jar" to any directory.

                          3) in the directory where the two jars were extracted to, run this command:

                           

                          {quote}
                          java -classpath StatelessClient.jar;StatelessEJB.jar;C:\temp\jboss-as-7.1.2.Final-SNAPSHOT\bin\client\jboss-client.jar de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient
                          {quote}

                           

                          This still brings the "javax.naming.NoInitialContextException" when performing a lookup for "java:comp/env/ejb/GeometricModelRemoteFromENC".

                           

                          Best regards

                           

                          Wolfgang

                          • 10. Re: Application Client and ENC in AS7.1
                            Stuart Douglas Master

                            Firstly that command does not launch the EE application client, it will simply run a client program with the EJB client libraries on the class path. To launch the application client you need to use the ./appclient.sh script in the bin directory.

                             

                            The EE application client is basically a cut down server instance, that has access to its own EE namespaces, and all the other stuff that is specified in the EE specification.

                             

                            The EJB client libraries on the other hand simply allow you to invoke remote EJB's, they do not give access to  java:comp, java:module etc. Instead there is a jboss specifiec ejb: namespace that you can use, or you can use remote naming to look up entries in the java:jboss/exported namespace. 

                            • 11. Re: Application Client and ENC in AS7.1
                              Wolfgang Knauf Master

                              OK, this might be a step forward ;-).

                               

                              But I did not manage to make "appclient.bat" work. I found this post: https://community.jboss.org/message/638220

                              The "appclient.sh" call from there did not work for me:

                              C:\temp\jboss-as-7.1.2.Final-SNAPSHOT\bin>.\appclient.bat Stateless.ear#StatelessClient.jar

                               

                              =>this just caused an error:

                               

                              {quote}

                              JBAS015801: Invalid option 'Stateless.ear#StatelessClient.jar'Usage: ./standalone.sh [args...]

                              where args include:

                                  --admin-only                        Set the server's running type to

                              ...

                              {quote}

                               

                              Has the call changed?

                               

                              If "appclient.bat" just launches a trimmed server, is it the same as a "embedded JBoss" in previous major versions? Do I have to "deploy" my app in some manner?

                               

                              Probably I will not find the time to continue on this before next week. But I will keep continuing to ask dumb questions ;-).

                               

                              Best regards

                               

                              Wolfgang

                              • 12. Re: Application Client and ENC in AS7.1
                                Stuart Douglas Master

                                It looks like this may be a bug in the appclient.bat script, I will investigate, although I don't really have a convenient way to test on windows.

                                • 13. Re: Application Client and ENC in AS7.1
                                  Wolfgang Knauf Master

                                  If there is anything I can do to help, please give me advice ;-)

                                  • 14. Re: Application Client and ENC in AS7.1
                                    Stuart Douglas Master

                                    You could give upstream a try, I committed a fix today.

                                    1 2 Previous Next