public static OnExceptionDefinition handled(OnExceptionDefinition self, Closure<?> predicate) { return self.handled((Predicate) toExpression(predicate)); }
private void setupErrorHandling() { onException(AETException.class).handled(true); errorHandler(deadLetterChannel(ERROR_ENDPOINT)); from(ERROR_ENDPOINT).process(new ErrorHandlingProcessor()); }
public void configure() { logger.info("configure", null, "Configuring Admin Channel on Endpoint:" + endpoint); onException(Exception.class).handled(true).process(new ErrorProcessor()); from(endpoint).routeId("AdminRoute").unmarshal().xstream() .process(new AdminEventProcessor(delegate)); } });
@Override public void configure() throws Exception { getContext().setTracing(true); // general error handler errorHandler(defaultErrorHandler() .maximumRedeliveries(5) .redeliveryDelay(2000) .retryAttemptedLogLevel(LoggingLevel.WARN)); // in case of a http exception then retry at most 3 times // and if exhausted then upload using ftp instead onException(HttpOperationFailedException.class).maximumRedeliveries(3) .handled(true) // use file instead of ftp as its easier to play with .to("file:target/ftp/upload"); // poll files every 5th second and send them to the HTTP server from("file:target/rider?delay=5000&readLock=none") .to("http://localhost:8765/rider"); } }
@Override public void configure() throws Exception { getContext().setTracing(true); // general error handler errorHandler(defaultErrorHandler() .maximumRedeliveries(5) .redeliveryDelay(2000) .retryAttemptedLogLevel(LoggingLevel.WARN)); // in case of a http exception then retry at most 3 times // and if exhausted then upload using ftp instead onException(IOException.class, HttpOperationFailedException.class) .maximumRedeliveries(3) .handled(true) .to(ftp); // poll files send them to the HTTP server from(file).to(http); }
@Override public void configure() throws Exception { getContext().setTracing(true); // general error handler errorHandler(defaultErrorHandler() .maximumRedeliveries(5) .redeliveryDelay(2000) .retryAttemptedLogLevel(LoggingLevel.WARN)); // in case of a http exception then retry at most 3 times // and if exhausted then upload using ftp instead onException(IOException.class, HttpOperationFailedException.class) .maximumRedeliveries(3) .handled(true) .to(ftp); // poll files send them to the HTTP server from(file).to(http); }
@Override public void configure() throws Exception { getContext().setTracing(true); // general error handler errorHandler(defaultErrorHandler() .maximumRedeliveries(5) .redeliveryDelay(2000) .retryAttemptedLogLevel(LoggingLevel.WARN)); // in case of a http exception then retry at most 3 times // and if exhausted then upload using ftp instead onException(HttpOperationFailedException.class).maximumRedeliveries(3) .handled(true) // use file instead of ftp as its easier to play with .to("file:target/ftp/upload"); // poll files every 5th second and send them to the HTTP server from("file:target/rider?delay=5000&readLock=none") .to("http://localhost:8765/rider"); } }
@Override public void configure() throws Exception { restConfiguration() .component("servlet") .enableCORS(true) .contextPath("/") .bindingMode(RestBindingMode.auto); rest("/").get().produces("text/plain") .route().routeId("root") .to("http4:recommendation:8080/?httpClient.connectTimeout=1000&bridgeEndpoint=true©Headers=true&connectionClose=true") .routeId("recommendation") .onException(HttpOperationFailedException.class) .handled(true) .process(this::handleHttpFailure) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(503)) .end() .onException(Exception.class) .handled(true) .transform(simpleF(RESPONSE_STRING_FORMAT, exceptionMessage()) ) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(503)) .end() .transform(simpleF(RESPONSE_STRING_FORMAT, "${body}")) .endRest(); }
/** * 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 { 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(); }
@Override public void configure() throws Exception { // global error handler errorHandler(noErrorHandler()); from("direct:input-1") .to("mock:inter") // inherits global error handler (step in pipeline) .process(failure) // inherits global error handler (step in pipeline) .to("mock:output"); // inherits global error handler (step in pipeline) from("direct:input-2") // defines local error handler (placed before every node in this route) .errorHandler(defaultErrorHandler().maximumRedeliveries(2)).to("mock:error") .onException(Exception.class).handled(false).end() .to("mock:inter") // no redeliveries here .to("direct:temp"); // the error handler of this node redelivers from("direct:temp") .to("mock:check") // inherits global error handler (step in pipeline) .process(failure) // inherits global error handler (step in pipeline) .to("mock:output"); // inherits global error handler (step in pipeline) }
.handled(true) .log(LoggingLevel.DEBUG, "Asynch. routes - unspecified exception caught: ${property." + Exchange.EXCEPTION_CAUGHT + ".message}.") .handled(true) .log(LoggingLevel.ERROR, "Error while handling error: ${exception.stacktrace}") .end() .handled(true) .log(LoggingLevel.ERROR, "Error while handling error: ${exception.stacktrace}") .end() .handled(true) .log(LoggingLevel.ERROR, "exception during confirmation caught " + "- '${property." + Exchange.EXCEPTION_CAUGHT + ".message}'")
.maximumRedeliveries(2) .redeliveryDelay(1000) .handled(true) .routeId("retryAfterConcurrentUpdate") .handled(true) .to("direct:sendFailureResponse"); .log("failure during direct:sendFailureResponse, rolling back transaction for exchange ${exchangeId}") .rollback() .handled(true) .end() .transacted("PROPAGATION_REQUIRES_NEW") .handled(true) .stop() .end()