@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 { 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(); }
@Override public void configure() throws Exception { onException(Throwable.class).logStackTrace(true); createCamelContext(); from("timer:simple?period=" + period) .process(new OpenwireProducerConsumerExample.MessageProducerProcessor("openwire")) .to("jms:openwire.example") .onException(Throwable.class) .maximumRedeliveries(2) .redeliveryDelay(1000); from("jms:openwire.example?consumer.bridgeErrorHandler=true") .to("stream:out") .onException(Throwable.class) .maximumRedeliveries(-1); }
@Override public void configure() throws Exception { from("direct:input") // Enable the following statement if error handling // has been globally turned off via noErrorHandler(), // otherwise exception() statements have no effect. //.errorHandler(deadLetterChannel()) .onException(Exception1.class).to("mock:error1").end() .onException(Exception2.class).to("mock:error2").end() .onException(Exception.class).to("mock:error3").end() .process(exceptionProcessor()) .to("mock:success"); }
@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) .handled(true) .routeId("retryAfterConcurrentUpdate") .routeId("onException") .handled(true) .to("direct:sendFailureResponse"); .routeId("direct:sendFailureResponse") .onException(Exception.class) .log("failure during direct:sendFailureResponse, rolling back transaction for exchange ${exchangeId}") .rollback() .handled(true) .end() .transacted("PROPAGATION_REQUIRES_NEW") .to("bean:parentLocker") .log("failure during seda:OwnerProtocolOut, ignoring. Exception message: ${exception.message}") .handled(true) .stop() .end() .transacted("PROPAGATION_NEVER") .routeId("seda:OwnerProtocolOut")
.handled(true) .log(LoggingLevel.DEBUG, "Asynch. routes - unspecified exception caught: ${property." + Exchange.EXCEPTION_CAUGHT + ".message}.") .setProperty(ExtCallComponentParams.EXTERNAL_CALL_SUCCESS, constant(false)) .to(URI_ERROR_HANDLING); .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}'") .choice() .when(body().isInstanceOf(ExternalCall.class))
/** * 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(); }
.handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400)) .setBody(constant("")); .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404)) .setBody(constant("")); .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)) .setBody(simple("${exception.message}\n"));
@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) }
@Override public void configure() throws Exception { from("xds-iti41:continuaHRNService") .onException(Exception.class) .maximumRedeliveries(0) .end() .process(ContinuaHrnCamelProcessors.continuaHrnRequestTransformerAndValidator()) .process(CHECK_PROCESSOR) .setBody(constant(new Response(Status.SUCCESS))) .process(ContinuaHrnCamelProcessors.continuaHrnResponseValidator()); }
public static OnExceptionDefinition handled(OnExceptionDefinition self, Closure<?> predicate) { return self.handled((Predicate) toExpression(predicate)); }
@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"); }
.maximumRedeliveries("{{error.maxRedeliveries}}") .log("Event Routing Error: ${routeId}");
@Override public void configure() throws Exception { onException(ValidationException.class).to("mock:error"); from("direct:validator-test").process( helper.validator("testValidator").staticProfile("correct")); from("direct:validator-xml-test").process( helper.xsdValidator().staticProfile("/xsd/test.xsd")).setBody() .constant("passed"); from("direct:validator-schematron-test").process( helper.schematronValidator().staticProfile( new SchematronProfile( "/schematron/schematron-test-rules.xml"))) .setBody().constant("passed"); }
.handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400)) .setBody(constant("")); .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404)) .setBody(constant("")); .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)) .setBody(simple("${exception.message}\n"));
.errorHandler(deadLetterChannel(dlq)) .onException(SmppException.class) .maximumRedeliveries(0) .end() .removeHeaders("CamelSmpp*")//In case it started as SMS elsewhere .process(origin)
private void setupErrorHandling() { onException(AETException.class).handled(true); errorHandler(deadLetterChannel(ERROR_ENDPOINT)); from(ERROR_ENDPOINT).process(new ErrorHandlingProcessor()); }