use of org.apache.camel.Expression in project camel by apache.
the class TokenizeLanguage method createExpression.
/**
* Creates a tokenize expression.
*/
public Expression createExpression() {
ObjectHelper.notNull(token, "token");
// validate some invalid combinations
if (endToken != null && inheritNamespaceTagName != null) {
throw new IllegalArgumentException("Cannot have both xml and pair tokenizer enabled.");
}
if (isXml() && (endToken != null || includeTokens)) {
throw new IllegalArgumentException("Cannot have both xml and pair tokenizer enabled.");
}
Expression answer = null;
if (isXml()) {
answer = ExpressionBuilder.tokenizeXMLExpression(token, inheritNamespaceTagName);
} else if (endToken != null) {
answer = ExpressionBuilder.tokenizePairExpression(token, endToken, includeTokens);
}
if (answer == null) {
// use the regular tokenizer
Expression exp = headerName == null ? ExpressionBuilder.bodyExpression() : ExpressionBuilder.headerExpression(headerName);
if (regex) {
answer = ExpressionBuilder.regexTokenizeExpression(exp, token);
} else {
answer = ExpressionBuilder.tokenizeExpression(exp, token);
}
if (group == 0 && skipFirst) {
// wrap in skip first (if group then it has its own skip first logic)
answer = ExpressionBuilder.skipFirstExpression(answer);
}
}
// if group then wrap answer in group expression
if (group > 0) {
if (isXml()) {
answer = ExpressionBuilder.groupXmlIteratorExpression(answer, group);
} else {
answer = ExpressionBuilder.groupIteratorExpression(answer, token, group, skipFirst);
}
}
return answer;
}
use of org.apache.camel.Expression in project camel by apache.
the class ServiceCallDefinition method createProcessor.
// *****************************
// Processor Factory
// *****************************
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
final CamelContext camelContext = routeContext.getCamelContext();
final ServiceDiscovery serviceDiscovery = retrieveServiceDiscovery(camelContext);
final ServiceFilter serviceFilter = retrieveServiceFilter(camelContext);
final ServiceChooser serviceChooser = retrieveServiceChooser(camelContext);
final LoadBalancer loadBalancer = retrieveLoadBalancer(camelContext);
final Expression expression = retrieveExpression(camelContext);
if (loadBalancer instanceof CamelContextAware) {
((CamelContextAware) loadBalancer).setCamelContext(camelContext);
}
if (loadBalancer instanceof ServiceDiscoveryAware) {
((ServiceDiscoveryAware) loadBalancer).setServiceDiscovery(serviceDiscovery);
}
if (loadBalancer instanceof ServiceFilterAware) {
((ServiceFilterAware) loadBalancer).setServiceFilter(serviceFilter);
}
if (loadBalancer instanceof ServiceChooserAware) {
((ServiceChooserAware) loadBalancer).setServiceChooser(serviceChooser);
}
// The component is used to configure the default scheme to use (eg camel component name).
// The component configured on EIP takes precedence vs configured on configuration.
String component = this.component;
if (component == null) {
ServiceCallConfigurationDefinition conf = retrieveConfig(camelContext);
if (conf != null) {
component = conf.getComponent();
}
}
if (component == null) {
ServiceCallConfigurationDefinition conf = retrieveDefaultConfig(camelContext);
if (conf != null) {
component = conf.getComponent();
}
}
return new DefaultServiceCallProcessor(camelContext, name, component, uri, pattern, loadBalancer, expression);
}
use of org.apache.camel.Expression in project camel by apache.
the class ServiceCallDefinition method retrieveExpression.
// ******************************************
// Expression
// ******************************************
private Expression retrieveExpression(CamelContext camelContext, Function<CamelContext, ServiceCallConfigurationDefinition> function) throws Exception {
Expression answer = null;
ServiceCallConfigurationDefinition config = function.apply(camelContext);
if (config != null) {
if (config.getExpressionConfiguration() != null) {
answer = config.getExpressionConfiguration().newInstance(camelContext);
} else {
answer = retrieve(Expression.class, camelContext, config::getExpression, config::getExpressionRef);
}
}
return answer;
}
use of org.apache.camel.Expression in project camel by apache.
the class ServiceCallExpressionConfiguration method newInstance.
// *************************************************************************
// Factory
// *************************************************************************
@Override
public Expression newInstance(CamelContext camelContext) throws Exception {
ObjectHelper.notNull(factoryKey, "Expression factoryKey");
Expression answer;
// First try to find the factory from the registry.
ServiceExpressionFactory factory = CamelContextHelper.lookup(camelContext, factoryKey, ServiceExpressionFactory.class);
if (factory != null) {
// If a factory is found in the registry do not re-configure it as
// it should be pre-configured.
answer = factory.newInstance(camelContext);
} else {
Class<?> type;
try {
// Then use Service factory.
type = camelContext.getFactoryFinder(RESOURCE_PATH).findClass(factoryKey);
} catch (Exception e) {
throw new NoFactoryAvailableException(RESOURCE_PATH + factoryKey, e);
}
if (type != null) {
if (ServiceExpressionFactory.class.isAssignableFrom(type)) {
factory = (ServiceExpressionFactory) camelContext.getInjector().newInstance(type);
} else {
throw new IllegalArgumentException("Resolving Expression: " + factoryKey + " detected type conflict: Not a ExpressionFactory implementation. Found: " + type.getName());
}
}
try {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(this, parameters, null, false);
parameters.put("properties", getPropertiesAsMap(camelContext));
postProcessFactoryParameters(camelContext, parameters);
IntrospectionSupport.setProperties(factory, parameters);
answer = factory.newInstance(camelContext);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
return answer;
}
use of org.apache.camel.Expression in project camel by apache.
the class ExpressionDefinition method getLabel.
/**
* Returns some descriptive text to describe this node
*/
public String getLabel() {
Predicate predicate = getPredicate();
if (predicate != null) {
return predicate.toString();
}
Expression expressionValue = getExpressionValue();
if (expressionValue != null) {
return expressionValue.toString();
}
String exp = getExpression();
return exp != null ? exp : "";
}
Aggregations