5 Replies Latest reply on Feb 16, 2006 5:43 AM by gurrie09

    Session Bean Lookup Error

    gurrie09

      HiAll,

      I am trying to gettting a very simple application running, involving a stateless session bean and the client. I have managed to get the session bean deployed and it is running. My problem comes when I lookup the session bean from the client application. I get the following error.

      java.lang.ClassCastException: org.jnp.interfaces.NamingContext
      at com.gurrie.simple.client.SimpleSessionBeanClient.main(SimpleSessionBeanClient.java:14)
      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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


      The code for my client is as follows :

      public class SimpleSessionBeanClient {
      public static void main(String[] args) {
      try {
      InitialContext ctx = new InitialContext();
      SimpleSession simpleSession = (SimpleSession) ctx.lookup("SessionTest");

      for (int i = 0; i < args.length; i++) {
      String returnedString = simpleSession.echoString(args);
      System.out.println("sent string: " + args
      + ", received string: " + returnedString);
      }
      } catch (Throwable e) {
      e.printStackTrace();
      }
      }
      }

      My class path contains the following jars :

      C:\Program Files\jboss-4.0.4RC1\lib\concurrent.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\deploy\jboss-aop-jdk50.deployer\jboss-aop-jdk50.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\deploy\jboss-aop-jdk50.deployer\jboss-aspect-library-jdk50.jar
      C:\Program Files\jboss-4.0.4RC1\lib\jboss-common.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\deploy\ejb3.deployer\jboss-ejb3.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\deploy\ejb3.deployer\jboss-ejb3x.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\lib\jboss-remoting.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\lib\jboss-transaction.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\lib\jboss.jar
      C:\Program Files\jboss-4.0.4RC1\server\default\lib\jnpserver.jar

      Any help would be greatly appreciated!

      Regards,
      Brian

        • 1. Re: Session Bean Lookup Error
          jaikiran

           

          SimpleSession simpleSession = (SimpleSession) ctx.lookup("SessionTest");


          ctx.lookup will return you a local/remote home object. So your code should be something like:

          SimpleSessionRemoteHome simpleSessionHome = (SimpleSessionRemoteHome) ctx.lookup("SessionTest");


          or

          SimpleSessionLocalHome simpleSessionHome = (SimpleSessionLocalHome) ctx.lookup("SessionTest");


          and once you get hold of the home object, you will have to invoke:

          SimpleSession simpleSession = (SimpleSession) home.create();




          • 2. Re: Session Bean Lookup Error
            gurrie09

            Are you sure that is correct? This code is copied from a Javaworld article, on EJB 3?

            • 3. Re: Session Bean Lookup Error
              jaikiran

              Sorry, i wasnt aware you were using EJB3. Well, i havent worked with EJB3 so not sure why you are seeing the exception.

              • 4. Re: Session Bean Lookup Error
                jaikiran

                One of the easiest way to debug this, would be:

                Object simpleSession = ctx.lookup("SessionTest");
                System.out.println("Type of object : " + simpleSession.getClass().getName());


                This will help you in identifying the type of object that is being returned by the lookup() method.

                • 5. Re: Session Bean Lookup Error
                  gurrie09

                  No problem! Thanks for the reply.

                  The type being returned is org.jnp.interfaces.NamingContext?