Versions Compared

Key

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

...

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

Parameter binding

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

The following Camel specific types is automatic binded:

  • org.apache.camel.Exchange
  • org.apache.camel.Message
  • org.apache.camel.CamelContext
  • org.apache.camel.TypeConverter
  • org.apache.camel.spi.Registry
  • java.lang.Exception

So if you declare any of the given type above they will be provided by Camel. A note on the Exception is that it will bind to the caught exception of the Exchange. So its often usable if you use a POJO to handle a given using using eg an onException route.

What is most interresting is that Camel will also try to bind the body of the Exchange to the first parameter of the method signature (albeit not of any of the types above). So if we for instance declare e parameter as: String body then Camel will bind the IN body to this type. Camel will also automatic type convert to the given type declared.

Okay lets show some examples.

Below is just a simple method with a body binding. Camel will bind the IN body to the body parameter and convert it to a String type.

Code Block

public String doSomething(String body)

And in this sample we got one of the automatic binded type as well, for instance the Registry that we can use to lookup beans.

Code Block

public String doSomething(String body, Registry registry)

And we can also use Exchange as well:

Code Block

public String doSomething(String body, Exchange exchange)

You can have multiple types as well

Code Block

public String doSomething(String body, Exchange exchange, TypeConverter converter)

And imagine you use a POJO to handle a given custom exception InvalidOrderException then we can bind that as well:
Notice we can bind to it even if we use a sub type of java.lang.Exception as Camel still knows its an exception and thus can bind the caused exception (if any exists).

Code Block

public String badOrder(String body, InvalidOrderException invalid)

So what about headers and other stuff? Well now it gets a bit tricky so we can use annotations to help us. See next section for details.

Binding Annotations

You can use the Parameter Binding Annotations to customize how parameter values are created from the Message

...