Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set message headers from a bean?

Tags:

apache-camel

I have a simple camel route I need to modify. The route looks like this:

from(source.uri)
    .unmarshal()
    .bean(TransformMessageBean.class, "SomeMethod")
    .to(destination.uri)

I want to add another bean method call after the unmarshaling that set's a header value without disrupting the current data flow . Does anyone know of a way to do this? I read that in apache's documentation that a bean's return value is set in the outbound message body. Is there a way to change that to a header?

Thanks in advance!

like image 647
David Avatar asked Nov 13 '14 22:11

David


3 Answers

Certainly! One of the options available is

.setHeader("headerName").method(beanInstance, "methodToGetHeaderValue")

Using this approach, the method (say, methodToGetHeaderValue) on the provided bean instance will return a value, and that will become the value of the header.

There are a number of options available. You can call it with a bean instance, a bean class (like in your example), or even a bean name, all with or without a method name.

like image 110
Ray Avatar answered Nov 17 '22 08:11

Ray


In Spring XML DSL, it would be something like

 <setHeader headerName="headerName">
      <method bean="mybean" method="mymethod" />                
</setHeader>
like image 41
Kimutai Avatar answered Nov 17 '22 10:11

Kimutai


Another way in XML:

<setHeader name="headerName"> 
    <simple>${bean:yourBean.getMethod}</simple>           
</setHeader>
like image 3
Justinas Jakavonis Avatar answered Nov 17 '22 10:11

Justinas Jakavonis