use of org.apache.camel.Predicate 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);
}
use of org.apache.camel.Predicate in project camel by apache.
the class ExpressionNodeHelper method toExpressionDefinition.
/**
* Determines which {@link ExpressionDefinition} describes the given predicate best possible.
* <p/>
* This implementation will use types such as {@link SimpleExpression}, {@link XPathExpression} etc.
* if the given predicate is detect as such a type.
*
* @param predicate the predicate
* @return a definition which describes the predicate
*/
public static ExpressionDefinition toExpressionDefinition(Predicate predicate) {
if (predicate instanceof SimpleBuilder) {
SimpleBuilder builder = (SimpleBuilder) predicate;
// we keep the original expression by using the constructor that accepts an expression
SimpleExpression answer = new SimpleExpression(builder);
answer.setExpression(builder.getText());
return answer;
} else if (predicate instanceof XPathBuilder) {
XPathBuilder builder = (XPathBuilder) predicate;
// we keep the original expression by using the constructor that accepts an expression
XPathExpression answer = new XPathExpression(builder);
answer.setExpression(builder.getText());
return answer;
} else if (predicate instanceof ValueBuilder) {
// ValueBuilder wraps the actual predicate so unwrap
ValueBuilder builder = (ValueBuilder) predicate;
Expression expression = builder.getExpression();
if (expression instanceof Predicate) {
predicate = (Predicate) expression;
}
}
if (predicate instanceof ExpressionDefinition) {
return (ExpressionDefinition) predicate;
}
return new ExpressionDefinition(predicate);
}
use of org.apache.camel.Predicate in project camel by apache.
the class LoopDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
Processor output = this.createChildProcessor(routeContext, true);
boolean isCopy = getCopy() != null && getCopy();
boolean isWhile = getDoWhile() != null && getDoWhile();
Predicate predicate = null;
Expression expression = null;
if (isWhile) {
predicate = getExpression().createPredicate(routeContext);
} else {
expression = getExpression().createExpression(routeContext);
}
return new LoopProcessor(output, expression, predicate, isCopy);
}
use of org.apache.camel.Predicate in project camel by apache.
the class OnCompletionDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
// and therefore is in a better position to decide among context/route scoped OnCompletion at runtime
if (routeScoped == null) {
routeScoped = super.getParent() != null;
}
boolean isOnCompleteOnly = getOnCompleteOnly() != null && getOnCompleteOnly();
boolean isOnFailureOnly = getOnFailureOnly() != null && getOnFailureOnly();
boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing();
boolean original = getUseOriginalMessagePolicy() != null && getUseOriginalMessagePolicy();
if (isOnCompleteOnly && isOnFailureOnly) {
throw new IllegalArgumentException("Both onCompleteOnly and onFailureOnly cannot be true. Only one of them can be true. On node: " + this);
}
if (original) {
// ensure allow original is turned on
routeContext.setAllowUseOriginalMessage(true);
}
String routeId = routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
Processor childProcessor = this.createChildProcessor(routeContext, true);
// wrap the on completion route in a unit of work processor
CamelInternalProcessor internal = new CamelInternalProcessor(childProcessor);
internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeContext));
onCompletions.put(routeId, internal);
Predicate when = null;
if (onWhen != null) {
when = onWhen.getExpression().createPredicate(routeContext);
}
boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing);
ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "OnCompletion", this, isParallelProcessing);
// should be after consumer by default
boolean afterConsumer = mode == null || mode == OnCompletionMode.AfterConsumer;
OnCompletionProcessor answer = new OnCompletionProcessor(routeContext.getCamelContext(), internal, threadPool, shutdownThreadPool, isOnCompleteOnly, isOnFailureOnly, when, original, afterConsumer);
return answer;
}
use of org.apache.camel.Predicate in project camel by apache.
the class PredicateBuilderTest method testCompoundAndPredicatesVarargs.
public void testCompoundAndPredicatesVarargs() throws Exception {
Predicate p1 = header("name").isEqualTo(constant("James"));
Predicate p2 = header("size").isGreaterThanOrEqualTo(constant(10));
Predicate p3 = header("location").contains(constant("London"));
Predicate and = PredicateBuilder.and(p1, p2, p3);
assertMatches(and);
}
Aggregations