Thanks JB, when the OSGI service invoked from XML DSL it worked and I got good 
response and I am not sure what I missed when I invoke OSGI service from java 
DSL.

//Blueprint with camel XML DSL
<?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";>
        <route id="_route1">
            <from id="_from1" uri="timer:foo?repeatCount=1"/>
            <setBody id="_setBody1">
                <method method="getGreeting" ref="com.test.api.Hello"/>
            </setBody>
            <log id="_log1" message="The message contains: ${body}"/>
        </route>
    </camelContext>
</blueprint>

//output
09:26:10.666 INFO [Blueprint Event Dispatcher: 1] Apache Camel 
2.21.0.fuse-730078-redhat-00001 (CamelContext: hello-routes-service) started in 
0.080 seconds
09:26:11.594 INFO [Camel (hello-routes-service) thread #8 - timer://foo] The 
message contains: OSGI Service successfully called by Camel route!!

Thanks,
VKA

________________________________

Hi,

Did you try to use # for bean ref ? I’m not sure it will work mixing blueprint 
and Java DSL, I’m pretty sure it works fully in blueprint.

Regards
JB

> Le 19 juil. 2020 à 21:30, vignesh k <[hidden 
> email]</user/SendEmail.jtp?type=node&node=5875497&i=0>> a écrit :
>
>
> // 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: [hidden email]</user/SendEmail.jtp?type=node&node=5875497&i=1> <[hidden 
> email]</user/SendEmail.jtp?type=node&node=5875497&i=2>>
> 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.
>
>



________________________________
If you reply to this email, your message will be added to the discussion below:
https://camel.465427.n5.nabble.com/Re-OSGI-service-Call-using-Camel-route-tp5875391p5875497.html
To unsubscribe from Camel, click 
here<https://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465427&code=dmthXzAwOUBvdXRsb29rLmNvbXw0NjU0Mjd8Mzc1MDE3NTkw>.
NAML<https://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>

Reply via email to