You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mark Doyle <ma...@googlemail.com> on 2011/04/23 14:38:52 UTC

Problem dynamically filtering a route using a bean via camel:method

Hi all,
I'm having a little trouble with a dynamically filtered route.
My route is defined in Spring as follows:
<!--The came route used to retrieve packets for the gui. Can be altered -->
    <camelContext id="camelContextBean"
xmlns="http://camel.apache.org/schema/spring">
        <route id="fromJmsProcessedParametersOut" autoStartup="false">
            <from uri="jms:topic:processedParametersOut" />
                <camel:filter>
                    <camel:method bean="parameterFilterer"></camel:method>
                </camel:filter>
            <to uri="bean:camelParameterProvider?method=parameterIn" />
        </route>
    </camelContext>

The filter bean has a method called matches which is being called by
camel. The method is as follows:

public final boolean matches(@Header("ParameterName") final String
headerParameterName) {
    boolean result = false;

    if (this.parameterNames == null) {
        result = true;
    }
    else if (parameterNames.size() > 0) {
        for (String parameterName : parameterNames) {
            System.out.println(parameterName + " : " + headerParameterName);
            // if the filter name matches the parameter in this message header
            if (StringUtils.equals(parameterName, headerParameterName)) {
                System.out.println("Filter match for " + parameterName
+ " : " + headerParameterName);
                result = true;
            }
        }
    }

    System.out.println("Returning " + result);
    return result;
}


Now, according to the System outs the returns are correct. If I change
the parameterNames Set at runtime the filter processes the list and
returns the correct true or false flag. The problem is that Camel
still routes every message.

Can anybody see any reason why this design will not work or whether
I've missed something in implementing it.

Thanks!

Re: Problem dynamically filtering a route using a bean via camel:method

Posted by Willem Jiang <wi...@gmail.com>.
+1, this is an important feature for the new rider of camel :)

On 4/23/11 11:26 PM, Claus Ibsen wrote:
> We might wanna add a check in the filter eip that it has child
> processors. So it would fail starting in this case. We do have that
> for some of the other eips
>
> On Saturday, April 23, 2011, Mark Doyle<ma...@googlemail.com>  wrote:
>> Argh! So simple :D
>>
>> Thanks, Ben, worked perfectly.
>>
>> On 23 April 2011 15:46, Ben O'Day<be...@initekconsulting.com>  wrote:
>>> put the<to>  before the closing</filter>  tag...
>>>
>>> _______________
>>> Ben O'Day
>>>
>>> On Apr 23, 2011, at 5:39 AM, Mark Doyle<ma...@googlemail.com>  wrote:
>>>
>>>> Hi all,
>>>> I'm having a little trouble with a dynamically filtered route.
>>>> My route is defined in Spring as follows:
>>>> <!--The came route used to retrieve packets for the gui. Can be altered -->
>>>>      <camelContext id="camelContextBean"
>>>> xmlns="http://camel.apache.org/schema/spring">
>>>>          <route id="fromJmsProcessedParametersOut" autoStartup="false">
>>>>              <from uri="jms:topic:processedParametersOut" />
>>>>                  <camel:filter>
>>>>                      <camel:method bean="parameterFilterer"></camel:method>
>>>>                  </camel:filter>
>>>>              <to uri="bean:camelParameterProvider?method=parameterIn" />
>>>>          </route>
>>>>      </camelContext>
>>>>
>>>> The filter bean has a method called matches which is being called by
>>>> camel. The method is as follows:
>>>>
>>>> public final boolean matches(@Header("ParameterName") final String
>>>> headerParameterName) {
>>>>     boolean result = false;
>>>>
>>>>     if (this.parameterNames == null) {
>>>>         result = true;
>>>>     }
>>>>     else if (parameterNames.size()>  0) {
>>>>         for (String parameterName : parameterNames) {
>>>>             System.out.println(parameterName + " : " + headerParameterName);
>>>>             // if the filter name matches the parameter in this message header
>>>>             if (StringUtils.equals(parameterName, headerParameterName)) {
>>>>                 System.out.println("Filter match for " + parameterName
>>>> + " : " + headerParameterName);
>>>>                 result = true;
>>>>             }
>>>>         }
>>>>     }
>>>>
>>>>     System.out.println("Returning " + result);
>>>>     return result;
>>>> }
>>>>
>>>>
>>>> Now, according to the System outs the returns are correct. If I change
>>>> the parameterNames Set at runtime the filter processes the list and
>>>> returns the correct true or false flag. The problem is that Camel
>>>> still routes every message.
>>>>
>>>> Can anybody see any reason why this design will not work or whether
>>>> I've missed something in implementing it.
>>>>
>>>> Thanks!
>>>
>>
>


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

Connect at CamelOne May 24-26
The Open Source Integration Conference
http://camelone.com

Re: Problem dynamically filtering a route using a bean via camel:method

Posted by Claus Ibsen <cl...@gmail.com>.
We might wanna add a check in the filter eip that it has child
processors. So it would fail starting in this case. We do have that
for some of the other eips

On Saturday, April 23, 2011, Mark Doyle <ma...@googlemail.com> wrote:
> Argh! So simple :D
>
> Thanks, Ben, worked perfectly.
>
> On 23 April 2011 15:46, Ben O'Day <be...@initekconsulting.com> wrote:
>> put the <to> before the closing </filter> tag...
>>
>> _______________
>> Ben O'Day
>>
>> On Apr 23, 2011, at 5:39 AM, Mark Doyle <ma...@googlemail.com> wrote:
>>
>>> Hi all,
>>> I'm having a little trouble with a dynamically filtered route.
>>> My route is defined in Spring as follows:
>>> <!--The came route used to retrieve packets for the gui. Can be altered -->
>>>     <camelContext id="camelContextBean"
>>> xmlns="http://camel.apache.org/schema/spring">
>>>         <route id="fromJmsProcessedParametersOut" autoStartup="false">
>>>             <from uri="jms:topic:processedParametersOut" />
>>>                 <camel:filter>
>>>                     <camel:method bean="parameterFilterer"></camel:method>
>>>                 </camel:filter>
>>>             <to uri="bean:camelParameterProvider?method=parameterIn" />
>>>         </route>
>>>     </camelContext>
>>>
>>> The filter bean has a method called matches which is being called by
>>> camel. The method is as follows:
>>>
>>> public final boolean matches(@Header("ParameterName") final String
>>> headerParameterName) {
>>>    boolean result = false;
>>>
>>>    if (this.parameterNames == null) {
>>>        result = true;
>>>    }
>>>    else if (parameterNames.size() > 0) {
>>>        for (String parameterName : parameterNames) {
>>>            System.out.println(parameterName + " : " + headerParameterName);
>>>            // if the filter name matches the parameter in this message header
>>>            if (StringUtils.equals(parameterName, headerParameterName)) {
>>>                System.out.println("Filter match for " + parameterName
>>> + " : " + headerParameterName);
>>>                result = true;
>>>            }
>>>        }
>>>    }
>>>
>>>    System.out.println("Returning " + result);
>>>    return result;
>>> }
>>>
>>>
>>> Now, according to the System outs the returns are correct. If I change
>>> the parameterNames Set at runtime the filter processes the list and
>>> returns the correct true or false flag. The problem is that Camel
>>> still routes every message.
>>>
>>> Can anybody see any reason why this design will not work or whether
>>> I've missed something in implementing it.
>>>
>>> Thanks!
>>
>

-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Problem dynamically filtering a route using a bean via camel:method

Posted by Mark Doyle <ma...@googlemail.com>.
Argh! So simple :D

Thanks, Ben, worked perfectly.

On 23 April 2011 15:46, Ben O'Day <be...@initekconsulting.com> wrote:
> put the <to> before the closing </filter> tag...
>
> _______________
> Ben O'Day
>
> On Apr 23, 2011, at 5:39 AM, Mark Doyle <ma...@googlemail.com> wrote:
>
>> Hi all,
>> I'm having a little trouble with a dynamically filtered route.
>> My route is defined in Spring as follows:
>> <!--The came route used to retrieve packets for the gui. Can be altered -->
>>     <camelContext id="camelContextBean"
>> xmlns="http://camel.apache.org/schema/spring">
>>         <route id="fromJmsProcessedParametersOut" autoStartup="false">
>>             <from uri="jms:topic:processedParametersOut" />
>>                 <camel:filter>
>>                     <camel:method bean="parameterFilterer"></camel:method>
>>                 </camel:filter>
>>             <to uri="bean:camelParameterProvider?method=parameterIn" />
>>         </route>
>>     </camelContext>
>>
>> The filter bean has a method called matches which is being called by
>> camel. The method is as follows:
>>
>> public final boolean matches(@Header("ParameterName") final String
>> headerParameterName) {
>>    boolean result = false;
>>
>>    if (this.parameterNames == null) {
>>        result = true;
>>    }
>>    else if (parameterNames.size() > 0) {
>>        for (String parameterName : parameterNames) {
>>            System.out.println(parameterName + " : " + headerParameterName);
>>            // if the filter name matches the parameter in this message header
>>            if (StringUtils.equals(parameterName, headerParameterName)) {
>>                System.out.println("Filter match for " + parameterName
>> + " : " + headerParameterName);
>>                result = true;
>>            }
>>        }
>>    }
>>
>>    System.out.println("Returning " + result);
>>    return result;
>> }
>>
>>
>> Now, according to the System outs the returns are correct. If I change
>> the parameterNames Set at runtime the filter processes the list and
>> returns the correct true or false flag. The problem is that Camel
>> still routes every message.
>>
>> Can anybody see any reason why this design will not work or whether
>> I've missed something in implementing it.
>>
>> Thanks!
>

Re: Problem dynamically filtering a route using a bean via camel:method

Posted by Ben O'Day <be...@initekconsulting.com>.
put the <to> before the closing </filter> tag...

_______________
Ben O'Day

On Apr 23, 2011, at 5:39 AM, Mark Doyle <ma...@googlemail.com> wrote:

> Hi all,
> I'm having a little trouble with a dynamically filtered route.
> My route is defined in Spring as follows:
> <!--The came route used to retrieve packets for the gui. Can be altered -->
>     <camelContext id="camelContextBean"
> xmlns="http://camel.apache.org/schema/spring">
>         <route id="fromJmsProcessedParametersOut" autoStartup="false">
>             <from uri="jms:topic:processedParametersOut" />
>                 <camel:filter>
>                     <camel:method bean="parameterFilterer"></camel:method>
>                 </camel:filter>
>             <to uri="bean:camelParameterProvider?method=parameterIn" />
>         </route>
>     </camelContext>
>
> The filter bean has a method called matches which is being called by
> camel. The method is as follows:
>
> public final boolean matches(@Header("ParameterName") final String
> headerParameterName) {
>    boolean result = false;
>
>    if (this.parameterNames == null) {
>        result = true;
>    }
>    else if (parameterNames.size() > 0) {
>        for (String parameterName : parameterNames) {
>            System.out.println(parameterName + " : " + headerParameterName);
>            // if the filter name matches the parameter in this message header
>            if (StringUtils.equals(parameterName, headerParameterName)) {
>                System.out.println("Filter match for " + parameterName
> + " : " + headerParameterName);
>                result = true;
>            }
>        }
>    }
>
>    System.out.println("Returning " + result);
>    return result;
> }
>
>
> Now, according to the System outs the returns are correct. If I change
> the parameterNames Set at runtime the filter processes the list and
> returns the correct true or false flag. The problem is that Camel
> still routes every message.
>
> Can anybody see any reason why this design will not work or whether
> I've missed something in implementing it.
>
> Thanks!