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 5A087113B4 for ; Tue, 8 Jul 2014 15:36:38 +0000 (UTC) Received: (qmail 8212 invoked by uid 500); 8 Jul 2014 15:36:38 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 8164 invoked by uid 500); 8 Jul 2014 15:36:37 -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 8151 invoked by uid 99); 8 Jul 2014 15:36:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jul 2014 15:36:37 +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 (athena.apache.org: domain of atgroxx@gmail.com designates 209.85.212.177 as permitted sender) Received: from [209.85.212.177] (HELO mail-wi0-f177.google.com) (209.85.212.177) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jul 2014 15:36:30 +0000 Received: by mail-wi0-f177.google.com with SMTP id ho1so1228937wib.4 for ; Tue, 08 Jul 2014 08:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=qtPSo4201hdInrdGFjS7KuyAGHKdWow1K4zumk32uEY=; b=bF/I+TIymY29je/Laqt4Zg7u8+CBgNu6BEc9KuV274dgviyAe8RLb4t7vFPsA3hG89 EZZH3AJxjwN67UFpuUyynX2yT1qaqN6xpNcMSya4vIrWprpxdZGWqkNCYasbLJQDEO2T Ufsm/Sg5YoAeWJYGdSUNPG5vZcNi56ZiTliZ/msnuG2sH+s2BLdohFP9Qr3hdceO7nZO Qcl6NQMZS9cOaZrg3Vp/S7lVFQ4d7Xl6ymJS+1MyiMamBVZceuMILxbQNB6d6WDyLuMM cGG4c/bNGwRzTnmTQwVIvh4JLxfdfircSThST54I4f6lWDIUtcPskAbaHb0SbLczWDjS CLnQ== MIME-Version: 1.0 X-Received: by 10.180.91.81 with SMTP id cc17mr4710537wib.17.1404833767931; Tue, 08 Jul 2014 08:36:07 -0700 (PDT) Received: by 10.194.79.106 with HTTP; Tue, 8 Jul 2014 08:36:07 -0700 (PDT) Date: Tue, 8 Jul 2014 16:36:07 +0100 Message-ID: Subject: onException is not working as expected. From: atg roxx To: users@camel.apache.org Content-Type: multipart/alternative; boundary=f46d0438923db4e8b504fdb059f6 X-Virus-Checked: Checked by ClamAV on apache.org --f46d0438923db4e8b504fdb059f6 Content-Type: text/plain; charset=UTF-8 Hi Team, I am using multicast with AggreationStrategy an also using onException on my route. Happy case is working fine, But when there is any exception, my exception processor handle it and set a header and add error message in the body of the exchange. When call go back to aggregator, it check whether the body of the exchange received is not null and of type Class A or not. if not then we know this exchange is returned by the Exception handler. and we return that exchange. When testing for exception , my mock end point does not receive exchange set by the exception processor. Kindly guide me where I am getting things wrong.: Below is the source code: Route definition :------------------------------------- onException(RecoverableException.class) .maximumRedeliveries(2) .handled(true) .beanRef("myCustomeExceptionHandler","handleException"); from("{{route.direct.endpoint}}") .routeId(ROUTE_ID) .multicast(new MyAggregationStrategy()) .parallelProcessing() .timeout(COMPLETION_TIMEOUT) .to(GET_DETAILS, GET_SUMMARY, GET_IMAGE) .end() .marshal(responseFormat); from(GET_SUMMARY) .choice() .when(summaryIsRequested) .beanRef("myCustomeService", "getSummary") .otherwise() .setBody().constant(null) .log(LoggingLevel.DEBUG, "Skipping summary - not requested.") .end(); from(GET_DETAILS) .choice() .when(detailsAreRequested) .beanRef("myCustomeService", "getDetails") .otherwise() .setBody().constant(null) .log(LoggingLevel.DEBUG, "Skipping details - not requested.") .end(); from(GET_IMAGE) .routeId("podImageRoute") .choice() .when(podImageIsRequested) .beanRef("myCustomeService", "getImage") .otherwise() .setBody().constant(null) .log(LoggingLevel.DEBUG, "Skipping image - not requested.") .end(); Exception Handler :------------------------------------------------------------------ public class HttpResponseExceptionHandler implements ExceptionHandler { @Override public void handleRecoverableException(Exchange exchange) { Throwable cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); String failureRouteId = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, String.class); String errorMessage = cause.getMessage(); LOGGER.error("Exception occurred in the route {}. Exception details are: {}", failureRouteId, errorMessage); exchange.getIn().removeHeaders("*"); exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, statusCode); exchange.getIn().setBody(errorMessage); } } Aggregator code: ---------------------------- public class MyCustomeAggregationStrategy implements AggregationStrategy { @Override public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { if (oldExchange == null) { // occurs for a new group return newExchange; } if (exchangeHasNonNullBody(oldExchange) && exchangeContainBodyofTypeClassA(oldExchange)) { oldBody=oldExchange.getIn().getBody(); } else { return oldExchange; // assuming that body contain string message set in Exception Handler } } if (exchangeHasNonNullBody(newExchange) && exchangeContainBodyofTypeClassA(newExchange)) { newBody=newExchange.getIn().getBody(); } else { return newExchange; // assuming that body contain string message set in Exception Handler } } MergeBodyofOldAndNewExchange(oldExchange,oldBody,newBody); return oldExchange; } ---------------------- Test case :--------------------- @DirtiesContext @Test public void testExceptionHandeling() throws Exception { // Given when(myService.getImage(anyString(), anyString())).thenThrow(new ConnectionException("Exception of type ConnectionException")); mockEndpointResult.expectedMessageCount(1); // When try { template.sendBody("{{route.direct.endpoint}}", request); Thread.sleep(1000); // wait a few moments... //then mockEndpointResult.assertIsSatisfied(); // fails here } catch (CamelExecutionException ex) { //then fail(); } } -- Regards, atg roxx --f46d0438923db4e8b504fdb059f6--