OSGI service Call using Camel route

classic Classic list List threaded Threaded
1 message Options
VKA
Reply | Threaded
Open this post in threaded view
|

OSGI service Call using Camel route

VKA
I get method not found exception when I try to connect/call OSGI service using camel route and I am not sure what logic I am missing here.


//Exception

    Caused by: org.apache.camel.RuntimeCamelException: org.apache.camel.component.bean.MethodNotFoundException: Static method with name: getGreeting not found on class: com.test.api.Hello


//The below is the blueprint that exports OSGI service

    <?xml version="1.0" encoding="UTF-8"?>
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
      <bean id="hello" class="com.test.HelloImpl"/>
      <service ref="hello" interface="com.test.api.Hello"/>
    </blueprint>


// Below is Java Interface and I did not include the java implementation code for interface here. but FYI, all method and class are declared as public

    package com.test.api;
    public interface Hello {
     public String getGreeting();
    }


//This below timer route is in Java DSL that is called by the route builder ref in the camel context and this camel context is defined inside blueprint

   from("timer:foo?repeatCount=1")
     .bean(com.test.api.Hello.class, "getGreeting")
     .log("The message contains: ${body}")





I got the same exception when I tried executing this route in the same bundle where I export interface service and also I tried executing this timer route in another separate bundle by referencing the exported OSGI interface.


If the method has to be made declared static then this below code snippet should throw the same exception but I get good response.
 //Inside the routeBuilder
               from("timer:foo?repeatCount=1")
                       .bean(HelloCamel.class,"doHandle")
                       .log("The message contains: ${body}")

 //Bean
           package com.test.handler;
            public class HelloCamel{
                          public String doHandle(){
                                        return "HelloWorld";
                          }

            }


I am testing all these routes and logic with the fuse server.