Search in sources :

Example 1 with CatchProcessor

use of org.apache.camel.processor.CatchProcessor in project camel by apache.

the class CatchDefinition method createProcessor.

@Override
public CatchProcessor createProcessor(RouteContext routeContext) throws Exception {
    // create and load exceptions if not done
    if (exceptionClasses == null) {
        exceptionClasses = createExceptionClasses(routeContext.getCamelContext());
    }
    // must have at least one exception
    if (exceptionClasses.isEmpty()) {
        throw new IllegalArgumentException("At least one Exception must be configured to catch");
    }
    // parent must be a try
    if (!(getParent() instanceof TryDefinition)) {
        throw new IllegalArgumentException("This doCatch should have a doTry as its parent on " + this);
    }
    // do catch does not mandate a child processor
    Processor childProcessor = this.createChildProcessor(routeContext, false);
    Predicate when = null;
    if (onWhen != null) {
        when = onWhen.getExpression().createPredicate(routeContext);
    }
    Predicate handle = handledPolicy;
    if (handled != null) {
        handle = handled.createPredicate(routeContext);
    }
    return new CatchProcessor(exceptionClasses, childProcessor, when, handle);
}
Also used : Processor(org.apache.camel.Processor) CatchProcessor(org.apache.camel.processor.CatchProcessor) AsPredicate(org.apache.camel.spi.AsPredicate) Predicate(org.apache.camel.Predicate) CatchProcessor(org.apache.camel.processor.CatchProcessor)

Example 2 with CatchProcessor

use of org.apache.camel.processor.CatchProcessor in project camel by apache.

the class OnExceptionDefinition method createProcessor.

@Override
public CatchProcessor createProcessor(RouteContext routeContext) throws Exception {
    // load exception classes
    if (exceptions != null && !exceptions.isEmpty()) {
        exceptionClasses = createExceptionClasses(routeContext.getCamelContext().getClassResolver());
    }
    if (useOriginalMessagePolicy != null && useOriginalMessagePolicy) {
        // ensure allow original is turned on
        routeContext.setAllowUseOriginalMessage(true);
    }
    // must validate configuration before creating processor
    validateConfiguration();
    Processor childProcessor = this.createChildProcessor(routeContext, false);
    Predicate when = null;
    if (onWhen != null) {
        when = onWhen.getExpression().createPredicate(routeContext);
    }
    Predicate handle = null;
    if (handled != null) {
        handle = handled.createPredicate(routeContext);
    }
    return new CatchProcessor(getExceptionClasses(), childProcessor, when, handle);
}
Also used : Processor(org.apache.camel.Processor) CatchProcessor(org.apache.camel.processor.CatchProcessor) AsPredicate(org.apache.camel.spi.AsPredicate) Predicate(org.apache.camel.Predicate) CatchProcessor(org.apache.camel.processor.CatchProcessor)

Aggregations

Predicate (org.apache.camel.Predicate)2 Processor (org.apache.camel.Processor)2 CatchProcessor (org.apache.camel.processor.CatchProcessor)2 AsPredicate (org.apache.camel.spi.AsPredicate)2