6 Replies Latest reply on Feb 16, 2006 9:29 PM by joegz1234

    lookup-problem in a swing-client

    oliverroell

      Hello,

      I am using JBoss 4.0.2, JDK 1.5.0_03 & Eclipse 3.02 and I have successfully deployed the "Fibonaci Computation"-application from the JBoss-Eclipse-Tutorial.

      Now I want to connect to the Fibo-EJB from a swing-client with the following program:

      import java.util.*;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;
      import tutorial.interfaces.FiboHome;

      public class SwingClient {

      public static void main(String[] args) {

      try {
      Hashtable props = new Hashtable();
      props.put("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      props.put("java.naming.provider.url",
      "jnp://localhost:1099");
      props.put("java.naming.factory.url.pkgs",
      "org.jboss.naming:org.jnp.interfaces");
      Context context = new InitialContext(props);
      Object ref = context.lookup("java:/comp/env/ejb/Fibo");

      } catch (Exception ex) {
      System.err.println("Caught an exception:");
      ex.printStackTrace();
      }
      }
      }

      After running this program, an exception is occurred:

      Caught an exception:
      javax.naming.NameNotFoundException: comp not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:249)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
      at sun.rmi.transport.Transport$1.run(Transport.java:153)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:595)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at client.SwingClient.main(SwingClient.java:39)


      This line doesn't work:

      Object ref = context.lookup("java:/comp/env/ejb/Fibo");

      But what's wrong with my code?

        • 1. Re: lookup-problem in a swing-client
          fbiaggi

          Hi,
          you may look in the jmx- or web-console to see the names of your deployed beans.
          Hope this helps.

          • 2. Re: lookup-problem in a swing-client

            Try changing it like this:

            Object ref = context.lookup("java:comp/env/ejb/Fibo");
            

            Note there is no '/' before 'comp'.

            • 3. Re: lookup-problem in a swing-client
              oliverroell

              Hello Andy and fbiaggi,

              thank you very much, you brought me on the right track.

              I have looked in the JMX-Console:

              Ejb Module: FiboEJB.jar
              java:comp namespace of the Fibo bean:
              +- env (class: org.jnp.interfaces.NamingContext)

              Global JNDI Namespace
              +- ejb (class: org.jnp.interfaces.NamingContext)
              | +- Fibo (proxy: $Proxy50 implements interface
              tutorial.interfaces.FiboHome,interface javax.ejb.Handle)

              The Fibo-Bean resides in the Global JNDI namespace, and not,
              like expected, in the java:comp namespace of the Fibo-Bean.

              I have changed my lookup like followed, and it works:

              Object ref = context.lookup("ejb/Fibo");

              But two questions remain:

              Why do the Fibo-Bean resides not in the java:comp namespace
              of the Fibo-Bean? I think, the reason has to do with the xml-files, but I am not sure.

              Why does the ComputeServlet-Class from the JBoss-Tutorial works with the following lookup:

              Object ref = context.lookup("java:/comp/env/ejb/Fibo");

              I have thought, if the Servlet works with lookup("java:/comp/env/ejb/Fibo"), the Swing-Client should work with this lookup, too. But my assumption was wrong. I don't understand, how the servlet can find the name java:/comp/env/ejb/Fibo, although nothing is bound with java:comp. That's strange, isn't it?

              Regards
              Oliver

              • 4. Re: lookup-problem in a swing-client

                I apologize for the confusion. I failed to recognize that you were doing this lookup from a Swing client.

                java:comp/env is a special naming context, the Environment Naming Context (ENC) for a J2EE component. It's only valid within the scope of a J2EE component, such as a servlet or EJB, which is why it works in the tutorial's servlet, and why you won't see it in the JMX console.

                The EJB reference gets mapped to the servlet's ENC (java:comp/env/ejb/Fibo) via an ejb-ref element in web.xml and an ejb-ref-jnid element in jboss-web.xml.

                • 5. Re: lookup-problem in a swing-client
                  oliverroell

                  Thank you very much for your clarification!

                  • 6. Re: lookup-problem in a swing-client
                    joegz1234

                    Could you please let me know how I can run your swing client ? Do I need to include it as part of tutorial project? And do I need to set any classpath?

                    Thanks.