5 Replies Latest reply on Aug 7, 2009 9:27 AM by wolfgangknauf

    PortableRemoteObject.narrow classCastExceptin

    folal

      Hi have another problem during ejb3 remote recovery:

      Context ctx = new InitialContext();
      Object object = ctx.lookup("ServiceBean/remote");
      IService service = (IService) PortableRemoteObject.narrow(object, IService.class);

      Iservice is a local inteface
      IserviceRemote is a remote interface
      ServiceBean th bean that invoke

      The PortableRemoteObject.narrow raise a classCastExceptino!!!

        • 1. Re: PortableRemoteObject.narrow classCastExceptin
          wolfgangknauf

          Hi,

          use:

          IServiceRemote service = (IServiceRemote) PortableRemoteObject.narrow(object, IServiceRemote.class);
          

          to look up your remote interface.

          By the way: with JavaEE5, you don't need the "PortableRemoteObject.narrow" any more, a typecast works fine.

          Best regards

          Wolfgang


          • 2. Re: PortableRemoteObject.narrow classCastExceptin
            folal

            If I use:

            IServiceRemote service = (IServiceRemote) PortableRemoteObject.narrow(object, IServiceRemote.class);

            The error is the same!
            But if there is another method that recover ejb class....,
            I accept any suggetion.

            • 3. Re: PortableRemoteObject.narrow classCastExceptin
              wolfgangknauf

              Hi,

              please post the full exception message. Does your application client contain older/outdated versions of the bean interfaces? Does the client JBoss libraries match the exact version of the server?

              A simpler way is:

              IServiceRemote service = (IServiceRemote) ctx.lookup("ServiceBean/remote");
              

              But this should result in the same error for you...


              Best regards

              Wolfgang

              • 4. Re: PortableRemoteObject.narrow classCastExceptin
                folal

                So, first I use jboss-5.0.1.GA.

                >please post the full exception message

                java.lang.ClassCastException at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
                at javax.rmi.PortableRemoteObject.narrow(Unknown Source)at com.aminoweb.ejb3sample.test.ServiceTestCase.testMultiply(ServiceTestCase.java:32)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
                Caused by: java.lang.ClassCastException: javax.naming.Reference cannot be cast to org.omg.CORBA.Object
                ... 23 more


                >Does your application client contain older/outdated versions of the bean interfaces? NO, I have only the ServiceBean, see startup-log:

                ServiceBean/remote - EJB3.x Default Remote Business Interface
                ServiceBean/remote com.aminoweb.ejb3sample.business.IServiceRemote - EJB3.x Remote Business Interface
                ServiceBean/local - EJB3.x Default Local Business Interface
                ServiceBean/local-com.aminoweb.ejb3sample.business.IService - EJB3.x Local Business Interface

                >Does the client JBoss libraries match the exact version of the server?
                NO, I have some jboss-4.2.3.GA's class library, like:

                jboss-ejb3x.jar
                jboss-ejb3-client.jar

                • 5. Re: PortableRemoteObject.narrow classCastExceptin
                  wolfgangknauf

                  I think it is not possible to access a 5.x server with 4.2 client libraries.
                  There exists a JBoss compatibility matrix, but I don't find it currently, and I think it does not contain the 5.0 branch.

                  Best regards

                  Wolfgang