Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-15793

MethodNotFoundException when calling method on OSGi service reference in Blueprint

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.5.0, 3.4.4, 3.6.0
    • Fix Version/s: 3.4.5, 3.7.0
    • Component/s: karaf, osgi
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      Camel throws an exception when trying to call a method on an OSGi service reference in Blueprint. For example:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
        <reference id="helloWorldServiceRef" interface="com.example.HelloWorldService"/>
        <camelContext xmlns="http://camel.apache.org/schema/blueprint" id="simple">
          <route>
            <from uri="timer:simple?period=5000"/>
            <setBody>
              <method ref="helloWorldServiceRef" method="greet()"/>
            </setBody>
            <to uri="log:simplecamel"/>
          </route>
        </camelContext>
      </blueprint>
      

      Here's the exception thrown:

      org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> SetBody[bean[ref:helloWorldServiceRef method:greet()]] <<< in route: Route(route1)[From[timer:simple?period=5000] -> [SetBody[bea... because of Method with name: greet() not found on bean: com.example.HelloWorldServiceImpl@604598c3 of type: Proxy7236e8f2_c140_49c7_a040_ac2eddfcda95
      	at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:384) ~[?:?]
      	at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:111) ~[?:?]
      	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:431) ~[?:?]
      	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:393) ~[?:?]
      	at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2606) ~[!/:3.6.0]
      	at org.apache.camel.support.service.BaseService.init(BaseService.java:83) ~[!/:3.6.0]
      	at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2378) ~[!/:3.6.0]
      	at org.apache.camel.support.service.BaseService.start(BaseService.java:111) ~[!/:3.6.0]
      	at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2395) ~[!/:3.6.0]
      	at org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:241) ~[!/:3.6.0]
      	at org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:283) ~[!/:3.6.0]
      	at org.apache.camel.blueprint.BlueprintCamelContext.blueprintEvent(BlueprintCamelContext.java:187) [!/:3.6.0]
      	at org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:190) [!/:1.10.2]
      	at org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:188) [!/:1.10.2]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_242]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_242]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_242]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_242]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_242]
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_242]
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_242]
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_242]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_242]
      	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_242]
      Caused by: org.apache.camel.component.bean.MethodNotFoundException: Method with name: greet() not found on bean: com.example.HelloWorldServiceImpl@604598c3 of type: Proxy7236e8f2_c140_49c7_a040_ac2eddfcda95
      	at org.apache.camel.language.bean.BeanExpression.validateHasMethod(BeanExpression.java:268) ~[?:?]
      	at org.apache.camel.language.bean.BeanExpression.init(BeanExpression.java:164) ~[?:?]
      	at org.apache.camel.language.bean.BeanLanguage.createExpression(BeanLanguage.java:173) ~[?:?]
      	at org.apache.camel.reifier.language.MethodCallExpressionReifier.createExpression(MethodCallExpressionReifier.java:57) ~[?:?]
      	at org.apache.camel.reifier.language.ExpressionReifier.createExpression(ExpressionReifier.java:135) ~[?:?]
      	at org.apache.camel.reifier.AbstractReifier.createExpression(AbstractReifier.java:113) ~[?:?]
      	at org.apache.camel.reifier.SetBodyReifier.createProcessor(SetBodyReifier.java:34) ~[?:?]
      	at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:752) ~[?:?]
      	at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:495) ~[?:?]
      	at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:382) ~[?:?]
      	... 23 more
      

      This bug was introduced by this change: https://github.com/apache/camel/commit/47d8ff92de888d923a7f3734080aa5a6d3d5bbcc#diff-d57c2c1fc8e674a5764e3fbe2cdc565dc12ca07541b9d6a2d9345f6c46a3d2e5R97-R107

      The service reference has a class of Proxy7236e8f2_c140_49c7_a040_ac2eddfcda95 (see the stack trace), which is a synthetic class, so the type for the BeanInfo is set to its superclass, which in this case is java.lang.Object.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                davsclaus Claus Ibsen
                Reporter:
                joshua.smith Josh Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: