// Blueprint referencing the OSGI service

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0";>

    <reference interface="com.test.api.Hello"/>
    <bean
        class="com.test.routes.HelloRoutes" id="routes"/>
    <camelContext id="hello-routes-service" 
xmlns="http://camel.apache.org/schema/blueprint";>
        <routeBuilder ref="routes"/>
    </camelContext>
</blueprint>

// Camel Java DSL

public class HelloRoutes extends RouteBuilder {


@Override
public void configure() throws Exception {

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

//Actual Error Trace

 ERROR [Blueprint Event Dispatcher: 1] Error occurred during starting 
CamelContext: hello-routes-service
org.apache.camel.FailedToCreateRouteException: Failed to create route route19 
at: >>> Bean[com.test.api.Hello] <<< in route: 
Route(route19)[[From[timer:foo?repeatCount=1]] -> [Bean[com.... because of 
org.apache.camel.component.bean.MethodNotFoundException: Static method with 
name: getGreeting not found on class: com.test.api.Hello
        at 
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1303) 
~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) 
~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1143)
 ~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3729)
 ~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3443)
 ~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:209)
 ~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3251) 
~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3247) 
~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3270)
 ~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3247)
 ~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3163) 
~[62:org.apache.camel.camel-core:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:255)
 ~[60:org.apache.camel.camel-blueprint:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:297)
 ~[60:org.apache.camel.camel-blueprint:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.camel.blueprint.BlueprintCamelContext.blueprintEvent(BlueprintCamelContext.java:188)
 [60:org.apache.camel.camel-blueprint:2.21.0.fuse-730078-redhat-00001]
        at 
org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:190)
 [51:org.apache.aries.blueprint.core:1.10.1]
        at 
org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:188)
 [51:org.apache.aries.blueprint.core:1.10.1]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
 [?:?]
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
 [?:?]
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
[?:?]
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
[?:?]
        at java.lang.Thread.run(Thread.java:745) [?:?]
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
        at 
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1830)
 ~[?:?]
        at 
org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:343) 
~[?:?]
        at 
org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:562)
 ~[?:?]
        at 
org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:523)
 ~[?:?]
        at 
org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:239)
 ~[?:?]
        at 
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1300) 
~[?:?]
        ... 26 more
Caused by: org.apache.camel.component.bean.MethodNotFoundException: Static 
method with name: getGreeting not found on class: com.test.api.Hello
        at 
org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:343) 
~[?:?]
        at 
org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:562)
 ~[?:?]
        at 
org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:523)
 ~[?:?]
        at 
org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:239)
 ~[?:?]
        at 
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1300) 
~[?:?]
        ... 26 more


________________________________
From: vignesh k
Sent: Friday, July 17, 2020 11:51 AM
To: users@camel.apache.org <users@camel.apache.org>
Subject: OSGI service Call using Camel route

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.


Reply via email to