Search in sources :

Example 1 with SimpleExpression

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

the class Builder method simple.

/**
     * Returns a simple expression
     */
public static ValueBuilder simple(String value, Class<?> resultType) {
    SimpleExpression exp = new SimpleExpression(value);
    exp.setResultType(resultType);
    return new ValueBuilder(exp);
}
Also used : SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Example 2 with SimpleExpression

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

the class Builder method bodyAs.

/**
     * Returns a predicate and value builder for the inbound message body as a
     * specific type
     */
public static <T> ValueBuilder bodyAs(Class<T> type) {
    ObjectHelper.notNull(type, "type");
    Expression exp = new SimpleExpression(String.format("${bodyAs(%s)}", type.getCanonicalName()));
    return new ValueBuilder(exp);
}
Also used : SimpleExpression(org.apache.camel.model.language.SimpleExpression) HeaderExpression(org.apache.camel.model.language.HeaderExpression) ConstantExpression(org.apache.camel.model.language.ConstantExpression) MethodCallExpression(org.apache.camel.model.language.MethodCallExpression) LanguageExpression(org.apache.camel.model.language.LanguageExpression) Expression(org.apache.camel.Expression) ExchangePropertyExpression(org.apache.camel.model.language.ExchangePropertyExpression) SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Example 3 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 expression best possible.
     * <p/>
     * This implementation will use types such as {@link SimpleExpression}, {@link XPathExpression} etc.
     * if the given expression is detect as such a type.
     *
     * @param expression the expression
     * @return a definition which describes the expression
     */
public static ExpressionDefinition toExpressionDefinition(Expression expression) {
    if (expression instanceof SimpleBuilder) {
        SimpleBuilder builder = (SimpleBuilder) expression;
        // we keep the original expression by using the constructor that accepts an expression
        SimpleExpression answer = new SimpleExpression(builder);
        answer.setExpression(builder.getText());
        answer.setResultType(builder.getResultType());
        return answer;
    } else if (expression instanceof XPathBuilder) {
        XPathBuilder builder = (XPathBuilder) expression;
        // we keep the original expression by using the constructor that accepts an expression
        XPathExpression answer = new XPathExpression(builder);
        answer.setExpression(builder.getText());
        answer.setResultType(builder.getResultType());
        return answer;
    } else if (expression instanceof ValueBuilder) {
        // ValueBuilder wraps the actual expression so unwrap
        ValueBuilder builder = (ValueBuilder) expression;
        expression = builder.getExpression();
    }
    if (expression instanceof ExpressionDefinition) {
        return (ExpressionDefinition) expression;
    }
    return new ExpressionDefinition(expression);
}
Also used : XPathExpression(org.apache.camel.model.language.XPathExpression) ValueBuilder(org.apache.camel.builder.ValueBuilder) SimpleBuilder(org.apache.camel.builder.SimpleBuilder) XPathBuilder(org.apache.camel.builder.xml.XPathBuilder) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition) SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Example 4 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.
     * @param aggregateOnException   whether to call {@link org.apache.camel.processor.aggregate.AggregationStrategy#aggregate(org.apache.camel.Exchange, org.apache.camel.Exchange)} if
     *                               an exception was thrown.
     * @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, boolean aggregateOnException) {
    PollEnrichDefinition pollEnrich = new PollEnrichDefinition();
    pollEnrich.setExpression(new SimpleExpression("ref:" + resourceRef));
    pollEnrich.setTimeout(timeout);
    pollEnrich.setAggregationStrategyRef(aggregationStrategyRef);
    pollEnrich.setAggregateOnException(aggregateOnException);
    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 5 with SimpleExpression

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

the class ProcessorDefinition method enrichRef.

/**
     * 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>.
     * <p/>
     * The difference between this and {@link #pollEnrich(String)} is that this uses a producer
     * to obtain the additional data, where as pollEnrich uses a polling consumer.
     *
     * @param resourceRef            Reference of resource endpoint for obtaining additional data.
     * @param aggregationStrategyRef Reference of aggregation strategy to aggregate input data and additional data.
     * @param aggregateOnException   whether to call {@link org.apache.camel.processor.aggregate.AggregationStrategy#aggregate(org.apache.camel.Exchange, org.apache.camel.Exchange)} if
     *                               an exception was thrown.
     * @param shareUnitOfWork        whether to share unit of work
     * @return the builder
     * @see org.apache.camel.processor.Enricher
     * @deprecated use enrich with a <tt>ref:id</tt> as the resourceUri parameter.
     */
@Deprecated
@SuppressWarnings("unchecked")
public Type enrichRef(String resourceRef, String aggregationStrategyRef, boolean aggregateOnException, boolean shareUnitOfWork) {
    EnrichDefinition answer = new EnrichDefinition();
    answer.setExpression(new SimpleExpression("ref:" + resourceRef));
    answer.setAggregationStrategyRef(aggregationStrategyRef);
    answer.setAggregateOnException(aggregateOnException);
    answer.setShareUnitOfWork(shareUnitOfWork);
    addOutput(answer);
    return (Type) this;
}
Also used : XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) 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