Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • if the message contains the header CamelBeanMethodName (org.apache.camel.MethodName in Camel 1.x) then that method is invoked, converting the body to whatever the argument is to the method. From Camel 2.8 onwards you can qualify parameter types to exact pin-point which method to use when using overloaded methods with the same name.
  • the method name can be specified explicitly in the DSL or when using POJO Consuming
  • Camel 2.0: if the bean has a method that is marked with @Handler annotation then that method is selected
  • if the bean can be converted to a Processor using the Type Converter mechanism then this is used to process the message. This mechanism is used by the ActiveMQ component to allow any JMS MessageListener to be invoked directly by Camel without having to write any integration glue code. You can use the same mechanism to integrate Camel into any other messaging/remoting frameworks.
  • if the body of the message can be converted to a BeanInvocation (the default payload used by the ProxyHelper) - then that its used to invoke the method and pass the arguments
  • otherwise the type of the method body is used to try find a method which matches; an error is thrown if a single method cannot be chosen unambiguously.
  • you can also use Exchange as the parameter itself, but then the return type must be void.

...

By default the return value is set on the outbound message body.

Using type qualifier to pin-point method to use when having overloaded methods

Available as of Camel 2.8

If you have a Bean which has overloaded methods you can now specify the parameter types in the method name, so Camel can match the method you intend to use.
Given the following bean:

Wiki Markup
{snippet:id=e1|lang=java|title=MyBean|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadedMethodTest.java}

Then the MyBean has 2 overloaded methods with the names hello and times. So if we want to use the method which has 2 parameters we can do as follows in the Camel route:

Wiki Markup
{snippet:id=e2|lang=java|title=Invoke 2 parameter method|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadedMethodTest.java}

We can also use a * as wildcard so we can just say we want to execute the method with 2 parameters we do

Wiki Markup
{snippet:id=e2|lang=java|title=Invoke 2 parameter method using wildcard|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanOverloadedMethodTest.java}

By default Camel will match the type name using the simple name, eg any leading package name will be disregarded. However if you want to match using the FQN then specify the FQN type and Camel will leverage that. So if you have a com.foo.MyOrder and you want to match against the FQN, and not the simple name "MyOrder" then do as follows:

Code Block

   .bean(OrderService.class, "doSomething(com.foo.MyOrder)")

Parameter binding

When a method have been chosen to be invoked Camel will bind to the parameters of the method.

...