/** * Defines global (better to say semi-global because it's scoped for one route builder) exception policy * and common error handling. * <p> * Default implementation catches common {@link Exception} and if it's synchronous message * (see {@link AsynchConstants#ASYNCH_MSG_HEADER}) then redirect to {@link AsynchConstants#URI_EX_TRANSLATION}. * If it's asynchronous message then determines according to exception's type if redirect to * {@link AsynchConstants#URI_ERROR_FATAL} or {@link AsynchConstants#URI_ERROR_HANDLING} route URI. * * @throws Exception can be thrown during configuration */ @SuppressWarnings("unchecked") protected void doErrorHandling() throws Exception { // note: IO exceptions must be handled where is call to external system onException(Exception.class) .handled(true) .log(LoggingLevel.ERROR, "exception caught (asynch = '${header." + AsynchConstants.ASYNCH_MSG_HEADER + "}') " + "- ${property." + Exchange.EXCEPTION_CAUGHT + ".message}") .bean(this, "printMessageHistory") .choice() .when().method(this, "isAsynch") // process exception and redirect message to next route .routingSlip(method(this, "exceptionHandling")) .end() .otherwise() // synchronous .to(AsynchConstants.URI_EX_TRANSLATION) .end(); }
@Override public void configure() throws Exception { from("file://in").id("file2jms") .to("jms:person"); from("jms:person").id("personJms2Rest") // .onException(ConnectException.class).log("Exception processing message.. does the personservice run?").end() .setHeader("person_id", xpath("/person/id").stringResult()) .to("log:test") .setHeader(Exchange.HTTP_METHOD, constant("PUT")) .setHeader(Exchange.CONTENT_TYPE, constant("text/xml")) .setHeader(Exchange.HTTP_URI, simple("${properties:personServiceUri}/${header.person_id}")) // .to("http://dummy"); }
@Override public void configure() throws Exception { restConfiguration() .component("servlet") .enableCORS(true) .contextPath("/") .bindingMode(RestBindingMode.auto); rest("/").get().consumes(MediaType.TEXT_PLAIN_VALUE) .route().routeId("root") .pipeline() .bean("CustomerCamelRoute", "addTracer") .to("http4:preference:8080/?httpClient.connectTimeout=1000&bridgeEndpoint=true©Headers=true&connectionClose=true") .end() .convertBodyTo(String.class) .onException(HttpOperationFailedException.class) .handled(true) .process(this::handleHttpFailure) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(503)) .end() .onException(Exception.class) .log(exceptionMessage().toString()) .handled(true) .transform(simpleF(RESPONSE_STRING_FORMAT, exceptionMessage())) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(503)) .end() .transform(simpleF(RESPONSE_STRING_FORMAT, "${body}")) .endRest(); }
.log(LoggingLevel.DEBUG, "Asynch. routes - unspecified exception caught: ${property." + Exchange.EXCEPTION_CAUGHT + ".message}.") .log(LoggingLevel.ERROR, "Error while handling error: ${exception.stacktrace}") .end() .log(LoggingLevel.ERROR, "Error while handling error: ${exception.stacktrace}") .end() .log(LoggingLevel.ERROR, "exception during confirmation caught " + "- '${property." + Exchange.EXCEPTION_CAUGHT + ".message}'") .choice()
@Override public void configure() throws Exception { onException(CannotAcquireLockException.class, JpaSystemException.class) //due to our transaction isolation, we may have to retry .log(LoggingLevel.INFO, "re-delivering the current message because of an exception, wonMessage header: ${header." + WonCamelConstants.MESSAGE_HEADER +"}") .maximumRedeliveries(2) .redeliveryDelay(1000) .routeId("direct:sendFailureResponse") .onException(Exception.class) .log("failure during direct:sendFailureResponse, rolling back transaction for exchange ${exchangeId}") .rollback() .handled(true) .log("failure during seda:OwnerProtocolOut, ignoring. Exception message: ${exception.message}") .handled(true) .stop()
.log("Event Routing Error: ${routeId}");