6 Replies Latest reply on Apr 19, 2011 4:07 AM by Claus Ibsen

    ClassCastException with RmiEndpoint

    Ben Clark Newbie

      Hello everyone!

       

      I have (again) a problem with Camel...

      I'm trying to make a RmiEndpoint, so I'm coding this:

       

      Class c = Class.forName("HelloInterface");

      RmiEndpoint hello = (RmiEndpoint) endpoint("rmi://localhost:1099/Hello1");

      hello.setRemoteInterfaces(c);

      from("direct:hello").

      to(hello);

       

      I took this code from the official documentation.

      The compilation is Ok. During the execution the introspection (forName()) also is Ok but I have an another problem when my component is added to the list:

       

      java.lang.ClassCastException:

      org.apache.camel.component.rmi.RmiEndpoint cannot be cast to org.apache.camel.component.rmi.RmiEndpoint

       

      It's a little bit ironic.. so I thought it was a version problem. So I took the Jar from my Maven local repository and I deployed it on Servicemix. But the problems still persisting!

      I really can't see where the problem come from

       

      Thanks in advance!

        • 1. Re: ClassCastException with RmiEndpoint
          Claus Ibsen Master

          Hi

           

          Avoid using Class.forName to load the interface as you are not in control of the classloader.

           

          And hence why you see the weird class cast exception. But in reality the interface has been loaded by 2 different classloaders and thus it can't be casted.

           

          Try doing something like this instead:

          hello.setRemoteInterfaces(HelloInterface.class);

          • 2. Re: ClassCastException with RmiEndpoint
            Ben Clark Newbie

            Ok I see, but if i do that, maven at the compilation-time don't found my interface..

            How can I add my interface to RouteBuilder?

             

            I have this architecture:

             

            org

            |__a -> MyRouteBuilder.java

            |__b -> HelloInterface.java

             

            And an "import org.b.HelloInterface;" doesn't work..

             

            Edit: I have to add my HelloInterface to the ressources directory

             

            Edited by: manta7 on Apr 18, 2011 8:58 AM

            • 3. Re: ClassCastException with RmiEndpoint
              Ben Clark Newbie

              I didn't work

               

              Even with the hello.setRemoteInterfaces(HelloInterface.class); way..

              I still have the same exception!

              • 4. Re: ClassCastException with RmiEndpoint
                Ben Clark Newbie

                Finally I used this:

                 

                to("rmi://localhost:1099/Hello1?remoteInterfaces=org.xx.HelloInterface");

                 

                And I think it's working because it pass the compilation and the deployment time..

                But now during the execution of my workflow, I have this error:

                 

                Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.rmi.Remote but has value: B@715cb7 of type: byte[] on: Message:[B@715cb7.

                Caused by: No type converter available to convert from type: byte[] to the required type: java.rmi.Remote with value B@715cb7. ExchangeMessage: B@715cb7.

                Caused by: org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: byte[] to the required type: java.rmi.Remote with value B@715cb7

                 

                Do I need a converter ?...

                 

                Edited by: manta7 on Apr 18, 2011 12:58 PM

                 

                Edited by: manta7 on Apr 18, 2011 12:59 PM

                • 5. Re: ClassCastException with RmiEndpoint
                  Ben Clark Newbie

                  My workflow is the following:

                   

                  from(Queue).

                  bean(Bean.class, "processExchange").

                  convertBodyTo(String.class, "UTF-8").

                  enrich("direct:hello").

                  to(ExchangePattern.InOut, "jbi:endpoint:service:endpoint");

                   

                  And my direct:hello

                   

                  from("direct:hello").

                  to("rmi://localhost:1099/Hello1?remoteInterfaces=HelloInterface");

                   

                  And I have this exception:

                  No type converter available to convert from type: java.lang.String to the required type: java.rmi.Remote

                   

                  :(...

                  • 6. Re: ClassCastException with RmiEndpoint
                    Claus Ibsen Master

                    What version of Camel are you using?

                     

                    And what's the method signature of your hello interface?