4 Replies Latest reply on Jan 7, 2003 10:47 PM by Juha Lindfors

    Naming issue...

    Sean McGill Newbie

      I'm having a problem just getting a hello world application working...

      I've compiled & deployed a HelloWorld application, but when I try to run the client... I always get the following exception :

      javax.naming.NameNotFoundException: Hello not bound at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
      at sun.rmi.transport.StreamRemoteCall.executeCall (StreamRemoteCall.java:220)
      .
      .
      .



      Here's the code in a nutshell (- imports, comments, etc) :

      // Remote interface
      public interface HelloWorld extends EJBObject
      {
      public String hello() throws RemoteException;
      }

      // Home interface
      public interface HelloWorldHome extends EJBHome
      {
      HelloWorld create() throws RemoteException, CreateException;
      }

      // EJB class
      public class HelloWorldEJB implements SessionBean
      {
      private SessionContext ctx;

      public void setSessionContext(SessionContext ctx)
      {
      this.ctx = ctx;
      }

      public void ejbRemove()
      {
      System.out.println( "ejbRemove()" );
      }

      public void ejbActivate()
      {
      System.out.println( "ejbActivate()" );
      }

      public void ejbPassivate()
      {
      System.out.println( "ejbPassivate()" );
      }

      /**
      * The method called to display the string "Hello World!"
      * on the client.
      */
      public String hello()
      {
      return "Hello World!";
      }
      }


      // XML Deployment stuff
      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar>
      JBoss Hello World Application
      <display-name>Hello World EJB</display-name>
      <enterprise-beans>

      <ejb-name>Hello</ejb-name>
      helloworld.HelloWorldHome
      helloworld.HelloWorld
      <ejb-class>helloworld.HelloWorldEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>

      </enterprise-beans>
      </ejb-jar>

      // Client
      public class HelloWorldClient
      {
      public static void main(String[] args)
      {
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "localhost:1099");
      env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      try
      {
      Context ctx = new InitialContext(env);
      Object obj = ctx.lookup( "Hello" );
      HelloWorldHome home = (HelloWorldHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloWorldHome.class );
      HelloWorld helloWorld = home.create();
      System.out.println( helloWorld.hello());
      helloWorld.remove();
      }
      catch ( Exception e )
      {
      e.printStackTrace();
      System.out.println( "Exception: " + e.getMessage() );
      }
      }
      }



      1. I compiled the class files for everything, except the client and packaged them into HelloWorld.jar w/ the xml meta information.

      2. Copied the HelloWorld.jar file into the jboss deploy directory and got the following :

      14:22:08,397 INFO [MainDeployer] Starting deployment of package: file:/C:/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/H
      14:22:08,413 INFO [MainDeployer] Deployed package: file:/C:/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/HelloWorld.jar

      (In the tutorial I noticed more output when deploying the interfaces, etc.. things refering to creating EJB objects)

      3. Compiled & ran the client

        • 1. Re: Naming issue...
          Juha Lindfors Master

          browse to http://localhost:8080/jmx-console

          do a search on 'JNDIView'

          click on the link

          find list() operation and click 'invoke'

          In the displayed output, go to Global Namespace and see if there's anything bound under the name 'Hello'

          • 2. Re: Naming issue...
            Weber Oliveira Newbie

            hi,

            i think i know what's happening. As you said, it is a naming issue. The problem is that you are passing to the lookup method the bean's *ejb-name* instead of passing its jndi-name or local-jndi-name. This lookup method is part of the jndi API and requires that you specify where, in the jndi namespace, your bean can be found.

            The link between the ejb-name and the jndi-name can be specified in the jboss.xml descriptor. I don't know if you properly set this descriptor, but it could look like the following :

            **********************************************************
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS//EN" "http://www.jboss.org/j2ee/dtd/
            jboss.dtd">



            <enterprise-beans>


            <ejb-name>HelloWorld</ejb-name>
            <jndi-name>ejb/HelloWorld</jndi-name>


            </enterprise-beans>

            <resource-managers>
            </resource-managers>


            **********************************************************

            now, the lookup could be done with the string "ejb/HelloWorld".

            I think that's pretty much all there's to it.

            PS: if i'm not mistaken, when you're using your client app localy (i.e. when you're using the jndi API within the same VM that the JBoss server is running) you can create the InitialContext without any arguments (or .jndi.properties file).

            I wish it helps,
            Weber

            • 3. Re: Naming issue...
              venko Newbie

              Hi I am also facing similar proble.
              the error I am getting is
              16:37:44,761 ERROR [STDERR] javax.naming.NameNotFoundException: test not bound
              16:37:44,761 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495
              16:37:44,761 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503
              16:37:44,761 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
              16:37:44,761 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
              16:37:44,771 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:256)

              • 4. Re: Naming issue...
                Juha Lindfors Master

                what is the string you're trying to lookup and what does your JNDIView show as the content of your naming service?