4 Replies Latest reply on Mar 8, 2012 3:16 PM by Randahl Fink Isaksen

    JBoss AS 7.1.0 and The invincible javax.naming.NameNotFoundException

    Randahl Fink Isaksen Novice

      I am trying to connect to a stateless EJB from a desktop client application and it works partially – I can contact the server, but no matter how I try to name the EJB, I get a NameNotFoundException. If anyone could give me a hint to things I could try out, I would be grateful.

       

      My environment:

       

      Server Side

       

      JBoss 7.1.0

      My EAR: wefend-server.ear

      My EJB archive: wefend-server-ejb

      My bean: AuthenticationBean

      My remote business interface: Authentication

       

      JNDI bindings reported by JBoss 7.1.0 console log:

      20:11:06,967 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-15) JNDI bindings for session bean named AuthenticationBean in deployment unit subdeployment "wefend-server-ejb.jar" of deployment "wefend-server.ear" are as follows:

                java:global/wefend-server/wefend-server-ejb/AuthenticationBean!com.wefend.server.authentication.Authentication

                java:app/wefend-server-ejb/AuthenticationBean!com.wefend.server.authentication.Authentication

                java:module/AuthenticationBean!com.wefend.server.authentication.Authentication

                java:jboss/exported/wefend-server/wefend-server-ejb/AuthenticationBean!com.wefend.server.authentication.Authentication

                java:global/wefend-server/wefend-server-ejb/AuthenticationBean

                java:app/wefend-server-ejb/AuthenticationBean

                java:module/AuthenticationBean

       

      Client Side

       

      Maven dependencies:



      <dependency>



      <groupId>org.jboss.as</groupId>



      <artifactId>jboss-as-ejb-client-bom</artifactId>



      <type>pom</type>



      <version>7.1.0.Final</version>


      </dependency>


      <dependency>



      <groupId>org.jboss.as</groupId>



      <artifactId>jboss-as-jms-client-bom</artifactId>



      <type>pom</type>



      <version>7.1.0.Final</version>


      </dependency>

       

      jboss-ejb-client.properties:

       

           remote.connections=default

           endpoint.name=client-endpoint

           remote.connection.default.port=4447

           remote.connection.default.host=127.0.0.1

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

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

       

      The lookup:

       

        Properties properties = new Properties();

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

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

                                    properties.put(javax.naming.Context.PROVIDER_URL, "remote://localhost:4447");

                                    properties.put(javax.naming.Context.SECURITY_PRINCIPAL, "test");

                                    properties.put(javax.naming.Context.SECURITY_CREDENTIALS, "1234");

        javax.naming.Context context = new InitialContext(properties);

        String viewClassName = Authentication.class.getName();

        Authentication authentication =

          (Authentication) context.lookup("ejb:/wefend-server/wefend-server-ejb//AuthenticationBean!" + viewClassName");

       

      Exception

       

      javax.naming.NameNotFoundException: ejb:/wefend-server/wefend-server-ejb//AuthenticationBean!com.wefend.server.authentication.Authentication -- service jboss.naming.context.java.jboss.exported.ejb:.wefend-server.wefend-server-ejb."AuthenticationBean!com.wefend.server.authentication.Authentication"

                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:680)


        • 1. Re: JBoss AS 7.1.0 and The invincible javax.naming.NameNotFoundException
          jaikiran pai Master

          Change the code to match what's explained here https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI. You don't need these lines in the code:

           

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

                                        properties.put(javax.naming.Context.PROVIDER_URL, "remote://localhost:4447");

                                        properties.put(javax.naming.Context.SECURITY_PRINCIPAL, "test");

                                        properties.put(javax.naming.Context.SECURITY_CREDENTIALS, "1234");

           

           

          Just set the user name and password in the jboss-ejb-client.properties:

           

          remote.connection.default.username=test

          remote.connection.default.password=1234

          1 of 1 people found this helpful
          • 2. Re: JBoss AS 7.1.0 and The invincible javax.naming.NameNotFoundException
            Randahl Fink Isaksen Novice

            Thank you, but I have tried that. I have been using this jboss-ejb-client.properties

             

            remote.connections=default

            endpoint.name=client-endpoint

            remote.connection.default.port=4447

            remote.connection.default.host=127.0.0.1

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

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

            remote.connection.default.username=test

            remote.connection.default.password=1234

             

            And this code

            final Hashtable jndiProperties = new Hashtable();

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

            final javax.naming.Context context = new InitialContext(jndiProperties);

            final String viewClassName = Authentication.class.getName();

            Authentication authentication = (Authentication) context.lookup("ejb:wefend-server/wefend-server-ejb//AuthenticationBean!" + viewClassName);

             

            but then I get

             

            java.lang.IllegalStateException: No EJB receiver available for handling [appName:wefend-server,modulename:wefend-server-ejb,distinctname:] combination

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

                      at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:84)

                      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175)

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

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

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

                      at $Proxy0.authenticate(Unknown Source)

                      at com.wefend.ui.Wefend.testJndi(Wefend.java:160)

                      at com.wefend.ui.Wefend.init(Wefend.java:110)

                      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:276)

                      at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:28)

                      at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:98)

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

             

            As a side note, I was hoping to configure the user name and password at runtime since each enduser will have their own login.

            • 3. Re: JBoss AS 7.1.0 and The invincible javax.naming.NameNotFoundException
              jaikiran pai Master

              Randahl Fink Isaksen wrote:

               

              java.lang.IllegalStateException: No EJB receiver available for handling [appName:wefend-server,modulename:wefend-server-ejb,distinctname:] combination

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

                        at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:84)

                        at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175)

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

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

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

                        at $Proxy0.authenticate(Unknown Source)

                        at com.wefend.ui.Wefend.testJndi(Wefend.java:160)

                        at com.wefend.ui.Wefend.init(Wefend.java:110)

                        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:276)

                        at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:28)

                        at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:98)

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

               

               

              That indicates that the jboss-ejb-client.properties isn't available in the client classpath.

               

               

              Randahl Fink Isaksen wrote:

               

              As a side note, I was hoping to configure the user name and password at runtime since each enduser will have their own login.

              Yeah, that's possible. You can use a CallbackHandler to do that. The property for that is:

               

              remote.connection.<connection-name>.callback.handler.class=<fully qualified class name of callback handler>

              • 4. Re: JBoss AS 7.1.0 and The invincible javax.naming.NameNotFoundException
                Randahl Fink Isaksen Novice

                Wonderful, jaikiran pai – that was it. I had placed the jboss-ejb-client.properties in META-INF of my jar. Moving it to the root of my source tree fixed the problem.

                 

                You made my day :-)

                 

                Thanks!

                 

                Randahl