Esempio n. 1
0
  @Override
  protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters)
      throws Exception {
    EventBus resolvedEventBus = eventBus;
    if (resolvedEventBus == null) {
      resolvedEventBus =
          CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, EventBus.class);
    }

    return new GuavaEventBusEndpoint(uri, this, resolvedEventBus, listenerInterface);
  }
  protected void configureScheduledPollConsumerProperties(
      Map<String, Object> options, Map<String, Object> consumerProperties) {
    // special for scheduled poll consumers as we want to allow end users to configure its options
    // from the URI parameters without the consumer. prefix
    Map<String, Object> schedulerProperties =
        IntrospectionSupport.extractProperties(options, "scheduler.");
    if (schedulerProperties != null && !schedulerProperties.isEmpty()) {
      setSchedulerProperties(schedulerProperties);
    }

    if (scheduler == null && schedulerName != null) {
      if ("none".equals(schedulerName)) {
        // no cron scheduler in use
        scheduler = null;
      } else if ("spring".equals(schedulerName)) {
        // special for scheduler if its "spring" or "quartz2"
        try {
          Class<? extends ScheduledPollConsumerScheduler> clazz =
              getCamelContext()
                  .getClassResolver()
                  .resolveMandatoryClass(SPRING_SCHEDULER, ScheduledPollConsumerScheduler.class);
          setScheduler(getCamelContext().getInjector().newInstance(clazz));
        } catch (ClassNotFoundException e) {
          throw new IllegalArgumentException(
              "Cannot load "
                  + SPRING_SCHEDULER
                  + " from classpath. Make sure camel-spring.jar is on the classpath.",
              e);
        }
      } else if ("quartz2".equals(schedulerName)) {
        // special for scheduler if its "spring" or "quartz2"
        try {
          Class<? extends ScheduledPollConsumerScheduler> clazz =
              getCamelContext()
                  .getClassResolver()
                  .resolveMandatoryClass(QUARTZ_2_SCHEDULER, ScheduledPollConsumerScheduler.class);
          setScheduler(getCamelContext().getInjector().newInstance(clazz));
        } catch (ClassNotFoundException e) {
          throw new IllegalArgumentException(
              "Cannot load "
                  + QUARTZ_2_SCHEDULER
                  + " from classpath. Make sure camel-quarz2.jar is on the classpath.",
              e);
        }
      } else {
        // must refer to a custom scheduler by the given name
        setScheduler(
            CamelContextHelper.mandatoryLookup(
                getCamelContext(), schedulerName, ScheduledPollConsumerScheduler.class));
      }
    }
  }
  @Override
  protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters)
      throws Exception {

    CamelContext camelContext = getCamelContext();
    int idx = remaining.indexOf(":");
    if (idx <= 0) {
      throw new IllegalArgumentException(BAD_FORMAT_MESSAGE);
    }
    String bindingName = remaining.substring(0, idx);
    String delegateURI = remaining.substring(idx + 1);
    if (delegateURI.isEmpty()) {
      throw new IllegalArgumentException(BAD_FORMAT_MESSAGE);
    }
    Binding binding = CamelContextHelper.mandatoryLookup(camelContext, bindingName, Binding.class);
    Endpoint delegate = getMandatoryEndpoint(camelContext, delegateURI);
    return new BindingEndpoint(uri, this, binding, delegate);
  }
  /**
   * 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;
  }
Esempio n. 5
0
  @SuppressWarnings("deprecation")
  public MethodInfo(
      CamelContext camelContext,
      Class<?> type,
      Method method,
      List<ParameterInfo> parameters,
      List<ParameterInfo> bodyParameters,
      boolean hasCustomAnnotation,
      boolean hasHandlerAnnotation) {
    this.camelContext = camelContext;
    this.type = type;
    this.method = method;
    this.parameters = parameters;
    this.bodyParameters = bodyParameters;
    this.hasCustomAnnotation = hasCustomAnnotation;
    this.hasHandlerAnnotation = hasHandlerAnnotation;
    this.parametersExpression = createParametersExpression();

    Map<Class<?>, Annotation> collectedMethodAnnotation = collectMethodAnnotations(type, method);

    Pattern oneway = findOneWayAnnotation(method);
    if (oneway != null) {
      pattern = oneway.value();
    }

    org.apache.camel.RoutingSlip routingSlipAnnotation =
        (org.apache.camel.RoutingSlip)
            collectedMethodAnnotation.get(org.apache.camel.RoutingSlip.class);
    if (routingSlipAnnotation != null && matchContext(routingSlipAnnotation.context())) {
      routingSlip = new RoutingSlip(camelContext);
      routingSlip.setDelimiter(routingSlipAnnotation.delimiter());
      routingSlip.setIgnoreInvalidEndpoints(routingSlipAnnotation.ignoreInvalidEndpoints());
      // add created routingSlip as a service so we have its lifecycle managed
      try {
        camelContext.addService(routingSlip);
      } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
      }
    }

    org.apache.camel.DynamicRouter dynamicRouterAnnotation =
        (org.apache.camel.DynamicRouter)
            collectedMethodAnnotation.get(org.apache.camel.DynamicRouter.class);
    if (dynamicRouterAnnotation != null && matchContext(dynamicRouterAnnotation.context())) {
      dynamicRouter = new DynamicRouter(camelContext);
      dynamicRouter.setDelimiter(dynamicRouterAnnotation.delimiter());
      dynamicRouter.setIgnoreInvalidEndpoints(dynamicRouterAnnotation.ignoreInvalidEndpoints());
      // add created dynamicRouter as a service so we have its lifecycle managed
      try {
        camelContext.addService(dynamicRouter);
      } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
      }
    }

    org.apache.camel.RecipientList recipientListAnnotation =
        (org.apache.camel.RecipientList)
            collectedMethodAnnotation.get(org.apache.camel.RecipientList.class);
    if (recipientListAnnotation != null && matchContext(recipientListAnnotation.context())) {
      recipientList = new RecipientList(camelContext, recipientListAnnotation.delimiter());
      recipientList.setStopOnException(recipientListAnnotation.stopOnException());
      recipientList.setIgnoreInvalidEndpoints(recipientListAnnotation.ignoreInvalidEndpoints());
      recipientList.setParallelProcessing(recipientListAnnotation.parallelProcessing());
      recipientList.setParallelAggregate(recipientListAnnotation.parallelAggregate());
      recipientList.setStreaming(recipientListAnnotation.streaming());
      recipientList.setTimeout(recipientListAnnotation.timeout());
      recipientList.setShareUnitOfWork(recipientListAnnotation.shareUnitOfWork());

      if (ObjectHelper.isNotEmpty(recipientListAnnotation.executorServiceRef())) {
        ExecutorService executor =
            camelContext
                .getExecutorServiceManager()
                .newDefaultThreadPool(this, recipientListAnnotation.executorServiceRef());
        recipientList.setExecutorService(executor);
      }

      if (recipientListAnnotation.parallelProcessing()
          && recipientList.getExecutorService() == null) {
        // we are running in parallel so we need a thread pool
        ExecutorService executor =
            camelContext.getExecutorServiceManager().newDefaultThreadPool(this, "@RecipientList");
        recipientList.setExecutorService(executor);
      }

      if (ObjectHelper.isNotEmpty(recipientListAnnotation.strategyRef())) {
        AggregationStrategy strategy =
            CamelContextHelper.mandatoryLookup(
                camelContext, recipientListAnnotation.strategyRef(), AggregationStrategy.class);
        recipientList.setAggregationStrategy(strategy);
      }

      if (ObjectHelper.isNotEmpty(recipientListAnnotation.onPrepareRef())) {
        Processor onPrepare =
            CamelContextHelper.mandatoryLookup(
                camelContext, recipientListAnnotation.onPrepareRef(), Processor.class);
        recipientList.setOnPrepare(onPrepare);
      }

      // add created recipientList as a service so we have its lifecycle managed
      try {
        camelContext.addService(recipientList);
      } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
      }
    }
  }
Esempio n. 6
0
 /**
  * Looks up a mandatory endpoint for a given name.
  *
  * <p>Derived classes could use this name as a logical name and look it up on some registry.
  *
  * <p>The default implementation will do a mandatory look up the name in the {@link
  * org.apache.camel.spi.Registry}.
  *
  * @throws org.apache.camel.NoSuchBeanException if not found in the {@link
  *     org.apache.camel.spi.Registry}
  */
 protected Endpoint lookupEndpoint(String name, Map<String, Object> parameters) {
   return CamelContextHelper.mandatoryLookup(getCamelContext(), name, Endpoint.class);
 }
Esempio n. 7
0
 @Override
 public <T> T mandatoryLookup(String name, Class<T> type) {
   return CamelContextHelper.mandatoryLookup(getCamelContext(), name, type);
 }