use of org.apache.camel.support.ExpressionAdapter in project camel by apache.
the class NeilSplitterTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
Expression catFightCats = new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
CatFight catFight = (CatFight) exchange.getIn().getBody();
String[] cats = catFight.getCats();
return cats;
}
};
from("direct:custom").split(catFightCats).to("mock:result");
from("direct:xpath").split(xpath("/a/b")).to("mock:result");
}
};
}
use of org.apache.camel.support.ExpressionAdapter in project camel by apache.
the class InterceptFromDefinition method createProcessor.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Processor createProcessor(RouteContext routeContext) throws Exception {
// insert a set header definition so we can set the intercepted endpoint uri as a header
// this allows us to use the same header for both the interceptFrom and interceptSendToEndpoint
SetHeaderDefinition headerDefinition = new SetHeaderDefinition(Exchange.INTERCEPTED_ENDPOINT, new ExpressionAdapter() {
public Object evaluate(Exchange exchange, Class type) {
if (exchange.getFromEndpoint() != null) {
return exchange.getFromEndpoint().getEndpointUri();
} else {
return null;
}
}
public String toString() {
return "";
}
});
getOutputs().add(0, headerDefinition);
return this.createChildProcessor(routeContext, true);
}
use of org.apache.camel.support.ExpressionAdapter in project camel by apache.
the class ExpressionBuilder method toExpression.
/**
* Returns an expression processing the exchange to the given endpoint uri
*
* @param uri endpoint uri to send the exchange to
* @return an expression object which will return the OUT body
*/
public static Expression toExpression(final String uri) {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
String text = simpleExpression(uri).evaluate(exchange, String.class);
Endpoint endpoint = exchange.getContext().getEndpoint(text);
if (endpoint == null) {
throw new NoSuchEndpointException(text);
}
Producer producer;
try {
producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
// return the OUT body, but check for exchange pattern
if (ExchangeHelper.isOutCapable(exchange)) {
return exchange.getOut().getBody();
} else {
return exchange.getIn().getBody();
}
}
@Override
public String toString() {
return "to(" + uri + ")";
}
};
}
use of org.apache.camel.support.ExpressionAdapter in project camel by apache.
the class ProcessorDefinition method setHeader.
/**
* Adds a processor which sets the header on the IN message
*
* @param name the header name
* @param supplier the supplier used to set the header
* @return the builder
*/
@SuppressWarnings("unchecked")
public Type setHeader(String name, final Supplier<Object> supplier) {
SetHeaderDefinition answer = new SetHeaderDefinition(name, new ExpressionAdapter() {
@Override
public Object evaluate(Exchange exchange) {
return supplier.get();
}
});
addOutput(answer);
return (Type) this;
}
use of org.apache.camel.support.ExpressionAdapter in project camel by apache.
the class SetHeaderUsingDslExpressionsTest method testUseExpression.
public void testUseExpression() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from("direct:start").setHeader("foo").expression(new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
return "ABC";
}
}).to("mock:result");
}
});
template.sendBodyAndHeader("direct:start", body, "bar", "ABC");
assertMockEndpointsSatisfied();
}
Aggregations