Ejemplo n.º 1
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);
         }
       }
     }
   }
 }
  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);
  }
  /**
   * Determines if redelivery is enabled by checking if any of the redelivery policy settings may
   * allow redeliveries.
   *
   * @return <tt>true</tt> if redelivery is possible, <tt>false</tt> otherwise
   * @throws Exception can be thrown
   */
  private boolean determineIfRedeliveryIsEnabled() throws Exception {
    // determine if redeliver is enabled either on error handler
    if (getRedeliveryPolicy().getMaximumRedeliveries() != 0) {
      // must check for != 0 as (-1 means redeliver forever)
      return true;
    }
    if (retryWhilePolicy != null) {
      return true;
    }

    // or on the exception policies
    if (!exceptionPolicies.isEmpty()) {
      // walk them to see if any of them have a maximum redeliveries > 0 or retry until set
      for (OnExceptionDefinition def : exceptionPolicies.values()) {

        if (def.getRedeliveryPolicy() != null) {
          String ref = def.getRedeliveryPolicyRef();
          if (ref != null) {
            // lookup in registry if ref provided
            RedeliveryPolicy policy =
                CamelContextHelper.mandatoryLookup(camelContext, ref, RedeliveryPolicy.class);
            if (policy.getMaximumRedeliveries() != 0) {
              // must check for != 0 as (-1 means redeliver forever)
              return true;
            }
          } else {
            Integer max =
                CamelContextHelper.parseInteger(
                    camelContext, def.getRedeliveryPolicy().getMaximumRedeliveries());
            if (max != null && max != 0) {
              // must check for != 0 as (-1 means redeliver forever)
              return true;
            }
          }
        }

        if (def.getRetryWhilePolicy() != null || def.getRetryWhile() != null) {
          return true;
        }
      }
    }

    return false;
  }
Ejemplo n.º 4
0
  /** Returns the summary label of a node for visualisation purposes */
  public static String getDisplayText(OptionalIdentifiedDefinition camelNode) {
    String id = camelNode.getId();
    if (!Strings2.isEmpty(id)) {
      return id;
    }
    if (camelNode instanceof FromDefinition) {
      FromDefinition node = (FromDefinition) camelNode;
      return getUri(node);
    } else if (camelNode instanceof ToDefinition) {
      ToDefinition node = (ToDefinition) camelNode;
      return getUri(node);
    } else if (camelNode instanceof BeanDefinition) {
      BeanDefinition node = (BeanDefinition) camelNode;
      return "bean " + getOrBlank(node.getRef());
    } else if (camelNode instanceof CatchDefinition) {
      CatchDefinition node = (CatchDefinition) camelNode;
      List exceptions = node.getExceptions();
      if (exceptions != null && exceptions.size() > 0) {
        return "catch " + exceptions;
      } else {
        return "catch " + Expressions.getExpressionOrElse(node.getHandled());
      }
    } else if (camelNode instanceof ChoiceDefinition) {
      return "choice";
    } else if (camelNode instanceof ConvertBodyDefinition) {
      ConvertBodyDefinition node = (ConvertBodyDefinition) camelNode;
      return "convertBody " + getOrBlank(node.getType());
    } else if (camelNode instanceof EnrichDefinition) {
      EnrichDefinition node = (EnrichDefinition) camelNode;
      // return "enrich " + getOrBlank(node.getResourceUri());
      return "enrich " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof FinallyDefinition) {
      return "finally";
    } else if (camelNode instanceof InOnlyDefinition) {
      InOnlyDefinition node = (InOnlyDefinition) camelNode;
      return "inOnly " + getOrBlank(node.getUri());
    } else if (camelNode instanceof InOutDefinition) {
      InOutDefinition node = (InOutDefinition) camelNode;
      return "inOut " + getOrBlank(node.getUri());
    } else if (camelNode instanceof InterceptSendToEndpointDefinition) {
      InterceptSendToEndpointDefinition node = (InterceptSendToEndpointDefinition) camelNode;
      return "intercept " + getOrBlank(node.getUri());
    } else if (camelNode instanceof LogDefinition) {
      LogDefinition node = (LogDefinition) camelNode;
      return "log " + getOrBlank(node.getLogName());
    } else if (camelNode instanceof MarshalDefinition) {
      return "marshal";
    } else if (camelNode instanceof OnExceptionDefinition) {
      OnExceptionDefinition node = (OnExceptionDefinition) camelNode;
      return "on exception " + getOrBlank(node.getExceptions());
    } else if (camelNode instanceof OtherwiseDefinition) {
      return "otherwise";
    } else if (camelNode instanceof PollEnrichDefinition) {
      PollEnrichDefinition node = (PollEnrichDefinition) camelNode;
      // TODO
      // return "poll enrich " + getOrBlank(node.getResourceUri());
      return "poll enrich " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof RemoveHeaderDefinition) {
      RemoveHeaderDefinition node = (RemoveHeaderDefinition) camelNode;
      return "remove header " + getOrBlank(node.getHeaderName());
    } else if (camelNode instanceof RemovePropertyDefinition) {
      RemovePropertyDefinition node = (RemovePropertyDefinition) camelNode;
      return "remove property " + getOrBlank(node.getPropertyName());
    } else if (camelNode instanceof RollbackDefinition) {
      RollbackDefinition node = (RollbackDefinition) camelNode;
      return "rollback " + getOrBlank(node.getMessage());
    } else if (camelNode instanceof SetExchangePatternDefinition) {
      SetExchangePatternDefinition node = (SetExchangePatternDefinition) camelNode;
      ExchangePattern pattern = node.getPattern();
      if (pattern == null) {
        return "setExchangePattern";
      } else {
        return "set " + pattern;
      }
    } else if (camelNode instanceof SortDefinition) {
      SortDefinition node = (SortDefinition) camelNode;
      return "sort " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof WhenDefinition) {
      WhenDefinition node = (WhenDefinition) camelNode;
      return "when " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof UnmarshalDefinition) {
      return "unmarshal";
    } else if (camelNode instanceof TryDefinition) {
      return "try";
    } else if (camelNode instanceof LoadBalanceDefinition) {
      LoadBalanceDefinition load = (LoadBalanceDefinition) camelNode;
      return load.getShortName();
      /*
                  TODO

         			if (load.getRef() != null) {
         				return "custom " + getOrBlank(load.getRef());
         			} else if (load.getLoadBalancerType() != null) {
         				if (load.getLoadBalancerType().getClass().isAssignableFrom(CustomLoadBalancerDefinition.class)) {
         					CustomLoadBalancerDefinition custom = (CustomLoadBalancerDefinition) load.getLoadBalancerType();
         					return "custom " + getOrBlank(custom.getRef());
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(FailoverLoadBalancerDefinition.class)) {
         					return "failover";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(RandomLoadBalancerDefinition.class)) {
         					return "random";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(RoundRobinLoadBalancerDefinition.class)) {
         					return "round robin";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(StickyLoadBalancerDefinition.class)) {
         					return "sticky";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(TopicLoadBalancerDefinition.class)) {
         					return "topic";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(WeightedLoadBalancerDefinition.class)) {
         					return "weighted";
         				}
         			} else {
         				return "load balance";
         			}
      */
    }

    String answer = null;
    try {
      answer = camelNode.getLabel();
    } catch (Exception e) {
      // ignore errors in Camel
    }
    if (Strings2.isBlank(answer)) {
      answer = getPatternName(camelNode);
    }
    return answer;
  }