11 Replies Latest reply on Jul 24, 2012 8:19 AM by shinosha

    Local lookup failing

    shinosha

      Hello,

      I'm a kinda newbie with JEE and Jboss 7 and I'm currently working on a project for school. I work with JBoss 7.1.1 and Eclipse. I just finished a part of my DAO and want to test it using TestNG. Since I use Struts 2 I can't really use dependecy injection, so I thought about Service Locator. The problem is I get java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory when running the test method (full stacktrace) which triggers my delegate business method using my service locator. Test class is in my business layer.

       

      The properties for the locator :

       

       

      private ServiceLocator() throws NamingException

        {

      Properties props = new Properties();

      props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");

      props.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");

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

      context = new InitialContext(props);

        }

       

       

      The JNDI string :

       

      dao = (UtilisateurHome) ServiceLocator.getInstance().getService("java:global/businessLayer/UtilisateurHome");

       

      So this is my UtilisateurHome EJB from businessLayer project.

       

      Basically, what jar am I supposed to include in my classpath for local invocation ? Then what properties should I use ? Thanks.

        • 1. Re: Local lookup failing
          shinosha

          Well, I used jnp-client-4.0.2.jar and it worked, but now I have Caused by: java.net.SocketTimeoutException: Receive timed out... I'd like to know what port is Jboss listening to but I can't find it on Jboss7. By the way, are my properties corrects ?

          • 2. Re: Local lookup failing
            wdfink

            AS7 is different to former versions.

            You should use the new ejb-client connections. See https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

            • 3. Re: Local lookup failing
              shinosha

              So I put my properties file in my src folder of my .war and it looks like this :

               

              endpoint.name=client-endpoint

              remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

               

              remote.connections=default

               

              remote.connection.default.host=127.0.0.1

              remote.connection.default.port = 4447

              remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

               

              remote.connection.default.username=Shinosha

              remote.connection.default.password=*****

               

               

              I of course have ejb-client.jar in my build path. But it's still asking me for an initial context :

               

              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(Unknown Source)

               

              What have I done wrong here ?

              • 4. Re: Local lookup failing
                shinosha

                No one can help ? Is it even possible ?

                • 5. Re: Local lookup failing
                  wdfink

                  Do you use a web-app as client? Is it deployed in a JBoss instance?

                  Also how your InitialContext looks like (what properties do you set) and how the properties are named?

                  • 6. Re: Local lookup failing
                    shinosha

                    Do you use a web-app as client? Is it deployed in a JBoss instance?

                    scee.png

                    My .war contains the Service locator which does the lookup and the .jar my EJB stateless (no interface view)

                     

                    Also how your InitialContext looks like (what properties do you set) and how the properties are named?

                     

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

                     

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

                    context = new InitialContext(jndiProperties);

                     

                    Along with what I already said in my last post of course.

                    • 7. Re: Local lookup failing
                      jaikiran

                      You are using an incorrect JNDI name. You should be using ejb: namespace JNDI name. The article that Wolf pointed you to has the details. But before we go into that, I'm a bit confused about what you are trying to do. Your thread title says "Local lookup failing" but you are doing a lookup from a remote EJB client. You can't access local business interfaces from a remote client.

                      • 8. Re: Local lookup failing
                        shinosha

                        I just have, on the same server, a jar with my business and a war that uses it. I would like my webapp to access my EJB. I'm confused about the terminology I guess.

                        You can't access local business interfaces from a remote client.

                         

                        I just found this page... I understand better now but I already tried java:global actually but I got NoInitialContextException. That's why I tried remote access then, which was nonsense but I didn't realize it. From what I'm reading here I also need tobind my EJBs in my web.xml right ? Do you have a example because I don't really get what I'm supposed to write for an EJB. Thanks

                        • 9. Re: Local lookup failing
                          shinosha

                          I changed my lookup to java:global and did not pass any parameter to the InitialContext constructor and still have the same thing from my TestNG class (NoInitialContextException). But when I do it from my action class in Struts 2 I get ClassCastException on my EJB... So I guess this is working somehow but I still have a problem regarding my tests and this ClassCastException. On the last one it seems it's due to my deployments and project structure but I can't solve the issue...

                          • 10. Re: Local lookup failing
                            wdfink

                            Do you pack the interface classes into both archives, that will force such ClassCastExecptions for the same class, as it is loaded by different classloaders.

                            You can drop the interface classes from your archive and provide it as a module.

                            Or you might use call-by-value instead of call-by-reference (in that case you use it global and you can not use local interfaces).

                            • 11. Re: Local lookup failing
                              shinosha

                              Since I'm all local, according to JEE6 I can adopt the no interface view for my EJB, which I did. So I don't have any interfaces. The only thing I have right now is my EJBs packaged in a jar in my war build path.

                               

                              And I managed to make it work actually. Now I have an EJB module packaged as a jar inside my war project. And I only deployed the war on the server using the lookup with java:module/EJBname. Thanks for your help anyway.