0 Replies Latest reply on Oct 26, 2017 2:45 AM by Cleiton Ribeiro

    Remote JNDIjavax.naming.NameNotFoundException

    Cleiton Ribeiro Newbie

      Hi everyone!

       

      i'm trying to learn how to implement a remote ejb and i'm following the steps that i found at this website:

      EJB invocations from a remote client using JNDI - JBoss AS 7.1 - Project Documentation Editor

       

      The only difference is my Application Server, because have been using the Jboss EAP 7.0.

       

      I've two projects... the first one is my EJB project which is deployed in my EAP 7.0 and it has a class and its respective interface:

      RemoteCalculator Interface

      package br.com.ejb.remote.stateless;
      
      
      public interface RemoteCalculator {
      
      
      int add(int a,int b);
      int subtract(int a, int b);
      }
      

       

      CalculatorBean

      package br.com.ejb.remote.stateless;
      
      
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      
      
      @Stateless
      @Remote(RemoteCalculator.class)
      public class CalculatorBean implements RemoteCalculator{
      
      
           public int add(int a, int b) {
                return a+b;
           }
      
           public int subtract(int a, int b) {
                return a-b;
           }
      }
      

       

      The EJB project is called : EJBExemplo

       

      Finally, my client project is called EJBCliente and it has only a main class, a jboss-ejb-client.properties file and the library jboss-client.jar in the classpath.

       

      The mains class is the following:

      package br.com.ejb.cliente;
      
      
      import java.util.Hashtable;
      
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      
      import br.com.ejb.remote.stateful.CounterBean;
      import br.com.ejb.remote.stateful.RemoteCounter;
      import br.com.ejb.remote.stateless.CalculatorBean;
      import br.com.ejb.remote.stateless.RemoteCalculator;
      
      
      public class RemoteEJBCliente {
      
      
      public static void main(String args[]) throws NamingException {
      invokeStatelessBean();
      invokeStatefulBean();
      }
      
      
      public static void invokeStatelessBean() throws NamingException {
      final RemoteCalculator statelessRemoteCalculator = lookupRemoteCalculator();
      
      
      int a = 204;
      int b = 340;
      
      
      int sum = statelessRemoteCalculator.add(a, b);
      System.out.println("Resultado da soma : " + sum);
      }
      
      
      public static void invokeStatefulBean() throws NamingException {
      final RemoteCounter statefulCounter = lookupStatefulCounter();
      
      
      for (int i = 1; i <= 20; i++) {
      statefulCounter.increment();
      System.out.println("Count after increment: " + statefulCounter.getCount());
      }
      
      
      for (int i = 20; i >= 1; i--) {
      statefulCounter.decrement();
      System.out.println("Count after decrement: " + statefulCounter.getCount());
      }
      }
      
      
      private static RemoteCounter lookupStatefulCounter() throws NamingException {
      final Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
      jndiProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY,
      "org.jboss.naming.remote.client.InitialContextFactory");
      jndiProperties.put(InitialContext.PROVIDER_URL, "http-remoting://localhost:8080");
      final Context context = new InitialContext(jndiProperties);
      
      
      final String appName = "";
      final String moduleName = "EJBExemplo";
      final String beanName = CounterBean.class.getSimpleName();
      final String viewClassName = RemoteCounter.class.getName();
      
      
      return (RemoteCounter) context
      .lookup("ejb:/" + moduleName + "//" + beanName + "!" + viewClassName + "?stateful");
      }
      
      
      private static RemoteCalculator lookupRemoteCalculator() throws NamingException {
      final Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
      jndiProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY,
      "org.jboss.naming.remote.client.InitialContextFactory");
      jndiProperties.put(InitialContext.PROVIDER_URL, "http-remoting://localhost:8080");
      final Context context = new InitialContext(jndiProperties);
      final String appName = "";
      final String moduleName = "EJBExemplo";
      final String beanName = CalculatorBean.class.getSimpleName();
      final String viewClassName = RemoteCalculator.class.getName();
      
      
      return (RemoteCalculator) context
      .lookup("ejb:/" + moduleName + "//" + beanName + "!" + viewClassName);
      }
      }
      

       

      My properties file:

      java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
      java.naming.provider.url=remote://localhost:4447
      jboss.naming.client.ejb.context=true
      java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
      endpoint.name=client-endpoint
      remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
      remote.connections=default
      remote.connection.default.host=localhost
      remote.connection.default.port = 4447
      remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
      remote.connection.default.username=usuario
      remote.connection.default.password=123
      remote.connections=one, two 
      remote.connection.one.host=localhost
      remote.connection.one.port=6999
      remote.connection.one.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
      remote.connection.two.host=localhost
      remote.connection.two.port=7999
      remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
      

       

      Whe i run the main class i receive an error message like:

      out 26, 2017 4:19:35 AM org.xnio.Xnio <clinit>
      INFO: XNIO version 3.3.6.Final-redhat-1
      out 26, 2017 4:19:35 AM org.xnio.nio.NioXnio <clinit>
      INFO: XNIO NIO Implementation Version 3.3.6.Final-redhat-1
      out 26, 2017 4:19:35 AM org.jboss.remoting3.EndpointImpl <clinit>
      INFO: JBoss Remoting version 4.0.18.Final-redhat-1
      Exception in thread "main" javax.naming.NameNotFoundException: ejb:/EJBExemplo//CalculatorBean!br.com.ejb.remote.stateless.RemoteCalculator -- service jboss.naming.context.java.jboss.exported.ejb:.EJBExemplo."CalculatorBean!br.com.ejb.remote.stateless.RemoteCalculator"
      at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
      at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
      at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
      

       

      Any idea ?

       

      I think that EJB technology its so hard to implement because each application server has its own properties, configurations, and ways to prepare the enviroment to work with remote/local ejb's, maybe the advantages of ejb could be affected by the time that is necessary to configure everything.