Search in sources :

Example 36 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class LogDefinition method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    ObjectHelper.notEmpty(message, "message", this);
    // use simple language for the message string to give it more power
    Expression exp = routeContext.getCamelContext().resolveLanguage("simple").createExpression(message);
    // get logger explicitely set in the definition
    Logger logger = this.getLogger();
    // get logger which may be set in XML definition
    if (logger == null && ObjectHelper.isNotEmpty(loggerRef)) {
        logger = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), loggerRef, Logger.class);
    }
    if (logger == null) {
        // first - try to lookup single instance in the registry, just like LogComponent
        Map<String, Logger> availableLoggers = routeContext.lookupByType(Logger.class);
        if (availableLoggers.size() == 1) {
            logger = availableLoggers.values().iterator().next();
            LOG.debug("Using custom Logger: {}", logger);
        } else if (availableLoggers.size() > 1) {
            // we should log about this somewhere...
            LOG.debug("More than one {} instance found in the registry. Falling back to create logger by name.", Logger.class.getName());
        }
    }
    if (logger == null) {
        String name = getLogName();
        if (name == null) {
            name = routeContext.getCamelContext().getGlobalOption(Exchange.LOG_EIP_NAME);
            if (name != null) {
                LOG.debug("Using logName from CamelContext properties: {}", name);
            }
        }
        if (name == null) {
            name = routeContext.getRoute().getId();
            LOG.debug("LogName is not configured, using route id as logName: {}", name);
        }
        logger = LoggerFactory.getLogger(name);
    }
    // should be INFO by default
    LoggingLevel level = getLoggingLevel() != null ? getLoggingLevel() : LoggingLevel.INFO;
    CamelLogger camelLogger = new CamelLogger(logger, level, getMarker());
    return new LogProcessor(exp, camelLogger);
}
Also used : CamelLogger(org.apache.camel.util.CamelLogger) LoggingLevel(org.apache.camel.LoggingLevel) Expression(org.apache.camel.Expression) LogProcessor(org.apache.camel.processor.LogProcessor) Logger(org.slf4j.Logger) CamelLogger(org.apache.camel.util.CamelLogger)

Example 37 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class SetPropertyDefinition method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    ObjectHelper.notNull(getPropertyName(), "propertyName", this);
    Expression expr = getExpression().createExpression(routeContext);
    Expression nameExpr = ExpressionBuilder.parseSimpleOrFallbackToConstantExpression(getPropertyName(), routeContext.getCamelContext());
    return new SetPropertyProcessor(nameExpr, expr);
}
Also used : Expression(org.apache.camel.Expression) SetPropertyProcessor(org.apache.camel.processor.SetPropertyProcessor)

Example 38 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class SplitDefinition method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    Processor childProcessor = this.createChildProcessor(routeContext, true);
    aggregationStrategy = createAggregationStrategy(routeContext);
    boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing();
    boolean isStreaming = getStreaming() != null && getStreaming();
    boolean isShareUnitOfWork = getShareUnitOfWork() != null && getShareUnitOfWork();
    boolean isParallelAggregate = getParallelAggregate() != null && getParallelAggregate();
    boolean isStopOnAggregateException = getStopOnAggregateException() != null && getStopOnAggregateException();
    boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing);
    ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "Split", this, isParallelProcessing);
    long timeout = getTimeout() != null ? getTimeout() : 0;
    if (timeout > 0 && !isParallelProcessing) {
        throw new IllegalArgumentException("Timeout is used but ParallelProcessing has not been enabled.");
    }
    if (onPrepareRef != null) {
        onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class);
    }
    Expression exp = getExpression().createExpression(routeContext);
    Splitter answer = new Splitter(routeContext.getCamelContext(), exp, childProcessor, aggregationStrategy, isParallelProcessing, threadPool, shutdownThreadPool, isStreaming, isStopOnException(), timeout, onPrepare, isShareUnitOfWork, isParallelAggregate, isStopOnAggregateException);
    return answer;
}
Also used : Processor(org.apache.camel.Processor) Splitter(org.apache.camel.processor.Splitter) Expression(org.apache.camel.Expression) ExecutorService(java.util.concurrent.ExecutorService)

Example 39 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class ToDynamicDefinition method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    ObjectHelper.notEmpty(uri, "uri", this);
    Expression exp = createExpression(routeContext);
    SendDynamicProcessor processor = new SendDynamicProcessor(uri, exp);
    processor.setCamelContext(routeContext.getCamelContext());
    processor.setPattern(pattern);
    if (cacheSize != null) {
        processor.setCacheSize(cacheSize);
    }
    if (ignoreInvalidEndpoint != null) {
        processor.setIgnoreInvalidEndpoint(ignoreInvalidEndpoint);
    }
    return processor;
}
Also used : SendDynamicProcessor(org.apache.camel.processor.SendDynamicProcessor) Expression(org.apache.camel.Expression)

Example 40 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class IdempotentConsumerDefinition method createProcessor.

@Override
@SuppressWarnings("unchecked")
public Processor createProcessor(RouteContext routeContext) throws Exception {
    Processor childProcessor = this.createChildProcessor(routeContext, true);
    IdempotentRepository<String> idempotentRepository = resolveMessageIdRepository(routeContext);
    ObjectHelper.notNull(idempotentRepository, "idempotentRepository", this);
    Expression expression = getExpression().createExpression(routeContext);
    // these boolean should be true by default
    boolean eager = getEager() == null || getEager();
    boolean duplicate = getSkipDuplicate() == null || getSkipDuplicate();
    boolean remove = getRemoveOnFailure() == null || getRemoveOnFailure();
    // these boolean should be false by default
    boolean completionEager = getCompletionEager() != null && getCompletionEager();
    return new IdempotentConsumer(expression, idempotentRepository, eager, completionEager, duplicate, remove, childProcessor);
}
Also used : Processor(org.apache.camel.Processor) Expression(org.apache.camel.Expression) IdempotentConsumer(org.apache.camel.processor.idempotent.IdempotentConsumer)

Aggregations

Expression (org.apache.camel.Expression)183 Exchange (org.apache.camel.Exchange)44 Processor (org.apache.camel.Processor)24 Predicate (org.apache.camel.Predicate)22 DefaultExchange (org.apache.camel.impl.DefaultExchange)21 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)18 ArrayList (java.util.ArrayList)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)15 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)15 Language (org.apache.camel.spi.Language)15 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)14 SendProcessor (org.apache.camel.processor.SendProcessor)14 Test (org.junit.Test)8 SimpleParserException (org.apache.camel.language.simple.types.SimpleParserException)7 File (java.io.File)4 ExecutorService (java.util.concurrent.ExecutorService)4 SimpleIllegalSyntaxException (org.apache.camel.language.simple.types.SimpleIllegalSyntaxException)4 HashMap (java.util.HashMap)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 CamelExchangeException (org.apache.camel.CamelExchangeException)3