Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 77404 invoked from network); 12 Apr 2010 22:31:06 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 12 Apr 2010 22:31:06 -0000 Received: (qmail 30621 invoked by uid 500); 12 Apr 2010 22:31:06 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 30595 invoked by uid 500); 12 Apr 2010 22:31:06 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 30587 invoked by uid 99); 12 Apr 2010 22:31:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Apr 2010 22:31:06 +0000 X-ASF-Spam-Status: No, hits=1.7 required=10.0 tests=AWL,FREEMAIL_FROM,HTML_MESSAGE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jessesanford@gmail.com designates 74.125.83.173 as permitted sender) Received: from [74.125.83.173] (HELO mail-pv0-f173.google.com) (74.125.83.173) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Apr 2010 22:31:01 +0000 Received: by pvd12 with SMTP id 12so2371818pvd.32 for ; Mon, 12 Apr 2010 15:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:received:message-id:subject:to:content-type; bh=pS8Mv9vCKaSERSaz9slTzKVBAPwc2ZrNzv+8glwBtFY=; b=vd6TYiENM2evP7x7XoGQ+iTPfxKrixSZ9HcXxNkXInEjg/ufNug4OG4kBHAdPN/Kdy ESPJ9rtYWmNVMj4mevRYuUEgKfGWOI2zoQA7Hpe6odqI9fxS930dVWX2TGXGLEU4U/Gu tWIUd4S3TjtWDNyAzvzVtOBCWgLcDH4NRdlAA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=WDXixMkcc1I/k45Q11yY6qOf9Ndl7y3rOTT9TcHHRU5Tb5SvjGf7CQ2Nh+k/nTaC5+ 7rZtmZhwQ0dSLJ7zFj+KsAGAckdeqMLP5n8E9o4zB/YrOtOoNkvWsxXrCRLgU3EmpjQa WHstMw04Yj+hGelZ3DxBjFDaFDRFs6/BaRDvs= MIME-Version: 1.0 Received: by 10.143.19.6 with HTTP; Mon, 12 Apr 2010 15:30:21 -0700 (PDT) In-Reply-To: References: From: Jesse Sanford Date: Mon, 12 Apr 2010 18:30:21 -0400 Received: by 10.142.66.5 with SMTP id o5mr2208375wfa.159.1271111441116; Mon, 12 Apr 2010 15:30:41 -0700 (PDT) Message-ID: Subject: Re: need help with interceptor in camel 1.6.2 using custom predicate To: users@camel.apache.org Content-Type: multipart/alternative; boundary=001636e909e6eaefa2048411b163 --001636e909e6eaefa2048411b163 Content-Type: text/plain; charset=ISO-8859-1 FYI Here is my routeConfigurator class. You can see from the commented out sections in the configure method that I have tried a lot of different dsl configurations. public class commentRoute extends RouteBuilder { private Predicate commentFilter; @Override public void configure(){ //intercept().when(isBlacklisted()).to("log:comment").stop(); //intercept().to("log:comment").stop(); //from("comment-queue").to("comment-catcher"); //from("comment-queue").filter(commentFilter).to("comment-catcher"); errorHandler( deadLetterChannel("jms:queue:incoming.deadletterqueue"). delayPattern("20s"). maximumRedeliveries(5) ); from("comment-queue"). choice().when(commentFilter).to("comment-catcher"). otherwise().to("jms:queue:incoming.invalid"); } /** * Your standard getter * @return the commentFilter */ public Predicate getCommentFilter() { return commentFilter; } /** * Your standard setter * @param commentFilter the commentFilter to set */ public void setCommentFilter(Predicate commentFilter) { this.commentFilter = commentFilter; } private Predicate isBlacklisted(){ return new Predicate(){ public boolean matches(Exchange exchange) { String email = exchange.getIn().getBody(Comment.class).getEmail(); if(email.equalsIgnoreCase("jessesanford@gmail.com")) { return true; } else { return false; } } }; } } On Mon, Apr 12, 2010 at 6:28 PM, Jesse Sanford wrote: > Claus, Thanks for your help. Of course you deserve the kudos! > > I tried the filter method that you described with 1.6.2 and I also upgraded > to 2.2 and tried again with interceptors and also with choice().when() > > What I am finding is this. When I use the custom predicate: > > public class commentFilter implements Predicate { > public static final Log log = LogFactory.getLog(commentFilter.class); > > //camel 1.x > //public boolean matches(Object ex) { > public boolean matches(Exchange exchange) { > log.debug("Starting filter"); > > //came 1.x > //Exchange exchange = (Exchange)ex; > > String email = exchange.getIn().getBody(Comment.class).getEmail(); > if(email.equalsIgnoreCase("jessesanford@gmail.com")) { > log.debug("Skipping this exchange because it was " + > "sent by blacklisted email address: " + email); > > return false; > } else { > log.debug("Email not blacklisted. Allowing exchange to be > routed " + > email); > > return true; > } > } > > //camel 1.x > //public void assertMatches(String s, Object o) { > > //do nothing > //this just satisfies the interface > //} > } > > It only executes the predicate one time. On the first message that is > passed. I can tell this because I see the following in the logs: > > 18:19:03,894 DEBUG CommentCaptureController:captureWithJms:117 - > captureWithJms > 18:19:03,894 DEBUG CommentCaptureController:captureWithJms:117 - > captureWithJms > 18:19:03,895 DEBUG CommentCaptureController:capture:88 - Start > 18:19:03,895 DEBUG CommentCaptureController:capture:88 - Start > 18:19:03,896 DEBUG JmsCatcher:catchComment:84 - sending a message. > 18:19:03,896 DEBUG JmsCatcher:catchComment:84 - sending a message. > 18:19:03,923 INFO SingleConnectionFactory:initConnection:293 - Established > shared JMS Connection: PooledConnection { > org.apache.activemq.pool.ConnectionPool@4800ef96 } > 18:19:03,934 INFO FailoverTransport:doReconnect:756 - Successfully > connected to tcp://localhost:61716 > 18:19:04,024 INFO VelocityEngine:logVelocityMessage:49 - ResourceManager : > found index.vm with loader > org.apache.velocity.runtime.resource.loader.FileResourceLoader > 18:19:04,077 DEBUG commentFilter:matches:25 - Starting filter > 18:19:04,077 DEBUG commentFilter:matches:25 - Starting filter > 18:19:04,079 DEBUG commentFilter:matches:31 - Skipping this exchange > because it was sent by blacklisted email address: jessesanford@gmail.com > 18:19:04,079 DEBUG commentFilter:matches:31 - Skipping this exchange > because it was sent by blacklisted email address: jessesanford@gmail.com > 18:19:28,423 DEBUG CommentCaptureController:captureWithJms:117 - > captureWithJms > 18:19:28,423 DEBUG CommentCaptureController:captureWithJms:117 - > captureWithJms > 18:19:28,424 DEBUG CommentCaptureController:capture:88 - Start > 18:19:28,424 DEBUG CommentCaptureController:capture:88 - Start > 18:19:28,424 DEBUG JmsCatcher:catchComment:84 - sending a message. > 18:19:28,424 DEBUG JmsCatcher:catchComment:84 - sending a message. > 18:19:28,597 DEBUG JdbcCatcher:capture:204 - done > 18:19:28,597 DEBUG JdbcCatcher:capture:204 - done > > > You can see that on the second submit (of the same exact data so the > exchange should hold the same info) that the predicate is not run or at > least it does not fire the section of the code that has my log message in > it. > > Can you think of any reason why this might be? > > Ultimately I would like to have the predicate do a jdbc call to a > blacklisted email table to check that the messages are allowed through > before processing them. > > Am I pursuing this in the wrong fashion? > > How would you go about achieving this functionality? > > Thanks so much! > > Jesse > > > On Mon, Apr 12, 2010 at 12:09 AM, Claus Ibsen wrote: > >> Hi Jesse >> >> btw thanks for the kudo. >> >> The interceptors in Camel 1.x is not working super duper. >> And hence why they have been overhauled in the 2.0 onwards, which >> would allow you to do what you want. >> >> I suggest to search in the camel-core src/test/java directory for any >> intercept unit tests and see if you can find an example that looks >> like what you are doing. >> >> I assume upgrading to 2.x is not an option. You may instead want to >> use a Filter EIP in 1.x to build a solution where you can use the >> predicate to include the "good" messages in the filter. Then the bad >> messages can be "skipped". >> >> >> On Sun, Apr 11, 2010 at 11:11 PM, Jesse Sanford >> wrote: >> > I am trying to intercept an exchange using a custom predicate and I am >> > having trouble re-routing the exchange or even simply stoping it. >> > >> > Here is my routebuilder: >> > >> > public class commentRoute extends RouteBuilder{ >> > @Override >> > public void configure(){ >> > intercept().when(isBlacklisted()).to("mock:intercepted").stop(); >> > from("comment-queue").to("comment-catcher"); >> > } >> > >> > private Predicate isBlacklisted(){ >> > return new Predicate(){ >> > public boolean matches(Object ex) { >> > Exchange exchange = (Exchange)ex; >> > String email = >> > exchange.getIn().getBody(Comment.class).getEmail(); >> > if(email.equalsIgnoreCase("jessesanford@gmail.com")) { >> > return true; >> > } else { >> > return false; >> > } >> > } >> > >> > public void assertMatches(String s, Object o) { >> > //do nothing >> > //this just satisfies the interface >> > } >> > }; >> > } >> > >> > } >> > >> > I know that the predicate is being run because If I set a breakpoint at >> > >> > if(email.equalsIgnoreCase("jessesanford@gmail.com")) { >> > >> > >> > and step through the code from there the return true; is reached when i >> send >> > an exchange with the email address filled in with my email address. >> > >> > Am I doing this all wrong? If this predicate is run and returns true why >> > doesn't camel respect my intercept re-routing or stoping? >> > >> > Thanks so much, >> > jesse >> > >> >> >> >> -- >> Claus Ibsen >> Apache Camel Committer >> >> Author of Camel in Action: http://www.manning.com/ibsen/ >> Open Source Integration: http://fusesource.com >> Blog: http://davsclaus.blogspot.com/ >> Twitter: http://twitter.com/davsclaus >> > > --001636e909e6eaefa2048411b163--