Search in sources :

Example 6 with SimpleExpression

use of org.apache.camel.model.language.SimpleExpression in project camel by apache.

the class FileSplitInSplitTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            Tracer tracer = new Tracer();
            getContext().addInterceptStrategy(tracer);
            from("file:target/split").routeId("foo").noAutoStartup().split(body().tokenize(comma)).parallelProcessing().streaming().setProperty("split", new SimpleExpression("${property.CamelSplitIndex}")).split(body().tokenize(LS)).parallelProcessing().streaming().setBody(body().append(":Status=OK").append(LS)).to("file:target/split/outbox?fileExist=Append&fileName=result${property.split}.txt").end().setBody(new SimpleExpression("${property.split} complete")).to("file:target/split/outbox?fileExist=Append&fileName=result${property.split}.txt").end().to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Tracer(org.apache.camel.processor.interceptor.Tracer) SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Example 7 with SimpleExpression

use of org.apache.camel.model.language.SimpleExpression 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);
}
Also used : XPathExpression(org.apache.camel.model.language.XPathExpression) ValueBuilder(org.apache.camel.builder.ValueBuilder) SimpleBuilder(org.apache.camel.builder.SimpleBuilder) XPathExpression(org.apache.camel.model.language.XPathExpression) SimpleExpression(org.apache.camel.model.language.SimpleExpression) Expression(org.apache.camel.Expression) XPathBuilder(org.apache.camel.builder.xml.XPathBuilder) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition) SimpleExpression(org.apache.camel.model.language.SimpleExpression) Predicate(org.apache.camel.Predicate)

Example 8 with SimpleExpression

use of org.apache.camel.model.language.SimpleExpression in project camel by apache.

the class ProcessorDefinition method pollEnrichRef.

/**
     * The <a href="http://camel.apache.org/content-enricher.html">Content Enricher EIP</a>
     * enriches an exchange with additional data obtained from a <code>resourceUri</code>
     * using a {@link org.apache.camel.PollingConsumer} to poll the endpoint.
     * <p/>
     * The difference between this and {@link #enrich(String)} is that this uses a consumer
     * to obtain the additional data, where as enrich uses a producer.
     * <p/>
     * The timeout controls which operation to use on {@link org.apache.camel.PollingConsumer}.
     * If timeout is negative, we use <tt>receive</tt>. If timeout is 0 then we use <tt>receiveNoWait</tt>
     * otherwise we use <tt>receive(timeout)</tt>.
     *
     * @param resourceRef            Reference of resource endpoint for obtaining additional data.
     * @param timeout                timeout in millis to wait at most for data to be available.
     * @param aggregationStrategyRef Reference of aggregation strategy to aggregate input data and additional data.
     * @return the builder
     * @see org.apache.camel.processor.PollEnricher
     * @deprecated use pollEnrich with a <tt>ref:id</tt> as the resourceUri parameter.
     */
@Deprecated
@SuppressWarnings("unchecked")
public Type pollEnrichRef(String resourceRef, long timeout, String aggregationStrategyRef) {
    PollEnrichDefinition pollEnrich = new PollEnrichDefinition();
    pollEnrich.setExpression(new SimpleExpression("ref:" + resourceRef));
    pollEnrich.setTimeout(timeout);
    pollEnrich.setAggregationStrategyRef(aggregationStrategyRef);
    addOutput(pollEnrich);
    return (Type) this;
}
Also used : XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Example 9 with SimpleExpression

use of org.apache.camel.model.language.SimpleExpression in project camel by apache.

the class ExpressionClauseSupport method simple.

/**
     * Evaluates a <a href="http://camel.apache.org/simple.html">Simple
     * expression</a>
     *
     * @param text the expression to be evaluated
     * @param resultType the result type
     * @return the builder to continue processing the DSL
     */
public T simple(String text, Class<?> resultType) {
    SimpleExpression expression = new SimpleExpression(text);
    expression.setResultType(resultType);
    setExpressionType(expression);
    return result;
}
Also used : SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Aggregations

SimpleExpression (org.apache.camel.model.language.SimpleExpression)9 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)3 XmlAccessorType (javax.xml.bind.annotation.XmlAccessorType)3 Expression (org.apache.camel.Expression)2 SimpleBuilder (org.apache.camel.builder.SimpleBuilder)2 ValueBuilder (org.apache.camel.builder.ValueBuilder)2 XPathBuilder (org.apache.camel.builder.xml.XPathBuilder)2 ExpressionDefinition (org.apache.camel.model.language.ExpressionDefinition)2 XPathExpression (org.apache.camel.model.language.XPathExpression)2 Predicate (org.apache.camel.Predicate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 ConstantExpression (org.apache.camel.model.language.ConstantExpression)1 ExchangePropertyExpression (org.apache.camel.model.language.ExchangePropertyExpression)1 HeaderExpression (org.apache.camel.model.language.HeaderExpression)1 LanguageExpression (org.apache.camel.model.language.LanguageExpression)1 MethodCallExpression (org.apache.camel.model.language.MethodCallExpression)1 Tracer (org.apache.camel.processor.interceptor.Tracer)1