0 Replies Latest reply on May 15, 2008 8:47 PM by 666705

    Why do I get a ClassCastException?

    666705
      Hello!

      I'm playing around with hibernate, axis2 and Weblogic 8.1.6 and I got I really tricky problem.

      My Weblogic 8.1.6 got consist of 3 servers.
      1 Adminserver (myserver)
      1 Managedserver (ejbserver)
      1 Managedserver (webserviceserver)

      My play_around_example is built around a database called names in a mysql-databas.

      To access data I got a package called nameshibernate.jar, that works fine used from an standalone application called namesjavaapplication.jar.
      (namesjavaapplication->nameshibernate->database)

      I also got an ejb in a packaged called namesejb.jar that uses the nameshibernate.jar. The namesejb.jar is deployed under "Ejb Modules" and the target is "ejbserver". If I call the ejb from my standalone application called namesjavaapplication.jar it works fine.
      (namesjavaapplication->namesejb->nameshibernate->database)

      I also got an webserviceapplication that uses axis2 in a aar-file called nameswebservice.aar. This application uses the namesejb.jar. The Axis2-server is deployed in the server under "Web Application Modules" and the target is "webserviceserver". In this Axis2-server the nameswebservice.aar is deployed. This i supposed to work like:
      (namesjavaapplication->nameswebservice->namesejb->nameshibernate->database)
      If I call the webservice from my standalone application called namesjavaapplication.jar I get a calsscast exception:
      java.lang.ClassCastException: Cannot narrow remote object to namesejb.client.NameManagerEJBHome

      I really can not find out the problem since it works fine if I go directly to the ejb like:
      (namesjavaapplication->namesejb->nameshibernate->database)


      ----------------------------------------------------------------------
      Below is the method inside my standalone application that calls the ejb directly.
      This is the code that works:
      (namesjavaapplication->namesejb->nameshibernate->database)
           public void getNamesEJB() throws Exception
           {
                try
                {
                     System.out.println("getNamesEJB start");
                     Context context = getWebLogicInitialContext();
                     
                     Object object = context.lookup("namesejb/client/NameManagerEJBHome");
                     
                     System.out.println("\t1: " + object.getClass().getName());
                     Class c = Class.forName("namesejb.client.NameManagerEJBHome");
                     System.out.println("\t2: " + c.getName());
                     System.out.println("\t3: " + NameManagerEJBHome.class.getName());
                     System.out.println("\t4: " + (object instanceof NameManagerEJBHome));
                     System.out.println("\tjava.class.version: " + System.getProperty("java.class.version"));
                     System.out.println("\tjava.class.path: " + System.getProperty("java.class.path"));
                     System.out.println("\tjava.library.path: " + System.getProperty("java.library.path"));
                     System.out.println("\tjava.compiler: " + System.getProperty("java.compiler"));
                     System.out.println("\tjava.ext.dirs: " + System.getProperty("java.ext.dirs"));
                     System.out.println("\tuser.dir: " + System.getProperty("user.dir"));
                     System.out.println("\tjava.home: " + System.getProperty("java.home"));
                     
                     if(object instanceof namesejb.server.NameManagerSessionBean)
                     {
                          System.out.println("\t"+ ((namesejb.server.NameManagerSessionBean)object).getSerialVersionUID() );
                     }
                     else
                     {
                          System.out.println("\tNOT instanceof NameManagerSessionBean");
                     }
                     
                     NameManagerEJBHome nameManagerEJBHome = (NameManagerEJBHome)PortableRemoteObject.narrow(object, NameManagerEJBHome.class);
                     NameManangerEJBObject nameManangerEJBObject = nameManagerEJBHome.create();
                     
           String nameString = "";
                     List names = nameManangerEJBObject.getNames();
           for (int i = 0; i < names.size(); i++)
           {
           Name theName = (Name) names.get(i);
           nameString = nameString + "\n" + theName.getName();
           }
           textAreaEJB.setText(nameString);

                }
                catch(RemoteException e)
                {
                     e.printStackTrace();
                }
                catch(NamingException e)
                {
                     e.printStackTrace();
                }
                catch(Exception e)
                {
                     e.printStackTrace();
                }
                
           }

      From this I get this output:

      getNamesEJB start
      1: namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub
      2: namesejb.client.NameManagerEJBHome
      3: namesejb.client.NameManagerEJBHome
      4: true
      java.class.version: 50.0
      java.class.path: namesjavaapplication.jar
      java.library.path: /home/fredrik/Applications/Java/Java_ee_sdk_5-04/jd k/jre/lib/i386/server:/home/fredrik/Applications/Java/Java_ee_sdk_5-04 /jdk/jre/lib/i386:/home/fredrik/Applications/Java/Java_ee_sdk_5-04/jdk /jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib

      java.compiler: null

      java.ext.dirs: /home/fredrik/Applications/Java/Java_ee_sdk_5-04/jdk/jr e/lib/ext:/usr/java/packages/lib/ext

      user.dir: /home/fredrik/eclipse_workspace/namesjavaapplication

      java.home: /home/fredrik/Applications/Java/Java_ee_sdk_5-04/jdk/jre
      NOT instanceof NameManagerSessionBean


      Below is my methods inside the ejb:
           public void ejbCreate()
           {
                try
                {
                     Class c = Class.forName("namesejb.client.NameManagerEJBHome");
                     System.out.println("1: " + c.getName());
                     System.out.println("2: " + NameManagerEJBHome.class.getName());
                     System.out.println("java.class.version: " + System.getProperty("java.class.version"));
                     System.out.println("java.class.path: " + System.getProperty("java.class.path"));
                     System.out.println("java.library.path: " + System.getProperty("java.library.path"));
                     System.out.println("java.compiler: " + System.getProperty("java.compiler"));
                     System.out.println("java.ext.dirs: " + System.getProperty("java.ext.dirs"));
                     System.out.println("user.dir: " + System.getProperty("user.dir"));

                }
                catch(Exception e)
                {
                     System.out.println(e.getMessage());
                     e.printStackTrace();
                }
           }

           public ArrayList getNames() throws Exception {
                Class c = Class.forName("namesejb.client.NameManagerEJBHome");
                System.out.println("4 " + c.getName());
                NameManager nameManager = new NameManager();
                return nameManager.getNames();
           }

      From these methods I get this output from the ejbserver:
      1: namesejb.client.NameManagerEJBHome
      2: namesejb.client.NameManagerEJBHome
      java.class.version: 48.0
      java.class.path:/home/fredrik/Applications/bea/jrockit81sp6_142_10/lib/tools.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic_sp.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic.jar::/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbserver44.jar:/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbclient44.jar:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/rt.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/webservices.jr:

      java.library.path:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386/jrockit:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/../lib/i386:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686/oci920_8

      java.compiler: null

      java.ext.dirs: /home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/ext

      user.dir: /home/fredrik/Applications/bea/user_projects/domains/mydomain

      4 namesejb.client.NameManagerEJBHome

      THIS WORKS FINE
      ---------------------------------------------------------
      Below is the method inside my webservice that calls the ejb directly.
      This is the code that throws the Exception:
      (namesjavaapplication->nameswebservice->namesejb->nameshibernate->database)

           public String getNamesWSEJB() throws Exception
           {
                String errorMessage = "Error: ";
                try
                {
                     System.out.println("getNamesWSEJB start");
                     Context context = getWebLogicInitialContext();
                     
                     Object object = context.lookup("namesejb/client/NameManagerEJBHome");
                     
                     System.out.println("\t1: " + object.getClass().getName());
                     Class c = Class.forName("namesejb.client.NameManagerEJBHome");
                     System.out.println("\t2: " + c.getName());
                     System.out.println("\t3: " + NameManagerEJBHome.class.getName());
                     System.out.println("\t4: " + (object instanceof NameManagerEJBHome));
                     System.out.println("\tjava.class.version: " + System.getProperty("java.class.version"));
                     System.out.println("\tjava.class.path: " + System.getProperty("java.class.path"));
                     System.out.println("\tjava.library.path: " + System.getProperty("java.library.path"));
                     System.out.println("\tjava.compiler: " + System.getProperty("java.compiler"));
                     System.out.println("\tjava.ext.dirs: " + System.getProperty("java.ext.dirs"));
                     System.out.println("\tuser.dir: " + System.getProperty("user.dir"));
                     System.out.println("java.home: " + System.getProperty("java.home"));
                     
                     if(object instanceof namesejb.server.NameManagerSessionBean)
                     {
                          System.out.println("\t"+ ((namesejb.server.NameManagerSessionBean)object).getSerialVersionUID() );
                     }
                     else
                     {
                          System.out.println("\tNOT instanceof NameManagerSessionBean");
                     }
                     
                     NameManagerEJBHome nameManagerEJBHome = (NameManagerEJBHome)PortableRemoteObject.narrow(object, NameManagerEJBHome.class);
                     NameManangerEJBObject nameManangerEJBObject = nameManagerEJBHome.create();
                     
           String nameString = "";
                     List names = nameManangerEJBObject.getNames();
                     for (int i = 0; i < names.size(); i++)
                     {
                          Name theName = (Name) names.get(i);
                          nameString = nameString + "\n" + theName.getName();
                     }
                     
                     return nameString;
                }
                catch(RemoteException e)
                {
                     errorMessage = errorMessage + e.getMessage();
                     e.printStackTrace();
                }
                catch(NamingException e)
                {
                     errorMessage = errorMessage + e.getMessage();
                     e.printStackTrace();
                }
                catch(Exception e)
                {
                     errorMessage = errorMessage + e.getMessage();
                     e.printStackTrace();
                }
                return errorMessage;
           }

      1: namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub
      2: namesejb.client.NameManagerEJBHome
      3: namesejb.client.NameManagerEJBHome
      4: false

      java.class.version: 48.0

      java.class.path:/home/fredrik/Applications/axis2-1.3/lib/jalopy-1.5rc3.jar:/home/fredrik/Applications/bea/jrockit81sp6_142_10/lib/tools.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic_sp.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic.jar::/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbserver44.jar:/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbclient44.jar:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/rt.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/webservices.jar:

      java.library.path: /home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386/jrockit:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/../lib/i386:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686/oci920_8

      java.compiler: null

      java.ext.dirs: /home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/ext

      user.dir: /home/fredrik/Applications/bea/user_projects/domains/mydomain

           NOT instanceof NameManagerSessionBean

      java.lang.ClassCastException: Cannot narrow remote object to namesejb.client.NameManagerEJBHome
      at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:242)
      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
      at nameswebservices.NamesWebService.getNamesWSEJB(NamesWebService.java:49)
      at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
              at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
              at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:165)
              at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:98)
              at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
              at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:96)
              at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:145)
              at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
              at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:120)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
              at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7047)
              at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
              at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
              at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
              at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
                                                                      


      I really can not find out what might be the problem since it works to call tje ejb from a standalone application.
      The "same" code executed from a webservice throws the exception.

      One strange thing that I notice is that from the standalone the java.class.version gets 50.0 and from the webserver it gets 48.0 But the standalone uses 1.6 when I run it and the Weblogic uses 1.4. (I do not think that weblogic can run with 1.6)

      Pretty long thread but I hope for some mercy!
      Best regards
      Fredrik