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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations