0 Replies Latest reply on Apr 18, 2008 7:45 PM by 666705

    Why do I get a ClassCastException

    666705
      Hello!

      I'm playing around with axis2 at home.

      I have a small application arch around a database called names.
      This database consist of one table of names.

      To access the database I have developed a hibernate package called nameshibernate.jar

      I have also developed a ejb package that uses nameshibernate.jar, called namesejb_server.jar. And for any client to the ejb I got a namesejb_client.jar.
      This ejb is running within a weblogic manage server 8.1.6 (called manged_wls_ejb, port:7011)

      I have also developed a standalone Java application, namesjavaapplication.jar, that can access the database direct through nameshibernate.jar, and also through namesejb.jar (by using namesejb_client.jar).

      This works fine:

      namesjavaapplication.jar
      ->nameshibernate.jar
      ->->database

      namesjavaapplication.jar
      ->namesejb_client.jar
      ->->manged_wls_ejb_7011
      ->->->namesejb.jar
      ->->->->nameshibernate.jar
      ->->->->->database

      (Hope you understand my call/access hierarchy)


      Now I am trying to access it through a webservice, with axis2.
      My axis2 runs in an other weblogic manage server 8.1.6 (called manged_wls_webservice, port:7021)
      I have developed a package called nameswebservice.aar. And for any client to the webservice I got a nameswebservice_client.jar.

      The communicatio between the standalone Java application and the .aar works fine:
      namesjavaapplication.jar
      ->nameswebservice_client.jar
      ->->manged_wls_webservice_7021
      ->->->nameswebservice.aar

      But if I try to do it all the way like:

      namesjavaapplication.jar
      ->nameswebservice_client.jar
      ->->manged_wls_webservice_7021
      ->->->nameswebservice.aar
      ->->->->namesejb_client.jar
      ->->->->->manged_wls_ejb_7011
      ->->->->->->namesejb.jar
      ->->->->->->->nameshibernate.jar
      ->->->->->->->->database

      It seems to crash in my webservice layer:
      nameswebservice.aar

      I get this exception, and I can not figure out why, since the code to call the ejb is the same in namesjavaapplication.jar and in nameswebservice.aar.

      namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub
      namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub
      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:31)
      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)

      The code looks like:
              try
              {
                  System.out.println("addNameWSEJB start " + name);
                  Context context = getWebLogicInitialContext();
                
                  Object object1 = context.lookup("namesejb/client/NameManagerEJBHome");
                  System.out.println(object1.getClass().getName());
                
                  Object object2 = PortableRemoteObject.narrow(object1, Object.class);
                  System.out.println(object2.getClass().getName());

                  NameManagerEJBHome nameManagerEJBHome = (NameManagerEJBHome)PortableRemoteObject.narrow(object1, NameManagerEJBHome.class);
                  NameManangerEJBObject nameManangerEJBObject = nameManagerEJBHome.create();
                
                  nameManangerEJBObject.addName(name);
                
              }
      catch(Exception e)
      {
      e.printStackTrace();
      }

      To me it looks strange that the name of the class for the instances is:
      namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub

      So if any one got any ideas peleas let me know!

      Best regards
      Fredrik

      --
      Edited by fredand44 at 04/18/2008 12:44 PM

      --
      Edited by fredand44 at 04/18/2008 12:45 PM