From 78126c74a57b75fe978a4da5dbf45e462c6a4eda Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Sun, 4 Feb 2024 09:42:34 +0100 Subject: [PATCH] Lang5 (#12986) CAMEL-20378: Languages should be thread-safe and be configured only via properties array, all in the same way. --- .../camel/language/bean/BeanLanguage.java | 18 ++++++--------- .../datasonnet/DatasonnetLanguage.java | 23 ++----------------- .../joor/JavaAnnotationExpressionFactory.java | 4 ++-- .../camel/language/joor/JavaLanguage.java | 4 ++-- .../joor/JoorAnnotationExpressionFactory.java | 4 ++-- .../apache/camel/language/jq/JqLanguage.java | 2 +- .../camel/jsonpath/JsonPathLanguage.java | 6 +---- .../component/language/LanguageEndpoint.java | 14 +++++------ .../component/language/LanguageProducer.java | 3 ++- .../camel/language/xquery/XQueryLanguage.java | 6 +---- .../camel/language/wasm/WasmLanguage.java | 6 +---- .../camel/language/xpath/XPathLanguage.java | 14 ++++------- .../catalog/impl/AbstractCamelCatalog.java | 2 +- .../camel/language/csimple/CSimpleHelper.java | 10 ++++---- .../language/csimple/CSimpleLanguage.java | 2 +- .../simple/SimpleExpressionBuilder.java | 14 +++++------ .../simple/ast/SimpleFunctionExpression.java | 10 ++++---- .../language/JavaExpressionReifier.java | 4 ++-- .../language/JoorExpressionReifier.java | 4 ++-- .../language/MethodCallExpressionReifier.java | 14 +++++------ .../SingleInputTypedLanguageSupport.java | 4 ++-- .../camel/support/TypedLanguageSupport.java | 12 +--------- .../support/builder/ExpressionBuilder.java | 4 ++-- 23 files changed, 68 insertions(+), 116 deletions(-) diff --git a/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java index 785dddb520423..2939f1e8b132f 100644 --- a/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java +++ b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java @@ -86,10 +86,6 @@ public boolean configure(CamelContext camelContext, Object target, String name, case "validate": setValidate(PropertyConfigurerSupport.property(camelContext, Boolean.class, value)); return true; - case "resultType": - case "resulttype": - setResultType(PropertyConfigurerSupport.property(camelContext, Class.class, value)); - return true; default: return false; } @@ -114,19 +110,19 @@ public Predicate createPredicate(String expression, Object[] properties) { public Expression createExpression(String expression, Object[] properties) { BeanExpression answer = null; - String method = property(String.class, properties, 1, null); - Object bean = property(Object.class, properties, 0, null); + Object bean = property(Object.class, properties, 1, null); + String method = property(String.class, properties, 2, null); if (bean != null) { answer = new BeanExpression(bean, method); } if (answer == null) { - Class beanType = property(Class.class, properties, 2, null); + Class beanType = property(Class.class, properties, 3, null); if (beanType != null) { answer = new BeanExpression(beanType, method); } } if (answer == null) { - String ref = property(String.class, properties, 3, null); + String ref = property(String.class, properties, 4, null); if (ref != null) { answer = new BeanExpression(ref, method); } @@ -137,14 +133,14 @@ public Expression createExpression(String expression, Object[] properties) { if (answer == null) { throw new IllegalArgumentException("Bean language requires bean, beanType, or ref argument"); } - Object scope = property(Object.class, properties, 4, null); + Object scope = property(Object.class, properties, 5, null); if (scope instanceof BeanScope) { answer.setScope((BeanScope) scope); } else if (scope != null) { answer.setScope(BeanScope.valueOf(scope.toString())); } - answer.setValidate(property(boolean.class, properties, 5, isValidate())); - answer.setResultType(property(Class.class, properties, 6, getResultType())); + answer.setValidate(property(boolean.class, properties, 6, isValidate())); + answer.setResultType(property(Class.class, properties, 0, null)); answer.setBeanComponent(beanComponent); answer.setParameterMappingStrategy(parameterMappingStrategy); answer.setSimple(simple); diff --git a/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetLanguage.java b/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetLanguage.java index 2c53f177adb7c..b3f5b24187c20 100644 --- a/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetLanguage.java +++ b/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/DatasonnetLanguage.java @@ -27,19 +27,16 @@ import com.datasonnet.document.MediaType; import io.github.classgraph.ClassGraph; import io.github.classgraph.ScanResult; -import org.apache.camel.CamelContext; import org.apache.camel.Expression; import org.apache.camel.Predicate; -import org.apache.camel.spi.PropertyConfigurer; import org.apache.camel.spi.annotations.Language; import org.apache.camel.support.LRUCacheFactory; import org.apache.camel.support.TypedLanguageSupport; -import org.apache.camel.support.component.PropertyConfigurerSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Language("datasonnet") -public class DatasonnetLanguage extends TypedLanguageSupport implements PropertyConfigurer { +public class DatasonnetLanguage extends TypedLanguageSupport { private static final Logger LOG = LoggerFactory.getLogger(DatasonnetLanguage.class); private static final Map CLASSPATH_IMPORTS = new HashMap<>(); @@ -84,7 +81,7 @@ public Expression createExpression(String expression, Object[] properties) { expression = loadResource(expression); DatasonnetExpression answer = new DatasonnetExpression(expression); - answer.setResultType(property(Class.class, properties, 0, getResultType())); + answer.setResultType(property(Class.class, properties, 0, null)); String mediaType = property(String.class, properties, 1, null); if (mediaType != null) { answer.setBodyMediaType(MediaType.valueOf(mediaType)); @@ -111,20 +108,4 @@ public Map getClasspathImports() { return CLASSPATH_IMPORTS; } - @Override - public boolean configure(CamelContext camelContext, Object target, String name, Object value, boolean ignoreCase) { - if (target != this) { - throw new IllegalStateException("Can only configure our own instance !"); - } - - switch (ignoreCase ? name.toLowerCase() : name) { - case "resultType": - case "resulttype": - setResultType(PropertyConfigurerSupport.property(camelContext, Class.class, value)); - return true; - default: - return false; - } - } - } diff --git a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaAnnotationExpressionFactory.java b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaAnnotationExpressionFactory.java index ed013ce72b111..90921febaeaba 100644 --- a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaAnnotationExpressionFactory.java +++ b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaAnnotationExpressionFactory.java @@ -35,10 +35,10 @@ public Expression createExpression( if (resultType.equals(Object.class)) { resultType = expressionReturnType; } - params[1] = resultType; + params[0] = resultType; if (annotation instanceof Java) { Java joorAnnotation = (Java) annotation; - params[0] = joorAnnotation.preCompile(); + params[1] = joorAnnotation.preCompile(); params[2] = joorAnnotation.singleQuotes(); } String expression = getExpressionFromAnnotation(annotation); diff --git a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaLanguage.java b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaLanguage.java index 057222b1dfaa9..1b246cac11a7d 100644 --- a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaLanguage.java +++ b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JavaLanguage.java @@ -129,8 +129,8 @@ public Predicate createPredicate(String expression, Object[] properties) { public Expression createExpression(String expression, Object[] properties) { JoorExpression answer = new JoorExpression(expression); answer.setCompiler(compiler); - answer.setPreCompile(property(boolean.class, properties, 0, preCompile)); - answer.setResultType(property(Class.class, properties, 1, getResultType())); + answer.setResultType(property(Class.class, properties, 0, null)); + answer.setPreCompile(property(boolean.class, properties, 1, preCompile)); answer.setSingleQuotes(property(boolean.class, properties, 2, singleQuotes)); if (getCamelContext() != null) { answer.init(getCamelContext()); diff --git a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorAnnotationExpressionFactory.java b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorAnnotationExpressionFactory.java index f93574d743186..d8aa28956e934 100644 --- a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorAnnotationExpressionFactory.java +++ b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorAnnotationExpressionFactory.java @@ -35,10 +35,10 @@ public Expression createExpression( if (resultType.equals(Object.class)) { resultType = expressionReturnType; } - params[1] = resultType; + params[0] = resultType; if (annotation instanceof Joor) { Joor joorAnnotation = (Joor) annotation; - params[0] = joorAnnotation.preCompile(); + params[1] = joorAnnotation.preCompile(); params[2] = joorAnnotation.singleQuotes(); } String expression = getExpressionFromAnnotation(annotation); diff --git a/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqLanguage.java b/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqLanguage.java index 9be23525b60e2..2686e84b43766 100644 --- a/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqLanguage.java +++ b/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqLanguage.java @@ -58,7 +58,7 @@ public void stop() { @Override public Expression createExpression(Expression source, String expression, Object[] properties) { JqExpression answer = new JqExpression(Scope.newChildScope(rootScope), expression); - answer.setResultType(property(Class.class, properties, 0, getResultType())); + answer.setResultType(property(Class.class, properties, 0, null)); answer.setSource(source); if (getCamelContext() != null) { answer.init(getCamelContext()); diff --git a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathLanguage.java b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathLanguage.java index c370359cb3a35..233b86899006c 100644 --- a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathLanguage.java +++ b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathLanguage.java @@ -104,7 +104,7 @@ protected ExpressionAdapter doCreateJsonPathExpression( JsonPathExpression answer = new JsonPathExpression(expression); answer.setSource(source); answer.setPredicate(predicate); - answer.setResultType(property(Class.class, properties, 0, getResultType())); + answer.setResultType(property(Class.class, properties, 0, null)); answer.setSuppressExceptions(property(boolean.class, properties, 4, isSuppressExceptions())); answer.setAllowSimple(property(boolean.class, properties, 5, isAllowSimple())); answer.setAllowEasyPredicate(property(boolean.class, properties, 6, isAllowEasyPredicate())); @@ -151,10 +151,6 @@ public boolean configure(CamelContext camelContext, Object target, String name, } switch (ignoreCase ? name.toLowerCase() : name) { - case "resulttype": - case "resultType": - setResultType(PropertyConfigurerSupport.property(camelContext, Class.class, value)); - return true; case "suppressexceptions": case "suppressExceptions": setSuppressExceptions(PropertyConfigurerSupport.property(camelContext, boolean.class, value)); diff --git a/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java b/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java index b11f673bedef2..22adc8a1dca09 100644 --- a/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java +++ b/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java @@ -37,7 +37,6 @@ import org.apache.camel.support.CamelContextHelper; import org.apache.camel.support.EndpointHelper; import org.apache.camel.support.ResourceHelper; -import org.apache.camel.support.TypedLanguageSupport; import org.apache.camel.util.IOHelper; /** @@ -48,7 +47,8 @@ * defined as well. */ @UriEndpoint(firstVersion = "2.5.0", scheme = "language", title = "Language", syntax = "language:languageName:resourceUri", - remote = false, producerOnly = true, category = { Category.CORE, Category.SCRIPT }, headersClass = LanguageConstants.class) + remote = false, producerOnly = true, category = { Category.CORE, Category.SCRIPT }, + headersClass = LanguageConstants.class) public class LanguageEndpoint extends ResourceEndpoint { private Language language; private Expression expression; @@ -73,6 +73,7 @@ public class LanguageEndpoint extends ResourceEndpoint { private boolean contentCache; @UriParam private String resultType; + private volatile Class resultTypeClass; public LanguageEndpoint() { // enable cache by default @@ -93,16 +94,15 @@ protected void doInit() throws Exception { if (language == null && languageName != null) { language = getCamelContext().resolveLanguage(languageName); } - if (language instanceof TypedLanguageSupport && resultType != null) { - Class clazz = getCamelContext().getClassResolver().resolveMandatoryClass(resultType); - ((TypedLanguageSupport) language).setResultType(clazz); + if (resultTypeClass == null && resultType != null) { + resultTypeClass = getCamelContext().getClassResolver().resolveMandatoryClass(resultType); } if (cacheScript && expression == null && script != null) { boolean external = script.startsWith("file:") || script.startsWith("http:"); if (!external) { // we can pre optimize this as the script can be loaded from classpath or registry etc script = resolveScript(script); - expression = language.createExpression(script); + expression = language.createExpression(script, new Object[] { resultTypeClass }); } } if (expression != null) { @@ -114,7 +114,7 @@ protected void doInit() throws Exception { public Producer createProducer() throws Exception { if (cacheScript && expression == null && script != null) { script = resolveScript(script); - expression = language.createExpression(script); + expression = language.createExpression(script, new Object[] { resultTypeClass }); expression.init(getCamelContext()); } diff --git a/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageProducer.java b/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageProducer.java index 966d0f78a7a47..1be8a01cfadbf 100644 --- a/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageProducer.java +++ b/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageProducer.java @@ -97,7 +97,8 @@ public void process(Exchange exchange) throws Exception { // if we have a text based script then use and evaluate it if (script != null) { // create the expression from the script - exp = getEndpoint().getLanguage().createExpression(script); + Class type = resultType != Object.class ? resultType : null; + exp = getEndpoint().getLanguage().createExpression(script, new Object[] { type }); exp.init(getEndpoint().getCamelContext()); // expression was resolved from resource getEndpoint().setContentResolvedFromResource(true); diff --git a/components/camel-saxon/src/main/java/org/apache/camel/language/xquery/XQueryLanguage.java b/components/camel-saxon/src/main/java/org/apache/camel/language/xquery/XQueryLanguage.java index 6fd0336281733..cf1554b837ce2 100644 --- a/components/camel-saxon/src/main/java/org/apache/camel/language/xquery/XQueryLanguage.java +++ b/components/camel-saxon/src/main/java/org/apache/camel/language/xquery/XQueryLanguage.java @@ -53,7 +53,7 @@ public Expression createExpression(Expression source, String expression, Object[ protected void configureBuilder(XQueryBuilder builder, Object[] properties, Expression source) { builder.setSource(source); - Class clazz = property(Class.class, properties, 0, getResultType()); + Class clazz = property(Class.class, properties, 0, null); if (clazz != null) { builder.setResultType(clazz); } @@ -68,10 +68,6 @@ public boolean configure(CamelContext camelContext, Object target, String name, throw new IllegalStateException("Can only configure our own instance !"); } switch (ignoreCase ? name.toLowerCase() : name) { - case "resulttype": - case "resultType": - setResultType(PropertyConfigurerSupport.property(camelContext, Class.class, value)); - return true; case "configuration": case "Configuration": setConfiguration(PropertyConfigurerSupport.property(camelContext, Configuration.class, value)); diff --git a/components/camel-wasm/src/main/java/org/apache/camel/language/wasm/WasmLanguage.java b/components/camel-wasm/src/main/java/org/apache/camel/language/wasm/WasmLanguage.java index 62632ea79ae6d..07579ec2418e8 100644 --- a/components/camel-wasm/src/main/java/org/apache/camel/language/wasm/WasmLanguage.java +++ b/components/camel-wasm/src/main/java/org/apache/camel/language/wasm/WasmLanguage.java @@ -49,10 +49,6 @@ public boolean configure(CamelContext camelContext, Object target, String name, } switch (ignoreCase ? name.toLowerCase() : name) { - case "resulttype": - case "resultType": - setResultType(PropertyConfigurerSupport.property(camelContext, Class.class, value)); - return true; case "module": setModule(PropertyConfigurerSupport.property(camelContext, String.class, value)); return true; @@ -79,7 +75,7 @@ public Predicate createPredicate(String expression, Object[] properties) { @Override public Expression createExpression(String expression, Object[] properties) { WasmExpression answer = new WasmExpression(expression); - answer.setResultType(property(Class.class, properties, 0, getResultType())); + answer.setResultType(property(Class.class, properties, 0, null)); answer.setModule(property(String.class, properties, 1, getModule())); if (getCamelContext() != null) { answer.init(getCamelContext()); diff --git a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java index a0e158f5010b7..2156f392c1ade 100644 --- a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java +++ b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java @@ -130,7 +130,11 @@ public void setPreCompile(Boolean preCompile) { protected void configureBuilder(XPathBuilder builder, Object[] properties, Expression source) { builder.setSource(source); - Class clazz = property(Class.class, properties, 4, documentType); + Class clazz = property(Class.class, properties, 0, null); + if (clazz != null) { + builder.setResultType(clazz); + } + clazz = property(Class.class, properties, 4, documentType); if (clazz != null) { builder.setDocumentType(clazz); } @@ -138,10 +142,6 @@ protected void configureBuilder(XPathBuilder builder, Object[] properties, Expre if (qname != null) { builder.setResultQName(qname); } - clazz = property(Class.class, properties, 0, getResultType()); - if (clazz != null) { - builder.setResultType(clazz); - } Boolean bool = property(Boolean.class, properties, 6, saxon); if (bool != null) { builder.setUseSaxon(bool); @@ -185,10 +185,6 @@ public boolean configure(CamelContext camelContext, Object target, String name, } switch (ignoreCase ? name.toLowerCase() : name) { case "resulttype": - case "resultType": - setResultType(PropertyConfigurerSupport.property(camelContext, Class.class, value)); - return true; - case "resultqname": case "resultQName": setResultQName(PropertyConfigurerSupport.property(camelContext, QName.class, value)); return true; diff --git a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java index 0a6126ac7290f..84d998fa84046 100644 --- a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java +++ b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java @@ -1457,7 +1457,7 @@ private LanguageValidationResult doValidateLanguage( } return answer; } catch (NoSuchMethodException e) { - // ignore + // ignore } if (predicate) { instance.getClass().getMethod("createPredicate", String.class).invoke(instance, text); diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java index 4bf6cdd5f093d..6d2200a866b9b 100644 --- a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java +++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java @@ -380,11 +380,11 @@ public static Object bean(Exchange exchange, Language bean, String ref, String m } } - Object[] properties = new Object[5]; - properties[2] = type; - properties[3] = ref; - properties[1] = method; - properties[4] = scope; + Object[] properties = new Object[7]; + properties[3] = type; + properties[4] = ref; + properties[2] = method; + properties[5] = scope; Expression exp = bean.createExpression(null, properties); exp.init(exchange.getContext()); return exp.evaluate(exchange, Object.class); diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleLanguage.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleLanguage.java index 648974bdc0961..0c38af295e0f4 100644 --- a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleLanguage.java +++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleLanguage.java @@ -150,7 +150,7 @@ public Predicate createPredicate(String expression) { @Override public Expression createExpression(String expression, Object[] properties) { - Class resultType = property(Class.class, properties, 0, getResultType()); + Class resultType = property(Class.class, properties, 0, null); if (Boolean.class == resultType || boolean.class == resultType) { // we want it compiled as a predicate return (Expression) createPredicate(expression); diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java index 9ec436ae6ec76..47fa8d95fb786 100644 --- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java +++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java @@ -691,7 +691,7 @@ public Object evaluate(Exchange exchange) { } catch (InvalidPayloadException e) { throw CamelExecutionException.wrapCamelExecutionException(exchange, e); } - Expression ognlExp = bean.createExpression(null, new Object[] { body, ognl }); + Expression ognlExp = bean.createExpression(null, new Object[] { null, body, ognl }); ognlExp.init(exchange.getContext()); return ognlExp.evaluate(exchange, Object.class); } @@ -772,7 +772,7 @@ public Object evaluate(Exchange exchange) { if (msg != null) { // ognl is able to evaluate method name if it contains nested functions // so we should not eager evaluate ognl as a string - Expression ognlExp = bean.createExpression(null, new Object[] { msg, ognl }); + Expression ognlExp = bean.createExpression(null, new Object[] { null, msg, ognl }); ognlExp.init(exchange.getContext()); return ognlExp.evaluate(exchange, Object.class); } else { @@ -818,7 +818,7 @@ public Object evaluate(Exchange exchange) { if (body != null) { // ognl is able to evaluate method name if it contains nested functions // so we should not eager evaluate ognl as a string - Expression ognlExp = bean.createExpression(null, new Object[] { body, ognl }); + Expression ognlExp = bean.createExpression(null, new Object[] { null, body, ognl }); ognlExp.init(exchange.getContext()); return ognlExp.evaluate(exchange, Object.class); } else { @@ -854,7 +854,7 @@ public static Expression exchangeOgnlExpression(final String ognl) { public Object evaluate(Exchange exchange) { // ognl is able to evaluate method name if it contains nested functions // so we should not eager evaluate ognl as a string - Expression ognlExp = bean.createExpression(null, new Object[] { exchange, ognl }); + Expression ognlExp = bean.createExpression(null, new Object[] { null, exchange, ognl }); ognlExp.init(exchange.getContext()); return ognlExp.evaluate(exchange, Object.class); } @@ -915,7 +915,7 @@ public Object evaluate(Exchange exchange) { if (body == null) { return null; } - Expression ognlExp = bean.createExpression(null, new Object[] { body, ognl }); + Expression ognlExp = bean.createExpression(null, new Object[] { null, body, ognl }); ognlExp.init(exchange.getContext()); return ognlExp.evaluate(exchange, Object.class); } @@ -1063,7 +1063,7 @@ public Object evaluate(Exchange exchange) { // ognl is able to evaluate method name if it contains nested functions // so we should not eager evaluate ognl as a string - Expression ognlExp = bean.createExpression(null, new Object[] { exception, ognl }); + Expression ognlExp = bean.createExpression(null, new Object[] { null, exception, ognl }); ognlExp.init(exchange.getContext()); return ognlExp.evaluate(exchange, Object.class); } @@ -1145,7 +1145,7 @@ public Object evaluate(Exchange exchange) { return null; } if (method != null) { - Expression exp = beanLanguage.createExpression(null, new Object[] { property, method }); + Expression exp = beanLanguage.createExpression(null, new Object[] { null, property, method }); exp.init(exchange.getContext()); return exp.evaluate(exchange, Object.class); } else { diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java index a9276250d2e37..89ca1043278d1 100644 --- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java +++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java @@ -265,11 +265,11 @@ private Expression createSimpleExpression(CamelContext camelContext, String func } // there are parameters then map them into properties - Object[] properties = new Object[5]; - properties[2] = type; - properties[3] = ref; - properties[1] = method; - properties[4] = scope; + Object[] properties = new Object[7]; + properties[3] = type; + properties[4] = ref; + properties[2] = method; + properties[5] = scope; return bean.createExpression(null, properties); } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JavaExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JavaExpressionReifier.java index d48571dfb64f8..4245dc83d4039 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JavaExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JavaExpressionReifier.java @@ -29,8 +29,8 @@ public JavaExpressionReifier(CamelContext camelContext, ExpressionDefinition def @Override protected Object[] createProperties() { Object[] properties = new Object[3]; - properties[0] = parseBoolean(definition.getPreCompile()); - properties[1] = definition.getResultType(); + properties[0] = definition.getResultType(); + properties[1] = parseBoolean(definition.getPreCompile()); properties[2] = parseBoolean(definition.getSingleQuotes()); return properties; } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JoorExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JoorExpressionReifier.java index c986b64535a20..71b787bdd8117 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JoorExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JoorExpressionReifier.java @@ -30,8 +30,8 @@ public JoorExpressionReifier(CamelContext camelContext, ExpressionDefinition def @Override protected Object[] createProperties() { Object[] properties = new Object[3]; - properties[0] = parseBoolean(definition.getPreCompile()); - properties[1] = definition.getResultType(); + properties[0] = definition.getResultType(); + properties[1] = parseBoolean(definition.getPreCompile()); properties[2] = parseBoolean(definition.getSingleQuotes()); return properties; } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/MethodCallExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/MethodCallExpressionReifier.java index 2269903b5c6c9..7a6530c1e7cb5 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/MethodCallExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/MethodCallExpressionReifier.java @@ -31,13 +31,13 @@ public MethodCallExpressionReifier(CamelContext camelContext, ExpressionDefiniti @Override protected Object[] createProperties() { Object[] properties = new Object[7]; - properties[0] = definition.getInstance(); - properties[1] = parseString(definition.getMethod()); - properties[2] = definition.getBeanType(); - properties[3] = parseString(definition.getRef()); - properties[4] = parseString(definition.getScope()); - properties[5] = parseString(definition.getValidate()); - properties[6] = definition.getResultType(); + properties[0] = definition.getResultType(); + properties[1] = definition.getInstance(); + properties[2] = parseString(definition.getMethod()); + properties[3] = definition.getBeanType(); + properties[4] = parseString(definition.getRef()); + properties[5] = parseString(definition.getScope()); + properties[6] = parseString(definition.getValidate()); return properties; } diff --git a/core/camel-support/src/main/java/org/apache/camel/support/SingleInputTypedLanguageSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/SingleInputTypedLanguageSupport.java index c57f205534444..caf18859500f5 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/SingleInputTypedLanguageSupport.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/SingleInputTypedLanguageSupport.java @@ -39,7 +39,7 @@ public Expression createExpression(String expression) { @Override public Expression createExpression(String expression, Object[] properties) { - Class type = property(Class.class, properties, 0, getResultType()); + Class type = property(Class.class, properties, 0, null); String variable = property(String.class, properties, 1, null); String header = property(String.class, properties, 2, null); String property = property(String.class, properties, 3, null); @@ -52,7 +52,7 @@ public Expression createExpression(String expression, Object[] properties) { @Override public Predicate createPredicate(String expression, Object[] properties) { - Class type = property(Class.class, properties, 0, getResultType()); + Class type = property(Class.class, properties, 0, null); String variable = property(String.class, properties, 1, null); String header = property(String.class, properties, 2, null); String property = property(String.class, properties, 3, null); diff --git a/core/camel-support/src/main/java/org/apache/camel/support/TypedLanguageSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/TypedLanguageSupport.java index 921f1d1c5b7f8..5bd2b4bbe9206 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/TypedLanguageSupport.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/TypedLanguageSupport.java @@ -25,19 +25,9 @@ */ public abstract class TypedLanguageSupport extends LanguageSupport { - private Class resultType; - - public Class getResultType() { - return resultType; - } - - public void setResultType(Class resultType) { - this.resultType = resultType; - } - @Override public Expression createExpression(String expression, Object[] properties) { - Class type = property(Class.class, properties, 0, getResultType()); + Class type = property(Class.class, properties, 0, null); if (type == null || type == Object.class) { return createExpression(expression); } diff --git a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java index 47cef3ba81cfe..dbd7d6e3a3402 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java @@ -2299,7 +2299,7 @@ public Object evaluate(Exchange exchange) { public void init(CamelContext context) { super.init(context); final Language language = context.resolveLanguage("bean"); - this.exp = language.createExpression(null, new Object[] { bean, method }); + this.exp = language.createExpression(null, new Object[] { null, bean, method }); this.exp.init(context); } @@ -2316,7 +2316,7 @@ public static Expression beanExpression(final Expression expression, final Strin @Override public Object evaluate(Exchange exchange) { Object bean = expression.evaluate(exchange, Object.class); - Expression exp = language.createExpression(null, new Object[] { bean, method }); + Expression exp = language.createExpression(null, new Object[] { null, bean, method }); exp.init(exchange.getContext()); return exp.evaluate(exchange, Object.class); }