You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by rhowlett <rh...@silverchalice.com> on 2011/12/15 08:25:27 UTC

.filter().method(...) does not modify Exchange

I wanted to do this:


from("direct:start")
  .filter().method("beanRefName", "methodName")
    .to("log:test?showAll=true&multiline=true")
.end();


The bean class would be pretty simple:


public class BeanName {

  public boolean methodName(@Body String body, Exchange exchange,
@OutHeaders Map<String, Object> outHeaders) {
    // some logic
    outHeaders.put("someKey", "someValue");
    return someBooleanValue;
  }

}


However, the out Message headers are never set and don't show up on the log
output. 

I had a look at the Bean Processor and I can see that the out message on the
referenced exchange has the new headers, but the in message's headers are
actually the ones being copied over.

Altering the injected Exchange object doesn't work either, nor does using
any kind of ExpressionDefinition with BeanLanguage.bean(...).

A basic beanRef works fine (the out headers are set on the exchange):


from("direct:start")
  .beanRef("beanRefName", "methodName")
  .to("log:test?showAll=true&multiline=true");


I wanted to use the bean like a Predicate and alter the injected
Exchange/Headers. Anyone have any ideas to do this?

--
View this message in context: http://camel.465427.n5.nabble.com/filter-method-does-not-modify-Exchange-tp5076735p5076735.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .filter().method(...) does not modify Exchange

Posted by rhowlett <rh...@silverchalice.com>.
Thanks Willem, I figured that was the case. In the end I did the following:


from("direct:start")
  .beanRef("beanRefName", "methodName") 
  .filter(property(BeanClass.SHOULD_FILTER).isEqualTo(true))
    ...
  .end();


--
View this message in context: http://camel.465427.n5.nabble.com/filter-method-does-not-modify-Exchange-tp5076735p5077148.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .filter().method(...) does not modify Exchange

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

The Predicate does not suppose to change the message.
And the bean expression only affect to out message body.

You can change the message header and body in processor or bean method.

On Thu Dec 15 15:25:27 2011, rhowlett wrote:
> I wanted to do this:
>
>
> from("direct:start")
>    .filter().method("beanRefName", "methodName")
>      .to("log:test?showAll=true&multiline=true")
> .end();
>
>
> The bean class would be pretty simple:
>
>
> public class BeanName {
>
>    public boolean methodName(@Body String body, Exchange exchange,
> @OutHeaders Map<String, Object>  outHeaders) {
>      // some logic
>      outHeaders.put("someKey", "someValue");
>      return someBooleanValue;
>    }
>
> }
>
>
> However, the out Message headers are never set and don't show up on the log
> output.
>
> I had a look at the Bean Processor and I can see that the out message on the
> referenced exchange has the new headers, but the in message's headers are
> actually the ones being copied over.
>
> Altering the injected Exchange object doesn't work either, nor does using
> any kind of ExpressionDefinition with BeanLanguage.bean(...).
>
> A basic beanRef works fine (the out headers are set on the exchange):
>
>
> from("direct:start")
>    .beanRef("beanRefName", "methodName")
>    .to("log:test?showAll=true&multiline=true");
>
>
> I wanted to use the bean like a Predicate and alter the injected
> Exchange/Headers. Anyone have any ideas to do this?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/filter-method-does-not-modify-Exchange-tp5076735p5076735.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang