コード例 #1
0
    public void process(Exchange exchange) throws Exception {
      TracedRouteNodes traced = exchange.getUnitOfWork().getTracedRouteNodes();

      // get the list of intercepted nodes
      List<RouteNode> list = traced.getNodes();
      // get the 3rd last as its the bean
      Processor last = list.get(list.size() - 3).getProcessor();

      // wrapped by JMX
      if (last instanceof InstrumentationProcessor) {
        InstrumentationProcessor ip = (InstrumentationProcessor) last;
        last = ip.getProcessor();
      }

      // set error message
      exchange.getOut().setFault(true);
      exchange.getOut().setBody("Failed at: " + last.toString());
    }
コード例 #2
0
  /**
   * Creates the {@link ProcessorExchangePair} which holds the processor and exchange to be send
   * out.
   *
   * <p>You <b>must</b> use this method to create the instances of {@link ProcessorExchangePair} as
   * they need to be specially prepared before use.
   *
   * @param index the index
   * @param processor the processor
   * @param exchange the exchange
   * @param routeContext the route context
   * @return prepared for use
   */
  protected ProcessorExchangePair createProcessorExchangePair(
      int index, Processor processor, Exchange exchange, RouteContext routeContext) {
    Processor prepared = processor;

    // set property which endpoint we send to
    setToEndpoint(exchange, prepared);

    // rework error handling to support fine grained error handling
    prepared = createErrorHandler(routeContext, exchange, prepared);

    // invoke on prepare on the exchange if specified
    if (onPrepare != null) {
      try {
        onPrepare.process(exchange);
      } catch (Exception e) {
        exchange.setException(e);
      }
    }
    return new DefaultProcessorExchangePair(index, processor, prepared, exchange);
  }
コード例 #3
0
    public void process(Exchange exchange) throws Exception {
      // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
      // I need to copy the body of the exachange because for some reason
      // the getContext().getEndpoint() erase the content/or loose the reference
      String body = exchange.getIn().getBody(String.class);
      if (dep == null) {

        this.dep = exchange.getContext().getEndpoint(this.droolsUri, DroolsEndpoint.class);
      }

      if (dep == null) {
        throw new RuntimeException("Could not find DroolsEndPoint for uri=" + this.droolsUri);
      }

      ClassLoader originalClassLoader = null;
      try {
        originalClassLoader = Thread.currentThread().getContextClassLoader();

        CommandExecutor exec = dep.executor;
        if (exec == null) {
          String lookup = exchange.getIn().getHeader(DroolsComponent.DROOLS_LOOKUP, String.class);
          if (StringUtils.isEmpty(lookup)) {
            // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
            lookup = dep.getLookup(body);
            // lookup = dep.getLookup( exchange.getIn().getBody( String.class ) );
          }

          if (StringUtils.isEmpty(lookup)) {
            throw new RuntimeException(
                "No Executor defined and no lookup information available for uri "
                    + this.dep.getEndpointUri());
          }
          exec = dep.getCommandExecutor(lookup);
        }

        if (exec == null) {
          throw new RuntimeException(
              "CommandExecutor cannot be found for uri " + this.dep.getEndpointUri());
        }
        ClassLoader localClassLoader = dep.getClassLoader(exec);
        if (localClassLoader == null) {
          throw new RuntimeException(
              "CommandExecutor Classloader cannot be null for uri " + this.dep.getEndpointUri());
        }

        // Set the classloader to the one used by the CommandExecutor
        Thread.currentThread().setContextClassLoader(localClassLoader);
        ExecutionNodePipelineContextImpl context =
            new ExecutionNodePipelineContextImpl(dep.node, localClassLoader);
        context.setCommandExecutor(exec);

        exchange.setProperty("drools-context", context);
        // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
        // I need to re set the Body because the exchange loose the content at
        // the begining of the method
        exchange.getIn().setBody(new ByteArrayInputStream(body.getBytes("UTF-8")));

        boolean soap = false;
        if (!augmented && exchange.getFromEndpoint() instanceof CxfSpringEndpoint) {
          new PreCxfTransportSoapProcessor().process(exchange);
          soap = true;
        }
        processor.process(exchange);
        if (soap) {
          new PostCxfTransportSoapProcessor().process(exchange);
        }
      } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
      }
    }