Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Annotation Based Expression

...

Language

You can also use any of the Languages supported in Camel to bind expressions to method parameters when using bean integration Bean Integration. For example you can use any of these annotations:

Annotation

Description

@Bean

Inject a Bean expression

@BeanShell

Inject a BeanShell expression

@Constant

Inject a Constant expression

@EL

Inject an EL expression

@Groovy

Inject a Groovy expression

@Header

Inject a Header expression

@JavaScript

Inject a JavaScript expression

@MVEL

Inject a MVEL expression

@OGNL

Inject an OGNL expression

@PHP

Inject a PHP expression

@Python

Inject a Python expression

@Ruby

Inject a Ruby expression

@Simple

Inject an Simple expression

@XPath

Inject an XPath expression

@XQuery

Inject an XQuery expression

Example:

Code Block
public class Foo {
	
    @MessageDriven(uri = "activemq:my.queue")
    public void doSomething(@XPath("/foo/bar/text()") String correlationID, @Body String body) {
		// process the inbound message here
    }
}

Advanced example using @Bean

And an example of using the the @Bean binding annotation, where you can use a POJO where you can do whatever java code you like:

...

Code Block
xml
xml
   <bean id="myCorrelationIdGenerator" class="com.mycompany.MyIdGenerator"/>
MySimpleIdGenerator"/>

Example using Groovy

In this example we have an Exchange that has a User object stored in the in header. This User object has methods to get some user information. We want to use Groovy to inject an expression that extracts and concats the fullname of the user into the fullName parameter.

Code Block

    public void doSomething(@Groovy("$request.header['user'].firstName $request.header['user'].familyName) String fullName, @Body String body) {
		// process the inbound message here
    }

Groovy supports GStrings that is like a template where we can insert $ placeholders that will be evaluated by Groovy.