Hi Have you seen this FAQ. http://camel.apache.org/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html
Also if you put the predicate inside the filter as a parameter then it helps the DSL as well. filter( xxxx ) instead of filter().xxxx() On Thu, Apr 19, 2012 at 7:06 PM, Xuan Huang <xuan.hu...@gamesys.co.uk> wrote: > Hi all, > > What I'm trying to do is to authenticate a message before sending it to be > processed using message filter, so I have something like > > .filter().method(MyAuthenticator.class, "isAuthenticated") > > However in my route builder, I also route the messages based on their types > using choice. So for example I have > > from(IN_QUEUE).choice() > .when(header(JMS_TYPE).isEqualTo("Type1")) > .to("bean:myBean?method=handleMessage") > .when(header(JMS_TYPE).isEqualTo("Type2")) > .to("bean:yourBean?method=handleMessage") > .otherwise().to("activemq:myqueue.in.DLQ") > .routeId("jms-my-route"); > > the filter seems to work when I put it before choice, like this > > from(IN_QUEUE) > ..filter().method(ClientAuthenticator.class, "isAuthenticated") > .choice() > .when(header(JMS_TYPE).isEqualTo("Type1")) > .to("bean:myBean?method=handleMessage") > .when(header(JMS_TYPE).isEqualTo("Type2")) > .to("bean:yourBean?method=handleMessage") > .otherwise().to("activemq:myqueue.in.DLQ") > .routeId("jms-my-route"); > > But I want to only authenticate Type1 messages, not Type2 messages. > > So I tried > > from(IN_QUEUE).choice() > .when(header(JMS_TYPE).isEqualTo("Type1")) > .filter().method(ClientAuthenticator.class, > "isAuthenticated") > .to("bean:myBean?method=handleMessage").end() > .when(header(JMS_TYPE).isEqualTo("Type2")) > .to("bean:yourBean?method=handleMessage") > .otherwise().to("activemq:myqueue.in.DLQ") > .routeId("jms-my-route"); > > But the second when clauses is not valid. > > Can I use filter inside when?If not, is there another solution? > > Thanks! > xuan > -- Claus Ibsen ----------------- CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/