protected void handleException(Exchange exchange, RedeliveryData data) {
    Exception e = exchange.getException();

    // store the original caused exception in a property, so we can restore it later
    exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);

    // find the error handler to use (if any)
    OnExceptionDefinition exceptionPolicy = getExceptionPolicy(exchange, e);
    if (exceptionPolicy != null) {
      data.currentRedeliveryPolicy =
          exceptionPolicy.createRedeliveryPolicy(
              exchange.getContext(), data.currentRedeliveryPolicy);
      data.handledPredicate = exceptionPolicy.getHandledPolicy();
      data.continuedPredicate = exceptionPolicy.getContinuedPolicy();
      data.retryWhilePredicate = exceptionPolicy.getRetryWhilePolicy();
      data.useOriginalInMessage = exceptionPolicy.isUseOriginalMessage();
      data.asyncDelayedRedelivery = exceptionPolicy.isAsyncDelayedRedelivery(exchange.getContext());

      // route specific failure handler?
      Processor processor = exceptionPolicy.getErrorHandler();
      if (processor != null) {
        data.failureProcessor = processor;
      }
      // route specific on redelivery?
      processor = exceptionPolicy.getOnRedelivery();
      if (processor != null) {
        data.onRedeliveryProcessor = processor;
      }
    }

    // only log if not failure handled or not an exhausted unit of work
    if (!ExchangeHelper.isFailureHandled(exchange)
        && !ExchangeHelper.isUnitOfWorkExhausted(exchange)) {
      String msg =
          "Failed delivery for exchangeId: "
              + exchange.getExchangeId()
              + ". On delivery attempt: "
              + data.redeliveryCounter
              + " caught: "
              + e;
      logFailedDelivery(true, false, false, exchange, msg, data, e);
    }

    data.redeliveryCounter = incrementRedeliveryCounter(exchange, e, data);
  }
Ejemplo n.º 2
0
 /** Gather all other kind of route scoped services from the given route, except error handler */
 private void doGetRouteScopedServices(List<Service> services, Route route) {
   for (ProcessorDefinition<?> output : route.getRouteContext().getRoute().getOutputs()) {
     if (output instanceof OnExceptionDefinition) {
       OnExceptionDefinition onExceptionDefinition = (OnExceptionDefinition) output;
       if (onExceptionDefinition.isRouteScoped()) {
         Processor errorHandler = onExceptionDefinition.getErrorHandler(route.getId());
         if (errorHandler != null && errorHandler instanceof Service) {
           services.add((Service) errorHandler);
         }
       }
     } else if (output instanceof OnCompletionDefinition) {
       OnCompletionDefinition onCompletionDefinition = (OnCompletionDefinition) output;
       if (onCompletionDefinition.isRouteScoped()) {
         Processor onCompletionProcessor = onCompletionDefinition.getOnCompletion(route.getId());
         if (onCompletionProcessor != null && onCompletionProcessor instanceof Service) {
           services.add((Service) onCompletionProcessor);
         }
       }
     }
   }
 }