This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch lang6 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1398ec2ff34744c8a322d0115ddc5d6509ed36fa Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Feb 4 19:25:45 2024 +0100 CAMEL-20378: Languages should be thread-safe and be configured only via properties array, all in the same way. --- .../org/apache/camel/catalog/languages/xpath.json | 7 ++-- .../org/apache/camel/catalog/languages/xquery.json | 14 ++++---- .../apache/camel/catalog/languages/xtokenize.json | 14 ++++---- .../org/apache/camel/catalog/models/xpath.json | 7 ++-- .../org/apache/camel/catalog/models/xquery.json | 15 ++++---- .../org/apache/camel/catalog/models/xtokenize.json | 14 ++++---- .../org/apache/camel/language/xquery/xquery.json | 15 ++++---- .../src/main/docs/xquery-component.adoc | 2 +- .../camel-saxon/src/main/docs/xquery-language.adoc | 2 +- .../apache/camel/language/XQueryLanguageTest.java | 16 +++++++-- .../saxon/SpringXQueryTransformIssueTest.xml | 2 +- .../xquery/xqueryWithExplicitTypeContext.xml | 2 +- .../camel/language/xtokenizer/xtokenize.json | 14 ++++---- .../language/xtokenizer/XMLTokenizeLanguage.java | 6 ++++ .../camel/language/XMLTokenizeLanguageTest.java | 33 ++++++++++++++--- .../org/apache/camel/language/xpath/xpath.json | 5 +-- .../camel/language/tokenizer/TokenizeLanguage.java | 6 ++++ .../org/apache/camel/model/language/xpath.json | 3 +- .../org/apache/camel/model/language/xquery.json | 15 ++++---- .../apache/camel/model/ExpressionNodeHelper.java | 4 +-- .../camel/model/language/XPathExpression.java | 24 ++++++------- .../camel/model/language/XQueryExpression.java | 28 --------------- .../language/DatasonnetExpressionReifier.java | 2 +- .../reifier/language/JavaExpressionReifier.java | 2 +- .../reifier/language/JoorExpressionReifier.java | 2 +- .../language/JsonPathExpressionReifier.java | 2 +- .../language/MethodCallExpressionReifier.java | 2 +- .../reifier/language/SimpleExpressionReifier.java | 2 +- .../SingleInputTypedExpressionReifier.java | 2 +- .../language/TokenizerExpressionReifier.java | 4 +-- .../reifier/language/TypedExpressionReifier.java | 34 ++++++++++-------- .../reifier/language/WasmExpressionReifier.java | 2 +- .../language/XMLTokenizerExpressionReifier.java | 4 +-- .../reifier/language/XPathExpressionReifier.java | 13 ++----- .../reifier/language/XQueryExpressionReifier.java | 21 ++--------- .../file/FileConsumerFailureHandledTest.java | 8 ++--- .../AbstractSingleInputTypedLanguageTest.java | 41 ++++++++++++---------- .../camel/language/AbstractTypedLanguageTest.java | 26 +++++++++++--- .../apache/camel/language/XPathLanguageTest.java | 8 +++-- .../support/SingleInputTypedLanguageSupport.java | 15 +++++++- .../java/org/apache/camel/xml/in/ModelParser.java | 11 +++--- .../java/org/apache/camel/xml/out/ModelWriter.java | 3 +- .../org/apache/camel/yaml/out/ModelWriter.java | 3 +- .../dsl/yaml/deserializers/ModelDeserializers.java | 20 +++++------ .../generated/resources/schema/camelYamlDsl.json | 22 ++++++------ 45 files changed, 265 insertions(+), 232 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xpath.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xpath.json index b90d9ef9185..7de222cc05f 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xpath.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xpath.json @@ -19,7 +19,7 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, "documentType": { "index": 2, "kind": "attribute", "displayName": "Document Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class for document type The default value is org.w3c.dom.Document" }, - "resultType": { "index": 3, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "NUMBER", "STRING", "BOOLEAN", "NODESET", "NODE" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NODESET", "description": "Sets the class name of the result type (type from output) The default result type is NodeSet" }, + "resultQName": { "index": 3, "kind": "attribute", "displayName": "Result QName", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "NUMBER", "STRING", "BOOLEAN", "NODESET", "NODE" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NODESET", "description": "Sets the output type supported by XPath." }, "saxon": { "index": 4, "kind": "attribute", "displayName": "Saxon", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to use Saxon." }, "factoryRef": { "index": 5, "kind": "attribute", "displayName": "Factory Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "References to a custom XPathFactory to lookup in the registry" }, "objectModel": { "index": 6, "kind": "attribute", "displayName": "Object Model", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The XPath object model to use" }, @@ -27,9 +27,10 @@ "threadSafety": { "index": 8, "kind": "attribute", "displayName": "Thread Safety", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable thread-safety for the returned result of the xpath expression. This applies to when using NODESET as the result type, and the returned set has multiple elements. In this situation there can be threa [...] "preCompile": { "index": 9, "kind": "attribute", "displayName": "Pre Compile", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to enable pre-compiling the xpath expression during initialization phase. pre-compile is enabled by default. This can be used to turn off, for example in cases the compilation phase is desired at the starting phas [...] "namespace": { "index": 10, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 11, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, + "variableName": { "index": 11, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, "headerName": { "index": 12, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, "propertyName": { "index": 13, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, - "trim": { "index": 14, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } + "resultType": { "index": 14, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "trim": { "index": 15, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xquery.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xquery.json index 6c282f23bea..6cc4dad67d2 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xquery.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xquery.json @@ -18,13 +18,13 @@ "properties": { "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, - "resultType": { "index": 2, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, - "type": { "index": 3, "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name of the result type (type from output) The default result type is NodeSet" }, - "configurationRef": { "index": 4, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, - "namespace": { "index": 5, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 6, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, - "headerName": { "index": 7, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, - "propertyName": { "index": 8, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "type": { "index": 2, "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name of the result type (type from output) The default result type is NodeSet" }, + "configurationRef": { "index": 3, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, + "namespace": { "index": 4, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, + "variableName": { "index": 5, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, + "headerName": { "index": 6, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, + "propertyName": { "index": 7, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 8, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, "trim": { "index": 9, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xtokenize.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xtokenize.json index c70f189e3f7..08b3e202074 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xtokenize.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/xtokenize.json @@ -18,13 +18,13 @@ "properties": { "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, - "resultType": { "index": 2, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, - "mode": { "index": 3, "kind": "attribute", "displayName": "Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "i", "w", "u", "t" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "i", "description": "The extraction mode. The available extraction modes are: i - injecting the contextual namespace bindings into the extracted token (default) w - wrapping the extracted token in its ancestor context u - unwrapping the extracted to [...] - "group": { "index": 4, "kind": "attribute", "displayName": "Group", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "To group N parts together" }, - "namespace": { "index": 5, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 6, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, - "headerName": { "index": 7, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, - "propertyName": { "index": 8, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "mode": { "index": 2, "kind": "attribute", "displayName": "Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "i", "w", "u", "t" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "i", "description": "The extraction mode. The available extraction modes are: i - injecting the contextual namespace bindings into the extracted token (default) w - wrapping the extracted token in its ancestor context u - unwrapping the extracted to [...] + "group": { "index": 3, "kind": "attribute", "displayName": "Group", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "To group N parts together" }, + "namespace": { "index": 4, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, + "variableName": { "index": 5, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, + "headerName": { "index": 6, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, + "propertyName": { "index": 7, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 8, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, "trim": { "index": 9, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xpath.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xpath.json index 64ba6b80fbc..939d01aa984 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xpath.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xpath.json @@ -16,7 +16,7 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, "documentType": { "index": 2, "kind": "attribute", "displayName": "Document Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class for document type The default value is org.w3c.dom.Document" }, - "resultType": { "index": 3, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "NUMBER", "STRING", "BOOLEAN", "NODESET", "NODE" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NODESET", "description": "Sets the class name of the result type (type from output) The default result type is NodeSet" }, + "resultQName": { "index": 3, "kind": "attribute", "displayName": "Result QName", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "NUMBER", "STRING", "BOOLEAN", "NODESET", "NODE" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NODESET", "description": "Sets the output type supported by XPath." }, "saxon": { "index": 4, "kind": "attribute", "displayName": "Saxon", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to use Saxon." }, "factoryRef": { "index": 5, "kind": "attribute", "displayName": "Factory Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "References to a custom XPathFactory to lookup in the registry" }, "objectModel": { "index": 6, "kind": "attribute", "displayName": "Object Model", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The XPath object model to use" }, @@ -24,9 +24,10 @@ "threadSafety": { "index": 8, "kind": "attribute", "displayName": "Thread Safety", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable thread-safety for the returned result of the xpath expression. This applies to when using NODESET as the result type, and the returned set has multiple elements. In this situation there can be threa [...] "preCompile": { "index": 9, "kind": "attribute", "displayName": "Pre Compile", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to enable pre-compiling the xpath expression during initialization phase. pre-compile is enabled by default. This can be used to turn off, for example in cases the compilation phase is desired at the starting phas [...] "namespace": { "index": 10, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 11, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, + "variableName": { "index": 11, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, "headerName": { "index": 12, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, "propertyName": { "index": 13, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, - "trim": { "index": 14, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } + "resultType": { "index": 14, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "trim": { "index": 15, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xquery.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xquery.json index dfef4422e13..da5df3481ca 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xquery.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xquery.json @@ -15,13 +15,12 @@ "properties": { "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, - "resultType": { "index": 2, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, - "type": { "index": 3, "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name of the result type (type from output) The default result type is NodeSet" }, - "configurationRef": { "index": 4, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, - "namespace": { "index": 5, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 6, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, - "headerName": { "index": 7, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, - "propertyName": { "index": 8, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, - "trim": { "index": 9, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } + "configurationRef": { "index": 2, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, + "namespace": { "index": 3, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, + "variableName": { "index": 4, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, + "headerName": { "index": 5, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, + "propertyName": { "index": 6, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 7, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "trim": { "index": 8, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xtokenize.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xtokenize.json index fe64a44a46c..781d214fe31 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xtokenize.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xtokenize.json @@ -15,13 +15,13 @@ "properties": { "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, - "resultType": { "index": 2, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, - "mode": { "index": 3, "kind": "attribute", "displayName": "Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "i", "w", "u", "t" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "i", "description": "The extraction mode. The available extraction modes are: i - injecting the contextual namespace bindings into the extracted token (default) w - wrapping the extracted token in its ancestor context u - unwrapping the extracted to [...] - "group": { "index": 4, "kind": "attribute", "displayName": "Group", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "To group N parts together" }, - "namespace": { "index": 5, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 6, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, - "headerName": { "index": 7, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, - "propertyName": { "index": 8, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "mode": { "index": 2, "kind": "attribute", "displayName": "Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "i", "w", "u", "t" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "i", "description": "The extraction mode. The available extraction modes are: i - injecting the contextual namespace bindings into the extracted token (default) w - wrapping the extracted token in its ancestor context u - unwrapping the extracted to [...] + "group": { "index": 3, "kind": "attribute", "displayName": "Group", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "To group N parts together" }, + "namespace": { "index": 4, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, + "variableName": { "index": 5, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, + "headerName": { "index": 6, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, + "propertyName": { "index": 7, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 8, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, "trim": { "index": 9, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/components/camel-saxon/src/generated/resources/org/apache/camel/language/xquery/xquery.json b/components/camel-saxon/src/generated/resources/org/apache/camel/language/xquery/xquery.json index 6c282f23bea..8233882bdd8 100644 --- a/components/camel-saxon/src/generated/resources/org/apache/camel/language/xquery/xquery.json +++ b/components/camel-saxon/src/generated/resources/org/apache/camel/language/xquery/xquery.json @@ -18,13 +18,12 @@ "properties": { "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, - "resultType": { "index": 2, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, - "type": { "index": 3, "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name of the result type (type from output) The default result type is NodeSet" }, - "configurationRef": { "index": 4, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, - "namespace": { "index": 5, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 6, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, - "headerName": { "index": 7, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, - "propertyName": { "index": 8, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, - "trim": { "index": 9, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } + "configurationRef": { "index": 2, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, + "namespace": { "index": 3, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, + "variableName": { "index": 4, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, + "headerName": { "index": 5, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, + "propertyName": { "index": 6, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 7, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "trim": { "index": 8, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/components/camel-saxon/src/main/docs/xquery-component.adoc b/components/camel-saxon/src/main/docs/xquery-component.adoc index b098ee24719..10e2cd27b43 100644 --- a/components/camel-saxon/src/main/docs/xquery-component.adoc +++ b/components/camel-saxon/src/main/docs/xquery-component.adoc @@ -112,7 +112,7 @@ attribute: [source,xml] ------------------------------------------------------------------------------- -<xquery type="java.lang.String">concat('mock:foo.', /person/@city)</xquery> +<xquery resultType="java.lang.String">concat('mock:foo.', /person/@city)</xquery> ------------------------------------------------------------------------------- diff --git a/components/camel-saxon/src/main/docs/xquery-language.adoc b/components/camel-saxon/src/main/docs/xquery-language.adoc index e91e77f8a52..36f87c9a5e3 100644 --- a/components/camel-saxon/src/main/docs/xquery-language.adoc +++ b/components/camel-saxon/src/main/docs/xquery-language.adoc @@ -73,7 +73,7 @@ And in XML DSL: <route> <from uri="direct:start"/> <recipientList> - <xquery type="java.lang.String">concat('mock:foo.', /person/@city</xquery> + <xquery resultType="java.lang.String">concat('mock:foo.', /person/@city</xquery> </recipientList> </route> ----------------------------------------------------------------------------- diff --git a/components/camel-saxon/src/test/java/org/apache/camel/language/XQueryLanguageTest.java b/components/camel-saxon/src/test/java/org/apache/camel/language/XQueryLanguageTest.java index 28cd53c9106..5426e1d422a 100644 --- a/components/camel-saxon/src/test/java/org/apache/camel/language/XQueryLanguageTest.java +++ b/components/camel-saxon/src/test/java/org/apache/camel/language/XQueryLanguageTest.java @@ -21,14 +21,24 @@ import org.apache.camel.model.language.XQueryExpression; /** * Ensures that the "xquery" language is compliant with the single input expectations. */ -class XQueryLanguageTest extends AbstractSingleInputLanguageTest<XQueryExpression.Builder, XQueryExpression> { +class XQueryLanguageTest extends AbstractSingleInputTypedLanguageTest<XQueryExpression.Builder, XQueryExpression> { XQueryLanguageTest() { super("/foo/text()", factory -> factory.xquery().resultType(String.class)); } @Override - protected TestContext testContext() { - return new TestContext("<foo>John</foo>", "John", String.class); + protected Object defaultContentToSend() { + return "<foo>John</foo>"; + } + + @Override + protected TestContext testWithTypeContext() { + return new TestContext(defaultContentToSend(), "John", String.class); + } + + @Override + protected TestContext testWithoutTypeContext() { + return new TestContext(defaultContentToSend(), "John", null); } } diff --git a/components/camel-saxon/src/test/resources/org/apache/camel/builder/saxon/SpringXQueryTransformIssueTest.xml b/components/camel-saxon/src/test/resources/org/apache/camel/builder/saxon/SpringXQueryTransformIssueTest.xml index ce6848575ae..764b9d490ad 100644 --- a/components/camel-saxon/src/test/resources/org/apache/camel/builder/saxon/SpringXQueryTransformIssueTest.xml +++ b/components/camel-saxon/src/test/resources/org/apache/camel/builder/saxon/SpringXQueryTransformIssueTest.xml @@ -28,7 +28,7 @@ <route> <from uri="direct:start"/> <transform> - <xquery type="String">concat(/Envelope/Body/getEmployee/EmpId/text(),"TestConcat")</xquery> + <xquery resultType="String">concat(/Envelope/Body/getEmployee/EmpId/text(),"TestConcat")</xquery> </transform> <to uri="log:info"/> <to uri="mock:result"/> diff --git a/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml b/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml index 21d9743443c..fec695e312f 100644 --- a/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml +++ b/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/xqueryWithExplicitTypeContext.xml @@ -29,7 +29,7 @@ <route> <from uri="direct:start"/> <recipientList> - <xquery type="java.lang.String">concat('mock:foo.', /person/@city)</xquery> + <xquery resultType="java.lang.String">concat('mock:foo.', /person/@city)</xquery> </recipientList> </route> </camelContext> diff --git a/components/camel-stax/src/generated/resources/org/apache/camel/language/xtokenizer/xtokenize.json b/components/camel-stax/src/generated/resources/org/apache/camel/language/xtokenizer/xtokenize.json index c70f189e3f7..08b3e202074 100644 --- a/components/camel-stax/src/generated/resources/org/apache/camel/language/xtokenizer/xtokenize.json +++ b/components/camel-stax/src/generated/resources/org/apache/camel/language/xtokenizer/xtokenize.json @@ -18,13 +18,13 @@ "properties": { "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, - "resultType": { "index": 2, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, - "mode": { "index": 3, "kind": "attribute", "displayName": "Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "i", "w", "u", "t" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "i", "description": "The extraction mode. The available extraction modes are: i - injecting the contextual namespace bindings into the extracted token (default) w - wrapping the extracted token in its ancestor context u - unwrapping the extracted to [...] - "group": { "index": 4, "kind": "attribute", "displayName": "Group", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "To group N parts together" }, - "namespace": { "index": 5, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 6, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body" }, - "headerName": { "index": 7, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, - "propertyName": { "index": 8, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "mode": { "index": 2, "kind": "attribute", "displayName": "Mode", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "i", "w", "u", "t" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "i", "description": "The extraction mode. The available extraction modes are: i - injecting the contextual namespace bindings into the extracted token (default) w - wrapping the extracted token in its ancestor context u - unwrapping the extracted to [...] + "group": { "index": 3, "kind": "attribute", "displayName": "Group", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "To group N parts together" }, + "namespace": { "index": 4, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, + "variableName": { "index": 5, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, + "headerName": { "index": 6, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, + "propertyName": { "index": 7, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 8, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, "trim": { "index": 9, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/components/camel-stax/src/main/java/org/apache/camel/language/xtokenizer/XMLTokenizeLanguage.java b/components/camel-stax/src/main/java/org/apache/camel/language/xtokenizer/XMLTokenizeLanguage.java index 281b72d4df7..d87499136be 100644 --- a/components/camel-stax/src/main/java/org/apache/camel/language/xtokenizer/XMLTokenizeLanguage.java +++ b/components/camel-stax/src/main/java/org/apache/camel/language/xtokenizer/XMLTokenizeLanguage.java @@ -37,6 +37,12 @@ import org.apache.camel.support.builder.Namespaces; @Language("xtokenize") public class XMLTokenizeLanguage extends SingleInputTypedLanguageSupport { + @Override + protected boolean supportResultType() { + // result type is handled specially in tokenizer + return false; + } + @Override public Expression createExpression(Expression source, String expression, Object[] properties) { Character mode = property(Character.class, properties, 4, "i"); diff --git a/components/camel-stax/src/test/java/org/apache/camel/language/XMLTokenizeLanguageTest.java b/components/camel-stax/src/test/java/org/apache/camel/language/XMLTokenizeLanguageTest.java index 5641cc37320..7c2f5ad510a 100644 --- a/components/camel-stax/src/test/java/org/apache/camel/language/XMLTokenizeLanguageTest.java +++ b/components/camel-stax/src/test/java/org/apache/camel/language/XMLTokenizeLanguageTest.java @@ -16,26 +16,49 @@ */ package org.apache.camel.language; +import java.util.Iterator; + import org.apache.camel.model.language.XMLTokenizerExpression; import org.apache.camel.support.builder.Namespaces; /** - * Ensures that the "xtokenize" language is compliant with the single input expectations. + * Ensures that the xtokenize language is compliant with the single input expectations. */ -class XMLTokenizeLanguageTest extends AbstractSingleInputLanguageTest<XMLTokenizerExpression.Builder, XMLTokenizerExpression> { +class XMLTokenizeLanguageTest + extends AbstractSingleInputTypedLanguageTest<XMLTokenizerExpression.Builder, XMLTokenizerExpression> { XMLTokenizeLanguageTest() { super("/orders/order", factory -> factory.xtokenize().namespaces(new Namespaces("", "http:acme.com"))); } - protected String createBody() { + @Override + protected Object defaultContentToSend() { return "<?xml version=\"1.0\"?>\n" + "<orders xmlns=\"http:acme.com\">\n" + " <order>Camel in Action</order>\n" + "</orders>"; } @Override - protected TestContext testContext() { - return new TestContext(createBody(), "<order xmlns=\"http:acme.com\">Camel in Action</order>", String.class); + protected TestContext testWithTypeContext() { + return new TestContext(defaultContentToSend(), "<order xmlns=\"http:acme.com\">Camel in Action</order>", String.class); + } + + @Override + protected TestContext testWithoutTypeContext() { + return new TestContext(defaultContentToSend(), "<order xmlns=\"http:acme.com\">Camel in Action</order>", null); + } + + @Override + protected void assertTypeInstanceOf(Class<?> expected, Object body) { + // noop + } + + @Override + protected void assertBodyReceived(Object expected, Object body) { + // uses an iterator, so we need to walk it to get the body + if (body instanceof Iterator<?> it) { + body = it.next(); + } + super.assertBodyReceived(expected, body); } } diff --git a/components/camel-xpath/src/generated/resources/org/apache/camel/language/xpath/xpath.json b/components/camel-xpath/src/generated/resources/org/apache/camel/language/xpath/xpath.json index f2739357e7a..7de222cc05f 100644 --- a/components/camel-xpath/src/generated/resources/org/apache/camel/language/xpath/xpath.json +++ b/components/camel-xpath/src/generated/resources/org/apache/camel/language/xpath/xpath.json @@ -19,7 +19,7 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, "documentType": { "index": 2, "kind": "attribute", "displayName": "Document Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class for document type The default value is org.w3c.dom.Document" }, - "resultType": { "index": 3, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "resultQName": { "index": 3, "kind": "attribute", "displayName": "Result QName", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "NUMBER", "STRING", "BOOLEAN", "NODESET", "NODE" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NODESET", "description": "Sets the output type supported by XPath." }, "saxon": { "index": 4, "kind": "attribute", "displayName": "Saxon", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to use Saxon." }, "factoryRef": { "index": 5, "kind": "attribute", "displayName": "Factory Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "References to a custom XPathFactory to lookup in the registry" }, "objectModel": { "index": 6, "kind": "attribute", "displayName": "Object Model", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The XPath object model to use" }, @@ -30,6 +30,7 @@ "variableName": { "index": 11, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, "headerName": { "index": 12, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, "propertyName": { "index": 13, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, - "trim": { "index": 14, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } + "resultType": { "index": 14, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "trim": { "index": 15, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java index 8807c806a8f..a6d3c3b7d9a 100644 --- a/core/camel-core-languages/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java +++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java @@ -35,6 +35,12 @@ import org.apache.camel.support.builder.ExpressionBuilder; @org.apache.camel.spi.annotations.Language("tokenize") public class TokenizeLanguage extends SingleInputTypedLanguageSupport { + @Override + protected boolean supportResultType() { + // result type is handled specially in tokenizer + return false; + } + @Override public Expression createExpression(Expression source, String expression, Object[] properties) { Class<?> type = property(Class.class, properties, 0, null); diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xpath.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xpath.json index e5f2e88310d..939d01aa984 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xpath.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xpath.json @@ -16,7 +16,7 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, "documentType": { "index": 2, "kind": "attribute", "displayName": "Document Type", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class for document type The default value is org.w3c.dom.Document" }, - "resultType": { "index": 14, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "resultQName": { "index": 3, "kind": "attribute", "displayName": "Result QName", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "NUMBER", "STRING", "BOOLEAN", "NODESET", "NODE" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NODESET", "description": "Sets the output type supported by XPath." }, "saxon": { "index": 4, "kind": "attribute", "displayName": "Saxon", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to use Saxon." }, "factoryRef": { "index": 5, "kind": "attribute", "displayName": "Factory Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "References to a custom XPathFactory to lookup in the registry" }, "objectModel": { "index": 6, "kind": "attribute", "displayName": "Object Model", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The XPath object model to use" }, @@ -27,6 +27,7 @@ "variableName": { "index": 11, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, "headerName": { "index": 12, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, "propertyName": { "index": 13, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 14, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, "trim": { "index": 15, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xquery.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xquery.json index 52eb006e16c..da5df3481ca 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xquery.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/xquery.json @@ -15,13 +15,12 @@ "properties": { "id": { "index": 0, "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" }, "expression": { "index": 1, "kind": "value", "displayName": "Expression", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The expression value in your chosen language syntax" }, - "type": { "index": 2, "kind": "attribute", "displayName": "Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class name of the result type (type from output) The default result type is NodeSet" }, - "configurationRef": { "index": 3, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, - "namespace": { "index": 4, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, - "variableName": { "index": 5, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, - "headerName": { "index": 6, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, - "propertyName": { "index": 7, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, - "resultType": { "index": 8, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, - "trim": { "index": 9, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } + "configurationRef": { "index": 2, "kind": "attribute", "displayName": "Configuration Ref", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This may be needed to add custom functions to a saxon configuration, so these custom functions can be used in xquery expressions." }, + "namespace": { "index": 3, "kind": "element", "displayName": "Namespace", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Injects the XML Namespaces of prefix - uri mappings" }, + "variableName": { "index": 4, "kind": "attribute", "displayName": "Variable Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." }, + "headerName": { "index": 5, "kind": "attribute", "displayName": "Header Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of header to use as input, instead of the message body It has as higher precedent than the propertyName if both are set." }, + "propertyName": { "index": 6, "kind": "attribute", "displayName": "Property Name", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, + "resultType": { "index": 7, "kind": "attribute", "displayName": "Result Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the class of the result type (type from output)" }, + "trim": { "index": 8, "kind": "attribute", "displayName": "Trim", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" } } } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java index 5d8c0e189e1..d9ad5964f95 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNodeHelper.java @@ -49,7 +49,7 @@ public final class ExpressionNodeHelper { // accepts an expression XPathExpression answer = new XPathExpression(expression); answer.setExpression(aware.getExpressionText()); - answer.setResultType(answer.getResultType()); + answer.setResultType(aware.getResultType()); return answer; } else if (expression instanceof ValueBuilder) { // ValueBuilder wraps the actual expression so unwrap @@ -81,7 +81,7 @@ public final class ExpressionNodeHelper { // accepts an expression XPathExpression answer = new XPathExpression(expression); answer.setExpression(aware.getExpressionText()); - answer.setResultType(answer.getResultType()); + answer.setResultType(aware.getResultType()); return answer; } else if (predicate instanceof ValueBuilder) { // ValueBuilder wraps the actual predicate so unwrap diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java index e8c33af9cff..171ccbfe38d 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java @@ -44,9 +44,9 @@ public class XPathExpression extends NamespaceAwareExpression { @XmlAttribute(name = "documentType") @Metadata(label = "advanced") private String documentTypeName; - @XmlAttribute(name = "resultType") + @XmlAttribute(name = "resultQName") @Metadata(defaultValue = "NODESET", enums = "NUMBER,STRING,BOOLEAN,NODESET,NODE") - private String resultTypeName; + private String resultQName; @XmlAttribute @Metadata(label = "advanced", javaType = "java.lang.Boolean") private String saxon; @@ -82,7 +82,7 @@ public class XPathExpression extends NamespaceAwareExpression { this.documentType = builder.documentType; this.xpathFactory = builder.xpathFactory; this.documentTypeName = builder.documentTypeName; - this.resultTypeName = builder.resultTypeName; + this.resultQName = builder.resultQName; this.saxon = builder.saxon; this.factoryRef = builder.factoryRef; this.objectModel = builder.objectModel; @@ -122,17 +122,15 @@ public class XPathExpression extends NamespaceAwareExpression { this.documentTypeName = documentTypeName; } - public String getResultTypeName() { - return resultTypeName; + public String getResultQName() { + return resultQName; } /** - * Sets the class name of the result type (type from output) - * <p/> - * The default result type is NodeSet + * Sets the output type supported by XPath. */ - public void setResultTypeName(String resultTypeName) { - this.resultTypeName = resultTypeName; + public void setResultQName(String resultQName) { + this.resultQName = resultQName; } /** @@ -229,7 +227,7 @@ public class XPathExpression extends NamespaceAwareExpression { private Class<?> documentType; private XPathFactory xpathFactory; private String documentTypeName; - private String resultTypeName; + private String resultQName; private String saxon; private String factoryRef; private String objectModel; @@ -267,8 +265,8 @@ public class XPathExpression extends NamespaceAwareExpression { * <p/> * The default result type is NodeSet */ - public Builder resultTypeName(String resultTypeName) { - this.resultTypeName = resultTypeName; + public Builder resultQName(String resultTypeName) { + this.resultQName = resultQName; return this; } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XQueryExpression.java b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XQueryExpression.java index 9892796edc1..f310ed3ae02 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XQueryExpression.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XQueryExpression.java @@ -34,9 +34,6 @@ public class XQueryExpression extends NamespaceAwareExpression { @XmlTransient private Object configuration; - - @XmlAttribute - private String type; @XmlAttribute @Metadata(label = "advanced") private String configurationRef; @@ -51,7 +48,6 @@ public class XQueryExpression extends NamespaceAwareExpression { private XQueryExpression(Builder builder) { super(builder); this.configuration = builder.configuration; - this.type = builder.type; this.configurationRef = builder.configurationRef; } @@ -60,19 +56,6 @@ public class XQueryExpression extends NamespaceAwareExpression { return "xquery"; } - public String getType() { - return type; - } - - /** - * Sets the class name of the result type (type from output) - * <p/> - * The default result type is NodeSet - */ - public void setType(String type) { - this.type = type; - } - public String getConfigurationRef() { return configurationRef; } @@ -105,7 +88,6 @@ public class XQueryExpression extends NamespaceAwareExpression { public static class Builder extends AbstractNamespaceAwareBuilder<Builder, XQueryExpression> { private Object configuration; - private String type; private String configurationRef; /** @@ -117,16 +99,6 @@ public class XQueryExpression extends NamespaceAwareExpression { return this; } - /** - * Sets the class name of the result type (type from output) - * <p/> - * The default result type is NodeSet - */ - public Builder type(String type) { - this.type = type; - return this; - } - /** * Reference to a saxon configuration instance in the registry to use for xquery (requires camel-saxon). This * may be needed to add custom functions to a saxon configuration, so these custom functions can be used in diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/DatasonnetExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/DatasonnetExpressionReifier.java index 3c5cb244e89..2248b144ce4 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/DatasonnetExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/DatasonnetExpressionReifier.java @@ -29,7 +29,7 @@ public class DatasonnetExpressionReifier extends TypedExpressionReifier<Datasonn @Override protected Object[] createProperties() { Object[] properties = new Object[3]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseString(definition.getBodyMediaType()); properties[2] = parseString(definition.getOutputMediaType()); return 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 4245dc83d40..50b406f4dd5 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,7 +29,7 @@ public class JavaExpressionReifier extends TypedExpressionReifier<JavaExpression @Override protected Object[] createProperties() { Object[] properties = new Object[3]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); 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 71b787bdd81..303195f34ed 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,7 +30,7 @@ public class JoorExpressionReifier extends TypedExpressionReifier<JoorExpression @Override protected Object[] createProperties() { Object[] properties = new Object[3]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); 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/JsonPathExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JsonPathExpressionReifier.java index 3ee13662e94..306ed50c029 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JsonPathExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/JsonPathExpressionReifier.java @@ -29,7 +29,7 @@ public class JsonPathExpressionReifier extends SingleInputTypedExpressionReifier @Override protected Object[] createProperties() { Object[] properties = new Object[10]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseString(definition.getVariableName()); properties[2] = parseString(definition.getHeaderName()); properties[3] = parseString(definition.getPropertyName()); 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 7a6530c1e7c..7d7da74841e 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,7 +31,7 @@ public class MethodCallExpressionReifier extends TypedExpressionReifier<MethodCa @Override protected Object[] createProperties() { Object[] properties = new Object[7]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = definition.getInstance(); properties[2] = parseString(definition.getMethod()); properties[3] = definition.getBeanType(); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SimpleExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SimpleExpressionReifier.java index 59bb831cdc5..ca066c4d382 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SimpleExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SimpleExpressionReifier.java @@ -35,7 +35,7 @@ public class SimpleExpressionReifier extends TypedExpressionReifier<SimpleExpres @Override protected Object[] createProperties() { Object[] properties = new Object[2]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseBoolean(definition.getTrim()); return properties; } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SingleInputTypedExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SingleInputTypedExpressionReifier.java index 623d774a473..e3261967d89 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SingleInputTypedExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/SingleInputTypedExpressionReifier.java @@ -36,7 +36,7 @@ class SingleInputTypedExpressionReifier<T extends SingleInputTypedExpressionDefi @Override protected Object[] createProperties() { Object[] properties = new Object[4]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseString(definition.getVariableName()); properties[2] = parseString(definition.getHeaderName()); properties[3] = parseString(definition.getPropertyName()); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java index bc6d3df4bf4..88cfeba2322 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java @@ -24,7 +24,7 @@ import org.apache.camel.model.language.TokenizerExpression; import org.apache.camel.spi.Language; import org.apache.camel.support.ExpressionToPredicateAdapter; -public class TokenizerExpressionReifier extends ExpressionReifier<TokenizerExpression> { +public class TokenizerExpressionReifier extends TypedExpressionReifier<TokenizerExpression> { public TokenizerExpressionReifier(CamelContext camelContext, ExpressionDefinition definition) { super(camelContext, (TokenizerExpression) definition); @@ -32,7 +32,7 @@ public class TokenizerExpressionReifier extends ExpressionReifier<TokenizerExpre protected Object[] createProperties() { Object[] properties = new Object[13]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseString(definition.getVariableName()); properties[2] = parseString(definition.getHeaderName()); properties[3] = parseString(definition.getPropertyName()); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TypedExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TypedExpressionReifier.java index e3528df843f..b42ccf0acf3 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TypedExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TypedExpressionReifier.java @@ -37,30 +37,34 @@ class TypedExpressionReifier<T extends TypedExpressionDefinition> extends Expres } @Override - protected void configureLanguage(Language language) { - if (definition.getResultType() == null && definition.getResultTypeName() != null) { - try { - Class<?> clazz = camelContext.getClassResolver().resolveMandatoryClass(definition.getResultTypeName()); - definition.setResultType(clazz); - } catch (ClassNotFoundException e) { - throw RuntimeCamelException.wrapRuntimeException(e); - } - } + protected Expression createExpression(Language language, String exp) { + return language.createExpression(exp, createProperties()); + } + + @Override + protected Predicate createPredicate(Language language, String exp) { + return language.createPredicate(exp, createProperties()); } protected Object[] createProperties() { Object[] properties = new Object[1]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); return properties; } - @Override - protected Expression createExpression(Language language, String exp) { - return language.createExpression(exp, createProperties()); + protected Class<?> asResultType() { + if (definition.getResultType() == null && definition.getResultTypeName() != null) { + try { + return camelContext.getClassResolver().resolveMandatoryClass(parseString(definition.getResultTypeName())); + } catch (ClassNotFoundException e) { + throw RuntimeCamelException.wrapRuntimeException(e); + } + } + return definition.getResultType(); } @Override - protected Predicate createPredicate(Language language, String exp) { - return language.createPredicate(exp, createProperties()); + protected void configureLanguage(Language language) { + asResultType(); } } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/WasmExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/WasmExpressionReifier.java index f07a3af4043..4f3093ac137 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/WasmExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/WasmExpressionReifier.java @@ -35,7 +35,7 @@ public class WasmExpressionReifier extends TypedExpressionReifier<WasmExpression @Override protected Object[] createProperties() { Object[] properties = new Object[2]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseString(definition.getModule()); return properties; } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XMLTokenizerExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XMLTokenizerExpressionReifier.java index e10c2e27dab..001696fae83 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XMLTokenizerExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XMLTokenizerExpressionReifier.java @@ -25,7 +25,7 @@ import org.apache.camel.spi.Language; import org.apache.camel.spi.NamespaceAware; import org.apache.camel.support.ExpressionToPredicateAdapter; -public class XMLTokenizerExpressionReifier extends ExpressionReifier<XMLTokenizerExpression> { +public class XMLTokenizerExpressionReifier extends TypedExpressionReifier<XMLTokenizerExpression> { public XMLTokenizerExpressionReifier(CamelContext camelContext, ExpressionDefinition definition) { super(camelContext, (XMLTokenizerExpression) definition); @@ -66,7 +66,7 @@ public class XMLTokenizerExpressionReifier extends ExpressionReifier<XMLTokenize protected Object[] createProperties() { Object[] properties = new Object[7]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseString(definition.getVariableName()); properties[2] = parseString(definition.getHeaderName()); properties[3] = parseString(definition.getPropertyName()); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java index c5907b6ad2b..5e72919575c 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XPathExpressionReifier.java @@ -28,7 +28,7 @@ import org.apache.camel.model.language.XPathExpression; import org.apache.camel.spi.Language; import org.apache.camel.spi.NamespaceAware; -public class XPathExpressionReifier extends ExpressionReifier<XPathExpression> { +public class XPathExpressionReifier extends TypedExpressionReifier<XPathExpression> { public XPathExpressionReifier(CamelContext camelContext, ExpressionDefinition definition) { super(camelContext, (XPathExpression) definition); @@ -63,19 +63,12 @@ public class XPathExpressionReifier extends ExpressionReifier<XPathExpression> { protected Object[] createProperties() { Object[] properties = new Object[13]; - // resultType can either point to a QName or it can be a regular class that influence the qname - // so we need this special logic to set resultQName and resultType accordingly - Object qname = asQName(definition.getResultTypeName()); - if (definition.getResultType() == null && qname == null && definition.getResultTypeName() != null) { - properties[0] = definition.getResultTypeName(); - } else { - properties[0] = definition.getResultType(); - } + properties[0] = asResultType(); properties[1] = parseString(definition.getVariableName()); properties[2] = parseString(definition.getHeaderName()); properties[3] = parseString(definition.getPropertyName()); properties[4] = definition.getDocumentType(); - properties[5] = qname; + properties[5] = asQName(parseString(definition.getResultQName())); properties[6] = parseBoolean(definition.getSaxon()); properties[7] = definition.getXPathFactory(); properties[8] = parseString(definition.getObjectModel()); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XQueryExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XQueryExpressionReifier.java index 0ee0dbf4ab8..9646bfb4eef 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XQueryExpressionReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/XQueryExpressionReifier.java @@ -19,13 +19,12 @@ package org.apache.camel.reifier.language; import org.apache.camel.CamelContext; import org.apache.camel.Expression; import org.apache.camel.Predicate; -import org.apache.camel.RuntimeCamelException; import org.apache.camel.model.language.ExpressionDefinition; import org.apache.camel.model.language.XQueryExpression; import org.apache.camel.spi.Language; import org.apache.camel.spi.NamespaceAware; -public class XQueryExpressionReifier extends ExpressionReifier<XQueryExpression> { +public class XQueryExpressionReifier extends TypedExpressionReifier<XQueryExpression> { public XQueryExpressionReifier(CamelContext camelContext, ExpressionDefinition definition) { super(camelContext, (XQueryExpression) definition); @@ -60,7 +59,7 @@ public class XQueryExpressionReifier extends ExpressionReifier<XQueryExpression> protected Object[] createProperties() { Object[] properties = new Object[4]; - properties[0] = definition.getResultType(); + properties[0] = asResultType(); properties[1] = parseString(definition.getVariableName()); properties[2] = parseString(definition.getHeaderName()); properties[3] = parseString(definition.getPropertyName()); @@ -69,22 +68,6 @@ public class XQueryExpressionReifier extends ExpressionReifier<XQueryExpression> @Override protected void configureLanguage(Language language) { - if (definition.getResultType() == null && definition.getResultTypeName() != null) { - try { - Class<?> clazz = camelContext.getClassResolver().resolveMandatoryClass(definition.getResultTypeName()); - definition.setResultType(clazz); - } catch (ClassNotFoundException e) { - throw RuntimeCamelException.wrapRuntimeException(e); - } - } - if (definition.getResultType() == null && definition.getType() != null) { - try { - Class<?> clazz = camelContext.getClassResolver().resolveMandatoryClass(definition.getType()); - definition.setResultType(clazz); - } catch (ClassNotFoundException e) { - throw RuntimeCamelException.wrapRuntimeException(e); - } - } if (definition.getConfiguration() == null && definition.getConfigurationRef() != null) { definition.setConfiguration(mandatoryLookup(definition.getConfigurationRef(), Object.class)); } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java index d8d4cbd3778..0611553da63 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java @@ -43,7 +43,7 @@ public class FileConsumerFailureHandledTest extends ContextTestSupport { mock.expectedBodiesReceived("Hello Paris"); template.sendBodyAndHeader(fileUri(), "Paris", Exchange.FILE_NAME, "paris.txt"); - mock.assertIsSatisfied(1000); + mock.assertIsSatisfied(2000); oneExchangeDone.matchesWaitTime(); @@ -57,7 +57,7 @@ public class FileConsumerFailureHandledTest extends ContextTestSupport { mock.expectedBodiesReceived("London"); template.sendBodyAndHeader(fileUri(), "London", Exchange.FILE_NAME, "london.txt"); - mock.assertIsSatisfied(1000); + mock.assertIsSatisfied(2000); oneExchangeDone.matchesWaitTime(); @@ -72,7 +72,7 @@ public class FileConsumerFailureHandledTest extends ContextTestSupport { mock.expectedBodiesReceived("Dublin"); template.sendBodyAndHeader(fileUri(), "Dublin", Exchange.FILE_NAME, "dublin.txt"); - mock.assertIsSatisfied(1000); + mock.assertIsSatisfied(2000); oneExchangeDone.matchesWaitTime(); @@ -87,7 +87,7 @@ public class FileConsumerFailureHandledTest extends ContextTestSupport { mock.expectedBodiesReceived("Madrid"); template.sendBodyAndHeader(fileUri(), "Madrid", Exchange.FILE_NAME, "madrid.txt"); - mock.assertIsSatisfied(1000); + mock.assertIsSatisfied(2000); oneExchangeDone.matchesWaitTime(); diff --git a/core/camel-core/src/test/java/org/apache/camel/language/AbstractSingleInputTypedLanguageTest.java b/core/camel-core/src/test/java/org/apache/camel/language/AbstractSingleInputTypedLanguageTest.java index 2f1b6f113b6..52044969f3f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/AbstractSingleInputTypedLanguageTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/AbstractSingleInputTypedLanguageTest.java @@ -58,18 +58,22 @@ public abstract class AbstractSingleInputTypedLanguageTest< } }); context.start(); - MockEndpoint mockEndpoint = getMockEndpoint("mock:header-only"); + TestContext context = testWithoutTypeContext(); - mockEndpoint.expectedBodiesReceived(context.getBodyReceived()); + MockEndpoint mockEndpoint = getMockEndpoint("mock:header-only"); + mockEndpoint.expectedMessageCount(1); template.sendBodyAndHeader("direct:header-only", "foo", "someHeader", context.getContentToSend()); - assertMockEndpointsSatisfied(); - assertIsInstanceOf(context.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + + assertBodyReceived(context.getBodyReceived(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + assertTypeInstanceOf(context.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); } @Test void testPropertyOnly() throws Exception { + TestContext testContext = testWithoutTypeContext(); + context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -85,19 +89,20 @@ public abstract class AbstractSingleInputTypedLanguageTest< } }); context.start(); - MockEndpoint mockEndpoint = getMockEndpoint("mock:property-only"); - TestContext context = testWithoutTypeContext(); - mockEndpoint.expectedBodiesReceived(context.getBodyReceived()); - - template.sendBodyAndProperty("direct:property-only", "foo", "someProperty", context.getContentToSend()); + MockEndpoint mockEndpoint = getMockEndpoint("mock:property-only"); + mockEndpoint.expectedMessageCount(1); + template.sendBodyAndProperty("direct:property-only", "foo", "someProperty", testContext.getContentToSend()); assertMockEndpointsSatisfied(); - assertIsInstanceOf(context.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + + assertBodyReceived(testContext.getBodyReceived(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + assertTypeInstanceOf(testContext.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); } @Test void testHeaderAndType() throws Exception { TestContext testContext = testWithTypeContext(); + context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -115,14 +120,13 @@ public abstract class AbstractSingleInputTypedLanguageTest< } }); context.start(); - MockEndpoint mockEndpoint = getMockEndpoint("mock:header-and-type"); - mockEndpoint.expectedBodiesReceived(testContext.getBodyReceived()); + MockEndpoint mockEndpoint = getMockEndpoint("mock:header-and-type"); + mockEndpoint.expectedMessageCount(1); template.sendBodyAndHeader("direct:header-and-type", "foo", "someHeader", testContext.getContentToSend()); - assertMockEndpointsSatisfied(); - assertIsInstanceOf(testContext.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + assertTypeInstanceOf(testContext.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); } @Test @@ -145,13 +149,14 @@ public abstract class AbstractSingleInputTypedLanguageTest< } }); context.start(); - MockEndpoint mockEndpoint = getMockEndpoint("mock:property-and-type"); - mockEndpoint.expectedBodiesReceived(testContext.getBodyReceived()); + MockEndpoint mockEndpoint = getMockEndpoint("mock:property-and-type"); + mockEndpoint.expectedMessageCount(1); template.sendBodyAndProperty("direct:property-and-type", "foo", "someProperty", testContext.getContentToSend()); - assertMockEndpointsSatisfied(); - assertIsInstanceOf(testContext.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + + assertBodyReceived(testContext.getBodyReceived(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + assertTypeInstanceOf(testContext.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/language/AbstractTypedLanguageTest.java b/core/camel-core/src/test/java/org/apache/camel/language/AbstractTypedLanguageTest.java index f2f1f854cc9..8d304fe640a 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/AbstractTypedLanguageTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/AbstractTypedLanguageTest.java @@ -23,6 +23,7 @@ import org.apache.camel.builder.LanguageBuilderFactory; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.model.language.TypedExpressionDefinition; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** @@ -50,12 +51,29 @@ public abstract class AbstractTypedLanguageTest< protected void assertResult(String uriSuffix, TestContext context) throws Exception { MockEndpoint mockEndpoint = getMockEndpoint(String.format("mock:%s", uriSuffix)); - mockEndpoint.expectedBodiesReceived(context.getBodyReceived()); - + mockEndpoint.expectedMessageCount(1); template.sendBody(String.format("direct:%s", uriSuffix), context.getContentToSend()); - assertMockEndpointsSatisfied(); - assertIsInstanceOf(context.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + + assertTypeInstanceOf(context.getBodyReceivedType(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + assertBodyReceived(context.getBodyReceived(), mockEndpoint.getReceivedExchanges().get(0).getIn().getBody()); + } + + protected void assertTypeInstanceOf(Class<?> expected, Object body) { + if (expected != null) { + assertIsInstanceOf(expected, body); + } + } + + protected void assertBodyReceived(Object expected, Object body) { + if (expected != null) { + if (expected instanceof Integer && body instanceof Integer) { + // java objects for number crap + Assertions.assertEquals((int) expected, (int) body); + } else { + Assertions.assertEquals(expected, body); + } + } } protected Object defaultContentToSend() { diff --git a/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageTest.java b/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageTest.java index 939ccb3d73b..e41c147ce77 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageTest.java @@ -24,7 +24,7 @@ import org.apache.camel.model.language.XPathExpression; class XPathLanguageTest extends AbstractSingleInputTypedLanguageTest<XPathExpression.Builder, XPathExpression> { XPathLanguageTest() { - super("/foo/text()", factory -> factory.xpath().resultType(String.class)); + super("/foo/text()", factory -> factory.xpath().resultType(Integer.class)); } @Override @@ -34,7 +34,11 @@ class XPathLanguageTest extends AbstractSingleInputTypedLanguageTest<XPathExpres @Override protected TestContext testWithTypeContext() { - return new TestContext(defaultContentToSend(), 1, String.class); + return new TestContext(defaultContentToSend(), 1, Integer.class); } + @Override + protected TestContext testWithoutTypeContext() { + return new TestContext(defaultContentToSend(), 1, Integer.class); + } } 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 caf18859500..b387a557f53 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 @@ -37,6 +37,13 @@ public abstract class SingleInputTypedLanguageSupport extends TypedLanguageSuppo return createExpression(expression, null); } + /** + * Whether using result type is supported + */ + protected boolean supportResultType() { + return true; + } + @Override public Expression createExpression(String expression, Object[] properties) { Class<?> type = property(Class.class, properties, 0, null); @@ -44,7 +51,10 @@ public abstract class SingleInputTypedLanguageSupport extends TypedLanguageSuppo String header = property(String.class, properties, 2, null); String property = property(String.class, properties, 3, null); Expression source = ExpressionBuilder.singleInputExpression(variable, header, property); - if (type == null || type == Object.class) { + if (getCamelContext() != null) { + source.init(getCamelContext()); + } + if (type == null || type == Object.class || !supportResultType()) { return createExpression(source, expression, properties); } return ExpressionBuilder.convertToExpression(createExpression(source, expression, properties), type); @@ -57,6 +67,9 @@ public abstract class SingleInputTypedLanguageSupport extends TypedLanguageSuppo String header = property(String.class, properties, 2, null); String property = property(String.class, properties, 3, null); Expression source = ExpressionBuilder.singleInputExpression(variable, header, property); + if (getCamelContext() != null) { + source.init(getCamelContext()); + } return createPredicate(source, expression, properties); } diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java index e8b5e28bf2f..d4474dc6fb7 100644 --- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java +++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java @@ -3046,7 +3046,7 @@ public class ModelParser extends BaseParser { case "logNamespaces": def.setLogNamespaces(val); break; case "objectModel": def.setObjectModel(val); break; case "preCompile": def.setPreCompile(val); break; - case "resultType": def.setResultTypeName(val); break; + case "resultQName": def.setResultQName(val); break; case "saxon": def.setSaxon(val); break; case "threadSafety": def.setThreadSafety(val); break; default: return singleInputTypedExpressionDefinitionAttributeHandler().accept(def, key, val); @@ -3056,12 +3056,11 @@ public class ModelParser extends BaseParser { } protected XQueryExpression doParseXQueryExpression() throws IOException, XmlPullParserException { return doParse(new XQueryExpression(), (def, key, val) -> { - switch (key) { - case "configurationRef": def.setConfigurationRef(val); break; - case "type": def.setType(val); break; - default: return singleInputTypedExpressionDefinitionAttributeHandler().accept(def, key, val); + if ("configurationRef".equals(key)) { + def.setConfigurationRef(val); + return true; } - return true; + return singleInputTypedExpressionDefinitionAttributeHandler().accept(def, key, val); }, namespaceAwareExpressionElementHandler(), expressionDefinitionValueHandler()); } protected CustomLoadBalancerDefinition doParseCustomLoadBalancerDefinition() throws IOException, XmlPullParserException { diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java index 042df48a723..d2584e6c57f 100644 --- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java +++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java @@ -4241,9 +4241,9 @@ public class ModelWriter extends BaseWriter { doWriteAttribute("logNamespaces", def.getLogNamespaces()); doWriteAttribute("threadSafety", def.getThreadSafety()); doWriteAttribute("factoryRef", def.getFactoryRef()); + doWriteAttribute("resultQName", def.getResultQName()); doWriteAttribute("saxon", def.getSaxon()); doWriteAttribute("documentType", def.getDocumentTypeName()); - doWriteAttribute("resultType", def.getResultTypeName()); doWriteNamespaces(def); doWriteValue(def.getExpression()); endElement(name); @@ -4255,7 +4255,6 @@ public class ModelWriter extends BaseWriter { startElement(name); doWriteSingleInputTypedExpressionDefinitionAttributes(def); doWriteAttribute("configurationRef", def.getConfigurationRef()); - doWriteAttribute("type", def.getType()); doWriteNamespaces(def); doWriteValue(def.getExpression()); endElement(name); diff --git a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java index 9e9f0f67a48..7ff96f5e633 100644 --- a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java +++ b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java @@ -4241,9 +4241,9 @@ public class ModelWriter extends BaseWriter { doWriteAttribute("logNamespaces", def.getLogNamespaces()); doWriteAttribute("threadSafety", def.getThreadSafety()); doWriteAttribute("factoryRef", def.getFactoryRef()); + doWriteAttribute("resultQName", def.getResultQName()); doWriteAttribute("saxon", def.getSaxon()); doWriteAttribute("documentType", def.getDocumentTypeName()); - doWriteAttribute("resultType", def.getResultTypeName()); doWriteNamespaces(def); doWriteValue(def.getExpression()); endElement(name); @@ -4255,7 +4255,6 @@ public class ModelWriter extends BaseWriter { startElement(name); doWriteSingleInputTypedExpressionDefinitionAttributes(def); doWriteAttribute("configurationRef", def.getConfigurationRef()); - doWriteAttribute("type", def.getType()); doWriteNamespaces(def); doWriteValue(def.getExpression()); endElement(name); diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java index 6640db37c18..25c743ca62b 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java @@ -20522,7 +20522,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "propertyName", type = "string", description = "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set.", displayName = "Property Name"), @YamlProperty(name = "resultType", type = "string", description = "Sets the class of the result type (type from output)", displayName = "Result Type"), @YamlProperty(name = "trim", type = "boolean", description = "Whether to trim the value to remove leading and trailing whitespaces and line breaks", displayName = "Trim"), - @YamlProperty(name = "variableName", type = "string", description = "Name of variable to use as input, instead of the message body", displayName = "Variable Name") + @YamlProperty(name = "variableName", type = "string", description = "Name of variable to use as input, instead of the message body It has as higher precedent if other are set.", displayName = "Variable Name") } ) public static class XMLTokenizerExpressionDeserializer extends YamlDeserializerBase<XMLTokenizerExpression> { @@ -20631,11 +20631,12 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "objectModel", type = "string", description = "The XPath object model to use", displayName = "Object Model"), @YamlProperty(name = "preCompile", type = "boolean", description = "Whether to enable pre-compiling the xpath expression during initialization phase. pre-compile is enabled by default. This can be used to turn off, for example in cases the compilation phase is desired at the starting phase, such as if the application is ahead of time compiled (for example with camel-quarkus) which would then load the xpath factory of the built operating system, and not a JVM runtime." [...] @YamlProperty(name = "propertyName", type = "string", description = "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set.", displayName = "Property Name"), - @YamlProperty(name = "resultType", type = "enum:NUMBER,STRING,BOOLEAN,NODESET,NODE", defaultValue = "NODESET", description = "Sets the class name of the result type (type from output) The default result type is NodeSet", displayName = "Result Type"), + @YamlProperty(name = "resultQName", type = "enum:NUMBER,STRING,BOOLEAN,NODESET,NODE", defaultValue = "NODESET", description = "Sets the output type supported by XPath.", displayName = "Result QName"), + @YamlProperty(name = "resultType", type = "string", description = "Sets the class of the result type (type from output)", displayName = "Result Type"), @YamlProperty(name = "saxon", type = "boolean", description = "Whether to use Saxon.", displayName = "Saxon"), @YamlProperty(name = "threadSafety", type = "boolean", description = "Whether to enable thread-safety for the returned result of the xpath expression. This applies to when using NODESET as the result type, and the returned set has multiple elements. In this situation there can be thread-safety issues if you process the NODESET concurrently such as from a Camel Splitter EIP in parallel processing mode. This option prevents concurrency issues by doing defensive copies o [...] @YamlProperty(name = "trim", type = "boolean", description = "Whether to trim the value to remove leading and trailing whitespaces and line breaks", displayName = "Trim"), - @YamlProperty(name = "variableName", type = "string", description = "Name of variable to use as input, instead of the message body", displayName = "Variable Name") + @YamlProperty(name = "variableName", type = "string", description = "Name of variable to use as input, instead of the message body It has as higher precedent if other are set.", displayName = "Variable Name") } ) public static class XPathExpressionDeserializer extends YamlDeserializerBase<XPathExpression> { @@ -20708,6 +20709,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setPropertyName(val); break; } + case "resultQName": { + String val = asText(node); + target.setResultQName(val); + break; + } case "resultType": { String val = asText(node); target.setResultTypeName(val); @@ -20767,8 +20773,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "propertyName", type = "string", description = "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set.", displayName = "Property Name"), @YamlProperty(name = "resultType", type = "string", description = "Sets the class of the result type (type from output)", displayName = "Result Type"), @YamlProperty(name = "trim", type = "boolean", description = "Whether to trim the value to remove leading and trailing whitespaces and line breaks", displayName = "Trim"), - @YamlProperty(name = "type", type = "string", description = "Sets the class name of the result type (type from output) The default result type is NodeSet", displayName = "Type"), - @YamlProperty(name = "variableName", type = "string", description = "Name of variable to use as input, instead of the message body", displayName = "Variable Name") + @YamlProperty(name = "variableName", type = "string", description = "Name of variable to use as input, instead of the message body It has as higher precedent if other are set.", displayName = "Variable Name") } ) public static class XQueryExpressionDeserializer extends YamlDeserializerBase<XQueryExpression> { @@ -20831,11 +20836,6 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setTrim(val); break; } - case "type": { - String val = asText(node); - target.setType(val); - break; - } case "variableName": { String val = asText(node); target.setVariableName(val); diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json index a1f7023b15e..55a54c2dfb8 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json @@ -13817,7 +13817,7 @@ "variableName" : { "type" : "string", "title" : "Variable Name", - "description" : "Name of variable to use as input, instead of the message body" + "description" : "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." } } } ], @@ -13885,13 +13885,18 @@ "title" : "Property Name", "description" : "Name of property to use as input, instead of the message body. It has a lower precedent than the headerName if both are set." }, - "resultType" : { + "resultQName" : { "type" : "string", - "title" : "Result Type", - "description" : "Sets the class name of the result type (type from output) The default result type is NodeSet", + "title" : "Result QName", + "description" : "Sets the output type supported by XPath.", "default" : "NODESET", "enum" : [ "NUMBER", "STRING", "BOOLEAN", "NODESET", "NODE" ] }, + "resultType" : { + "type" : "string", + "title" : "Result Type", + "description" : "Sets the class of the result type (type from output)" + }, "saxon" : { "type" : "boolean", "title" : "Saxon", @@ -13910,7 +13915,7 @@ "variableName" : { "type" : "string", "title" : "Variable Name", - "description" : "Name of variable to use as input, instead of the message body" + "description" : "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." } } } ], @@ -13968,15 +13973,10 @@ "title" : "Trim", "description" : "Whether to trim the value to remove leading and trailing whitespaces and line breaks" }, - "type" : { - "type" : "string", - "title" : "Type", - "description" : "Sets the class name of the result type (type from output) The default result type is NodeSet" - }, "variableName" : { "type" : "string", "title" : "Variable Name", - "description" : "Name of variable to use as input, instead of the message body" + "description" : "Name of variable to use as input, instead of the message body It has as higher precedent if other are set." } } } ],