Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A01979F35 for ; Wed, 28 Mar 2012 07:58:59 +0000 (UTC) Received: (qmail 76474 invoked by uid 500); 28 Mar 2012 07:58:59 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 76433 invoked by uid 500); 28 Mar 2012 07:58:58 -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 76411 invoked by uid 99); 28 Mar 2012 07:58:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Mar 2012 07:58:58 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of borut.bolcina@gmail.com designates 209.85.210.173 as permitted sender) Received: from [209.85.210.173] (HELO mail-iy0-f173.google.com) (209.85.210.173) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Mar 2012 07:58:52 +0000 Received: by iafj26 with SMTP id j26so1387801iaf.32 for ; Wed, 28 Mar 2012 00:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=bt1slMmpV6UfGBL9+IXfAyFz6j0R8xfWLesDQ0T2ZyU=; b=RAqi6RsAe5a3EcAGhbz7W3vcbed1ZBCdh5SZNueWrEeCXvE8Ewxad3H8BjiwugjJHo TMJwzNaeCjoqSf2oixZJv+LnuZE4EgH4LWiQackNrfVx/Q2woDiYFsH5b5jxS/udkj6Q SPbZW/Se4tGRfjHMzCx5xy5okRlVAENbK6x1j667U1D6garmeBoNre3dw5rBVnCmXZ87 ueYqMN3dNPsMDJ7VEJzWMaXLSVceqGkLPW/t/0cJFvy0dppymsg+m5BLxfO0kPZlejlg gbSqaQ/uUXlE6gefE+a2TDBV6T6YwbfvFQqKjug/1J57APqjGy1GcwC1dTzDmciYBnDI dUig== Received: by 10.42.131.7 with SMTP id x7mr19448740ics.40.1332921510895; Wed, 28 Mar 2012 00:58:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.150.135 with HTTP; Wed, 28 Mar 2012 00:58:10 -0700 (PDT) In-Reply-To: References: From: =?UTF-8?Q?Borut_Bol=C4=8Dina?= Date: Wed, 28 Mar 2012 09:58:10 +0200 Message-ID: Subject: Re: Printing out bean validation exception message causes, well, exception To: users@camel.apache.org Content-Type: multipart/alternative; boundary=90e6ba61375e2ba00604bc48f9b9 --90e6ba61375e2ba00604bc48f9b9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks Claus, you rock! -borut Dne 28. marec 2012 09:05 je Claus Ibsen napisal/-a: > Hi > > You handle the exception, so the getException will return null, and > therefore you cause a 2nd exception to occur. > > The caused exception is stored as a property on the exchange. > Exception cause =3D exchange.getProperty(Exchange.EXCEPTION_CAUGHT, > Exception.class); > > > > On Wed, Mar 28, 2012 at 8:44 AM, Borut Bol=C4=8Dina > wrote: > > Hello, > > > > I am using bean-validator component to validate the content of some > fields: > > > > @Override > > protected RouteBuilder createRouteBuilder() throws Exception { > > return new RouteBuilder() { > > @Override > > public void configure() throws Exception { > > DataFormat jaxbDataFormat =3D new > > JaxbDataFormat("com.mycompany.model.entities.weather"); > > onException(BeanValidationException.class) > > .handled(true) > > .process(new Processor() { > > public void process(Exchange exchange) throws Exception { > > String station =3D ((WeatherCurrent) > exchange.getIn().getBody()).getStation(); > > System.out.println("Weather station '" + station + "' does not meet > > validation constraints. Skipping."); > > } > > }); > > > > > from("file:src/test/resources/weather/observation?fileName=3Dobservation_= si_latest.xml&noop=3Dtrue") > > .split() > > .tokenizeXML("metData") > > .unmarshal(jaxbDataFormat) > > .to("bean-validator://x") > > .to("mock:meteo"); > > } > > }; > > } > > > > Running this test route nicely prints out the weather station which do > not > > meet the validation criteria: > > > > Weather station 'Bilje pri Novi Gorici' does not meet validation > > constraints. Skipping. > > Weather station 'Lisca' does not meet validation constraints. Skipping. > > Weather station 'Novo mesto' does not meet validation constraints. > Skipping. > > > > Now I wanted to print the cause of the validation error, so I added the > > exception message in the process method: > > > > String exceptionMessage =3D exchange.getException().getMessage(); > > System.out.println("Weather station '" + station + "' does not meet > > validation constraints(" + exceptionMessage + "). Skipping."); > > > > and suddenly hell broke loose > > > > [2012/03/28 08:37:48.648] ERROR [o.a.c.p.FatalFallbackErrorHandler:done= ]: > > Exception occurred while trying to handle previously thrown exception o= n > > exchangeId: ID-BOBB-54461-1332916666871-0-3 using: > > > [Channel[Wrap[com.mycompany.datarobot.weather.WeatherCurrentValidateCondi= tionNotEmptyTest$1$1@15e92d7 > ] > > -> > > > com.mycompany.datarobot.weather.WeatherCurrentValidateConditionNotEmptyTe= st$1$1@15e92d7 > ]]. > > The previous and the new exception will be logged in the following. > > [2012/03/28 08:37:48.653] ERROR [o.a.c.p.FatalFallbackErrorHandler:done= ]: > > \--> Previous exception on exchangeId: ID-BOBB-54461-1332916666871-0-3 > > org.apache.camel.component.bean.validator.BeanValidationException: > > Validation failed for: > > com.mycompany.model.entities.weather.WeatherCurrent@1a4c5b4 errors: > > [property: conditions; value: jasna; constraint: must match > "jasno|prete=C5=BEno > > jasno|rahlo obla=C4=8Dno|delno obla=C4=8Dno|zmerno obla=C4=8Dno|prete= =C5=BEno > > obla=C4=8Dno|obla=C4=8Dno|megla"; ]. Exchange[null] at > > > org.apache.camel.component.bean.validator.BeanValidator.process(BeanValid= ator.java:54) > > ~[camel-bean-validator-2.9.1.jar:2.9.1] at > > > org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java= :101) > > ~[camel-core-2.9.1.jar:2.9.1] > > ... > > FAILED: testNumberOfWeatherStations > > java.lang.AssertionError: mock://meteo Received message count. Expected= : > > <6> but was: <12> > > ... > > > > > > What gives? > > > > -borut > > > > -- > Claus Ibsen > ----------------- > CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com > FuseSource > Email: cibsen@fusesource.com > Web: http://fusesource.com > Twitter: davsclaus, fusenews > Blog: http://davsclaus.blogspot.com/ > Author of Camel in Action: http://www.manning.com/ibsen/ > --90e6ba61375e2ba00604bc48f9b9--