3 Replies Latest reply on Mar 14, 2007 2:58 PM by alrubinger

    JNDI and Client Application

    gazzarda

      Hello,

      ( I can't seem to find an answer to following question. Please bare with me. )

      I am trying to run a client application at the command line to connect to a deployed stateless bean.

      I have complied a SimpleSession ( a remote interface ) and SimpleSessionBean ( a stateless bean that implements SimpleSession ).
      I have complied both the interface and the bean and created a jar file with the following command:

      "jar cf SimpleSessionApp.ejb3 beans\*.java"

      I then placed the jar file in the deploy directory.

      I have created a client application with the following code:

      package client;

      import beans.SimpleSession;
      import javax.naming.InitialContext;

      public class SimpleSessionClient {
      public static void main( String args[] ) throws Exception {
      InitialContext ctx = new InitialContext();
      SimpleSession simpleSession = ( SimpleSession )ctx.lookup( "beans/SimpleSession/remote" );
      for( int i = 0; i < args.length; i++ ) {
      String returnedString = simpleSession.sendMessage( args[ i ] );
      System.out.println( "sent string: " + args[ i ] + ", received string: " + returnedString );
      }
      }
      }
      ~
      I then compiled the code and tried running it at the command line with the following command:

      "java -Djava.naming.factory.initial=org.jnp.interfaces.
      NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url
      =localhost client.SimpleSessionClient Now is the time for all good men"

      I get the following error:

      Exception in thread "main" javax.naming.NameNotFoundException: beans not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
      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:466)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
      at java.lang.Thread.run(Thread.java:595)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
      at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
      at sun.rmi.server.UnicastRef.invoke(Unknown Source)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at client.SimpleSessionClient.main(SimpleSessionClient.java:9)

        • 1. Re: JNDI and Client Application
          alexg79

          First of all, when you ask for help, enclose your code with the "code" tag (use the buttons provided).
          Next, package your session beans in a .jar file. The .ejb3 extension is deprecated.
          Third, the correct JNDI path is //(remote|local).
          Just because you packaged your beans in a directory named "beans" doesn't mean it has anything to do with JNDI bindings. Session beans are usually part of some application, and (afaik) the application name dictates the default binding for them.
          You can find out if your beans were deployed correctly by checking the JNDI browser in the JMX console of JBoss.
          There are plenty of examples regarding this -- try out some of them before asking for help here.

          • 2. Re: JNDI and Client Application
            mleaning

             

            "alexg79" wrote:
            There are plenty of examples regarding this -- try out some of them before asking for help here.


            You could describe where to find the examples...


            • 3. Re: JNDI and Client Application
              alrubinger

              The TrailBlazer http://trailblazer.demo.jboss.com/EJB3Trail/ is usually a pretty good start. :)

              S,
              ALR