You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jason Shim <aq...@gmail.com> on 2012/09/27 12:56:06 UTC

How can i set variables in the filter(bean)?

(Sorry for my poor english)

I'm working with file consumer.
I need to filter(bean style, #) files in file consumer.
And the filter has some variables.
How can i set variables in the filter?

I tested route like this
*
*
*from("file://somedir?move=done")*
*.process(new Processor()*
*{*
*    @Override*
*    public void process(Exchange exchange) throws Exception*
*    {*
*        exchange.setProperty("propKey", "propVal"); // used in
filter(myFilter)*
*    }*
*})*
*.filter().method("**myFilter**", "isAccept")*
*.to("bean:somebean");  *
*
*
But this case result that all file moved done directory whether filter
return true or false.
This is not my intention.

I want to process some files that accept some conditions and the other
files doesn't touch.

Supplement)
  Of course, i can set instance variables in the bean.
  But my application run multiple route(same consumer) and different
environment(filters, directories and condition),
  so instance variables is not accepted.

Please help.
Thank you.

Re: How can i set variables in the filter(bean)?

Posted by Christian Müller <ch...@gmail.com>.
These links could be helpful:
http://camel.apache.org/predicate.html
http://camel.apache.org/bean-language.html

Best,
Christian

On Thu, Sep 27, 2012 at 8:00 PM, Christian Müller <
christian.mueller@gmail.com> wrote:

> MyFilterBean myFilterBean = new MyFilterBean();
> myFilterBean.setXXX("...");
> ...
>
> from("xxx")
>   .filter().method(myFilterBean, "myFilterMethod")
>   .to("yyy");
>
> You can do it similar if you use Spring (or another IOC container).
>
> Best,
> Christian
>
>
> On Thu, Sep 27, 2012 at 12:56 PM, Jason Shim <aq...@gmail.com> wrote:
>
>> (Sorry for my poor english)
>>
>> I'm working with file consumer.
>> I need to filter(bean style, #) files in file consumer.
>> And the filter has some variables.
>> How can i set variables in the filter?
>>
>> I tested route like this
>> *
>> *
>> *from("file://somedir?move=done")*
>> *.process(new Processor()*
>> *{*
>> *    @Override*
>> *    public void process(Exchange exchange) throws Exception*
>> *    {*
>> *        exchange.setProperty("propKey", "propVal"); // used in
>> filter(myFilter)*
>> *    }*
>> *})*
>> *.filter().method("**myFilter**", "isAccept")*
>> *.to("bean:somebean");  *
>> *
>> *
>> But this case result that all file moved done directory whether filter
>> return true or false.
>> This is not my intention.
>>
>> I want to process some files that accept some conditions and the other
>> files doesn't touch.
>>
>> Supplement)
>>   Of course, i can set instance variables in the bean.
>>   But my application run multiple route(same consumer) and different
>> environment(filters, directories and condition),
>>   so instance variables is not accepted.
>>
>> Please help.
>> Thank you.
>>
>
>
>
> --
>
>
>


--

Re: How can i set variables in the filter(bean)?

Posted by Christian Müller <ch...@gmail.com>.
MyFilterBean myFilterBean = new MyFilterBean();
myFilterBean.setXXX("...");
...

from("xxx")
  .filter().method(myFilterBean, "myFilterMethod")
  .to("yyy");

You can do it similar if you use Spring (or another IOC container).

Best,
Christian

On Thu, Sep 27, 2012 at 12:56 PM, Jason Shim <aq...@gmail.com> wrote:

> (Sorry for my poor english)
>
> I'm working with file consumer.
> I need to filter(bean style, #) files in file consumer.
> And the filter has some variables.
> How can i set variables in the filter?
>
> I tested route like this
> *
> *
> *from("file://somedir?move=done")*
> *.process(new Processor()*
> *{*
> *    @Override*
> *    public void process(Exchange exchange) throws Exception*
> *    {*
> *        exchange.setProperty("propKey", "propVal"); // used in
> filter(myFilter)*
> *    }*
> *})*
> *.filter().method("**myFilter**", "isAccept")*
> *.to("bean:somebean");  *
> *
> *
> But this case result that all file moved done directory whether filter
> return true or false.
> This is not my intention.
>
> I want to process some files that accept some conditions and the other
> files doesn't touch.
>
> Supplement)
>   Of course, i can set instance variables in the bean.
>   But my application run multiple route(same consumer) and different
> environment(filters, directories and condition),
>   so instance variables is not accepted.
>
> Please help.
> Thank you.
>



--