This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch var in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0fcf3c7d984cb4b75c2797f3a9196972c8ff8670 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Jan 23 13:44:06 2024 +0100 CAMEL-19749: EIPs should make it easy to use together with variables. --- .../org/apache/camel/catalog/models/marshal.json | 4 +- .../org/apache/camel/catalog/models/unmarshal.json | 4 +- .../apache/camel/catalog/schemas/camel-spring.xsd | 44 ++++ .../processor/SpringMarshalVariableTest.java | 29 +++ .../processor/SpringUnmarshalVariableTest.java | 29 +++ .../camel/spring/processor/MarshalVariableTest.xml | 68 ++++++ .../spring/processor/UnmarshalVariableTest.xml | 68 ++++++ .../dsl/yaml/deserializers/ModelDeserializers.java | 24 ++ .../generated/resources/schema/camelYamlDsl.json | 20 ++ .../camel/dsl/yaml/MarshalVariableTest.groovy | 270 +++++++++++++++++++++ .../camel/dsl/yaml/UnmarshalVariableTest.groovy | 268 ++++++++++++++++++++ 11 files changed, 826 insertions(+), 2 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/marshal.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/marshal.json index 178597ebd63..3f33b46e27e 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/marshal.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/marshal.json @@ -15,6 +15,8 @@ "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" }, "description": { "index": 1, "kind": "element", "displayName": "Description", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" }, "disabled": { "index": 2, "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later at runtime." }, - "dataFormatType": { "index": 3, "kind": "element", "displayName": "Data Format Type", "required": true, "type": "object", "javaType": "org.apache.camel.model.DataFormatDefinition", "oneOf": [ "asn1", "avro", "barcode", "base64", "bindy", "cbor", "crypto", "csv", "custom", "fhirJson", "fhirXml", "flatpack", "grok", "gzipDeflater", "hl7", "ical", "jacksonXml", "jaxb", "json", "jsonApi", "lzf", "mimeMultipart", "parquetAvro", "pgp", "protobuf", "rss", "soap", "swiftMt", "swiftMx", "sysl [...] + "dataFormatType": { "index": 3, "kind": "element", "displayName": "Data Format Type", "required": true, "type": "object", "javaType": "org.apache.camel.model.DataFormatDefinition", "oneOf": [ "asn1", "avro", "barcode", "base64", "bindy", "cbor", "crypto", "csv", "custom", "fhirJson", "fhirXml", "flatpack", "grok", "gzipDeflater", "hl7", "ical", "jacksonXml", "jaxb", "json", "jsonApi", "lzf", "mimeMultipart", "parquetAvro", "pgp", "protobuf", "rss", "soap", "swiftMt", "swiftMx", "sysl [...] + "variableSend": { "index": 4, "kind": "attribute", "displayName": "Variable Send", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the [...] + "variableReceive": { "index": 5, "kind": "attribute", "displayName": "Variable Receive", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not o [...] } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/unmarshal.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/unmarshal.json index fe21bf9f735..202b7a8f74b 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/unmarshal.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/unmarshal.json @@ -16,6 +16,8 @@ "description": { "index": 1, "kind": "element", "displayName": "Description", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the description of this node" }, "disabled": { "index": 2, "kind": "attribute", "displayName": "Disabled", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to disable this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later at runtime." }, "dataFormatType": { "index": 3, "kind": "element", "displayName": "Data Format Type", "required": true, "type": "object", "javaType": "org.apache.camel.model.DataFormatDefinition", "oneOf": [ "asn1", "avro", "barcode", "base64", "bindy", "cbor", "crypto", "csv", "custom", "fhirJson", "fhirXml", "flatpack", "grok", "gzipDeflater", "hl7", "ical", "jacksonXml", "jaxb", "json", "jsonApi", "lzf", "mimeMultipart", "parquetAvro", "pgp", "protobuf", "rss", "soap", "swiftMt", "swiftMx", "sysl [...] - "allowNullBody": { "index": 4, "kind": "attribute", "displayName": "Allow Null Body", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Indicates whether null is allowed as value of a body to unmarshall." } + "variableSend": { "index": 4, "kind": "attribute", "displayName": "Variable Send", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the [...] + "variableReceive": { "index": 5, "kind": "attribute", "displayName": "Variable Receive", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not o [...] + "allowNullBody": { "index": 6, "kind": "attribute", "displayName": "Allow Null Body", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Indicates whether null is allowed as value of a body to unmarshall." } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd index 0dc0cfd581e..37d14072f8a 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd @@ -7116,6 +7116,28 @@ down. Default value: false <xs:element ref="tns:zipFile"/> </xs:choice> </xs:sequence> + <xs:attribute name="variableSend" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +To use a variable to store the received message body (only body, not headers). This is handy for easy access to the +received message body via variables. Important: When using receive variable then the received body is stored only in +this variable and not on the current org.apache.camel.Message . +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="variableReceive" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +To use a variable to store the received message body (only body, not headers). This is handy for easy access to the +received message body via variables. Important: When using receive variable then the received body is stored only in +this variable and not on the current org.apache.camel.Message . +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> </xs:extension> </xs:complexContent> </xs:complexType> @@ -13952,6 +13974,28 @@ To type used as a target data type in the transformation. <xs:element ref="tns:zipFile"/> </xs:choice> </xs:sequence> + <xs:attribute name="variableSend" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +To use a variable to store the received message body (only body, not headers). This is handy for easy access to the +received message body via variables. Important: When using receive variable then the received body is stored only in +this variable and not on the current org.apache.camel.Message . +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="variableReceive" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +To use a variable to store the received message body (only body, not headers). This is handy for easy access to the +received message body via variables. Important: When using receive variable then the received body is stored only in +this variable and not on the current org.apache.camel.Message . +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> <xs:attribute name="allowNullBody" type="xs:string"> <xs:annotation> <xs:documentation xml:lang="en"> diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringMarshalVariableTest.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringMarshalVariableTest.java new file mode 100644 index 00000000000..8f320040fa9 --- /dev/null +++ b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringMarshalVariableTest.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.processor; + +import org.apache.camel.CamelContext; +import org.apache.camel.processor.MarshalVariableTest; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +public class SpringMarshalVariableTest extends MarshalVariableTest { + @Override + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/processor/MarshalVariableTest.xml"); + } +} diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringUnmarshalVariableTest.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringUnmarshalVariableTest.java new file mode 100644 index 00000000000..09918671cdb --- /dev/null +++ b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringUnmarshalVariableTest.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.processor; + +import org.apache.camel.CamelContext; +import org.apache.camel.processor.UnmarshalVariableTest; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +public class SpringUnmarshalVariableTest extends UnmarshalVariableTest { + @Override + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/processor/UnmarshalVariableTest.xml"); + } +} diff --git a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/MarshalVariableTest.xml b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/MarshalVariableTest.xml new file mode 100644 index 00000000000..9e1c7b0a510 --- /dev/null +++ b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/MarshalVariableTest.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <bean id="myDF" class="org.apache.camel.processor.MarshalVariableTest.MyByeDataFormat"/> + + <!-- START SNIPPET: example --> + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <jmxAgent id="jmx" disabled="true"/> + <route> + <from uri="direct:send"/> + <setVariable name="hello"> + <simple>Camel</simple> + </setVariable> + <to uri="mock:before"/> + <marshal variableSend="hello"> + <custom ref="myDF"/> + </marshal> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:receive"/> + <marshal variableReceive="bye"> + <custom ref="myDF"/> + </marshal> + <to uri="mock:after"/> + <setBody> + <simple>${variable:bye}</simple> + </setBody> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:sendAndReceive"/> + <setVariable name="hello"> + <simple>Camel</simple> + </setVariable> + <to uri="mock:before"/> + <marshal variableSend="hello" variableReceive="bye"> + <custom ref="myDF"/> + </marshal> + <to uri="mock:result"/> + </route> + </camelContext> + <!-- END SNIPPET: example --> + +</beans> diff --git a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/UnmarshalVariableTest.xml b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/UnmarshalVariableTest.xml new file mode 100644 index 00000000000..845acabd1cf --- /dev/null +++ b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/UnmarshalVariableTest.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <bean id="myDF" class="org.apache.camel.processor.UnmarshalVariableTest.MyByeDataFormat"/> + + <!-- START SNIPPET: example --> + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <jmxAgent id="jmx" disabled="true"/> + <route> + <from uri="direct:send"/> + <setVariable name="hello"> + <simple>Camel</simple> + </setVariable> + <to uri="mock:before"/> + <unmarshal variableSend="hello"> + <custom ref="myDF"/> + </unmarshal> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:receive"/> + <unmarshal variableReceive="bye"> + <custom ref="myDF"/> + </unmarshal> + <to uri="mock:after"/> + <setBody> + <simple>${variable:bye}</simple> + </setBody> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:sendAndReceive"/> + <setVariable name="hello"> + <simple>Camel</simple> + </setVariable> + <to uri="mock:before"/> + <unmarshal variableSend="hello" variableReceive="bye"> + <custom ref="myDF"/> + </unmarshal> + <to uri="mock:result"/> + </route> + </camelContext> + <!-- END SNIPPET: example --> + +</beans> 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 b6116965d2a..940c91db3e9 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 @@ -9058,6 +9058,8 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "univocityCsv", type = "object:org.apache.camel.model.dataformat.UniVocityCsvDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "univocityFixed", type = "object:org.apache.camel.model.dataformat.UniVocityFixedDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "univocityTsv", type = "object:org.apache.camel.model.dataformat.UniVocityTsvDataFormat", oneOf = "dataFormatType"), + @YamlProperty(name = "variableReceive", type = "string", description = "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message .", displayName = "Variable Receive"), + @YamlProperty(name = "variableSend", type = "string", description = "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message .", displayName = "Variable Send"), @YamlProperty(name = "xmlSecurity", type = "object:org.apache.camel.model.dataformat.XMLSecurityDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "yaml", type = "object:org.apache.camel.model.dataformat.YAMLDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "zipDeflater", type = "object:org.apache.camel.model.dataformat.ZipDeflaterDataFormat", oneOf = "dataFormatType"), @@ -9294,6 +9296,16 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setInheritErrorHandler(java.lang.Boolean.valueOf(val)); break; } + case "variableReceive": { + String val = asText(node); + target.setVariableReceive(val); + break; + } + case "variableSend": { + String val = asText(node); + target.setVariableSend(val); + break; + } case "id": { String val = asText(node); target.setId(val); @@ -19266,6 +19278,8 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "univocityCsv", type = "object:org.apache.camel.model.dataformat.UniVocityCsvDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "univocityFixed", type = "object:org.apache.camel.model.dataformat.UniVocityFixedDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "univocityTsv", type = "object:org.apache.camel.model.dataformat.UniVocityTsvDataFormat", oneOf = "dataFormatType"), + @YamlProperty(name = "variableReceive", type = "string", description = "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message .", displayName = "Variable Receive"), + @YamlProperty(name = "variableSend", type = "string", description = "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message .", displayName = "Variable Send"), @YamlProperty(name = "xmlSecurity", type = "object:org.apache.camel.model.dataformat.XMLSecurityDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "yaml", type = "object:org.apache.camel.model.dataformat.YAMLDataFormat", oneOf = "dataFormatType"), @YamlProperty(name = "zipDeflater", type = "object:org.apache.camel.model.dataformat.ZipDeflaterDataFormat", oneOf = "dataFormatType"), @@ -19507,6 +19521,16 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setInheritErrorHandler(java.lang.Boolean.valueOf(val)); break; } + case "variableReceive": { + String val = asText(node); + target.setVariableReceive(val); + break; + } + case "variableSend": { + String val = asText(node); + target.setVariableSend(val); + break; + } case "id": { String val = asText(node); target.setId(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 8737486cc97..ab37e0111dd 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 @@ -3075,6 +3075,16 @@ "title" : "Id", "description" : "Sets the id of this node" }, + "variableReceive" : { + "type" : "string", + "title" : "Variable Receive", + "description" : "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message ." + }, + "variableSend" : { + "type" : "string", + "title" : "Variable Send", + "description" : "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message ." + }, "asn1" : { }, "avro" : { }, "barcode" : { }, @@ -7176,6 +7186,16 @@ "title" : "Id", "description" : "Sets the id of this node" }, + "variableReceive" : { + "type" : "string", + "title" : "Variable Receive", + "description" : "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message ." + }, + "variableSend" : { + "type" : "string", + "title" : "Variable Send", + "description" : "To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current org.apache.camel.Message ." + }, "asn1" : { }, "avro" : { }, "barcode" : { }, diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/MarshalVariableTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/MarshalVariableTest.groovy new file mode 100644 index 00000000000..05ba3cf1742 --- /dev/null +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/MarshalVariableTest.groovy @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dsl.yaml + +import org.apache.camel.Exchange +import org.apache.camel.component.mock.MockEndpoint +import org.apache.camel.dsl.yaml.support.YamlTestSupport +import org.apache.camel.spi.DataFormat +import org.apache.camel.support.service.ServiceSupport + +class MarshalVariableTest extends YamlTestSupport { + + def "marshalVariable send"() { + setup: + loadRoutes ''' + - route: + from: + uri: direct:send + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - marshal: + custom: myDF + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:receive + steps: + - marshal: + custom: myDF + variableReceive: bye + - to: + uri: mock:after + - setBody: + simple: + expression: "${variable:bye}" + - to: + uri: mock:result + - route: + from: + uri: direct:sendAndReceive + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - marshal: + custom: myDF + variableReceive: bye + variableSend: hello + - to: + uri: mock:result + ''' + + withMock('mock:before') { + expectedBodiesReceived 'World' + expectedVariableReceived("hello", "Camel") + } + withMock('mock:result') { + expectedBodiesReceived 'Bye Camel' + expectedVariableReceived("hello", "Camel") + } + + when: + context.registry.bind("myDF", new MyByeDataFormat()) + context.start() + + withTemplate { + to('direct:send').withBody('World').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + + + def "marshalVariable receive"() { + setup: + loadRoutes ''' + - route: + from: + uri: direct:send + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - marshal: + custom: myDF + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:receive + steps: + - marshal: + custom: myDF + variableReceive: bye + - to: + uri: mock:after + - setBody: + simple: + expression: "${variable:bye}" + - to: + uri: mock:result + - route: + from: + uri: direct:sendAndReceive + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - marshal: + custom: myDF + variableReceive: bye + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:foo + steps: + - transform: + simple: + expression: "Bye ${body}" + ''' + + withMock('mock:after') { + expectedBodiesReceived 'World' + expectedVariableReceived("bye", "Bye World") + } + withMock('mock:result') { + expectedBodiesReceived 'Bye World' + expectedVariableReceived("bye", "Bye World") + } + + when: + context.registry.bind("myDF", new MyByeDataFormat()) + context.start() + + withTemplate { + to('direct:receive').withBody('World').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + + def "marshalVariable sendAndReceive"() { + setup: + loadRoutes ''' + - route: + from: + uri: direct:send + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - marshal: + custom: myDF + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:receive + steps: + - marshal: + custom: myDF + variableReceive: bye + - to: + uri: mock:after + - setBody: + simple: + expression: "${variable:bye}" + - to: + uri: mock:result + - route: + from: + uri: direct:sendAndReceive + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - marshal: + custom: myDF + variableReceive: bye + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:foo + steps: + - transform: + simple: + expression: "Bye ${body}" + ''' + + withMock('mock:before') { + expectedBodiesReceived 'World' + expectedVariableReceived("hello", "Camel") + } + withMock('mock:result') { + expectedBodiesReceived 'World' + expectedVariableReceived("bye", "Bye Camel") + } + + when: + context.registry.bind("myDF", new MyByeDataFormat()) + context.start() + + withTemplate { + to('direct:sendAndReceive').withBody('World').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + + static class MyByeDataFormat extends ServiceSupport implements DataFormat { + + @Override + void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { + String line = "Bye " + graph.toString(); + stream.write(line.getBytes()); + } + + @Override + Object unmarshal(Exchange exchange, InputStream stream) throws Exception { + // noop + return null; + } + } + +} diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/UnmarshalVariableTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/UnmarshalVariableTest.groovy new file mode 100644 index 00000000000..a03879a6186 --- /dev/null +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/UnmarshalVariableTest.groovy @@ -0,0 +1,268 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dsl.yaml + +import org.apache.camel.Exchange +import org.apache.camel.component.mock.MockEndpoint +import org.apache.camel.dsl.yaml.support.YamlTestSupport +import org.apache.camel.spi.DataFormat +import org.apache.camel.support.service.ServiceSupport + +class UnmarshalVariableTest extends YamlTestSupport { + + def "unmarshalVariable send"() { + setup: + loadRoutes ''' + - route: + from: + uri: direct:send + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - unmarshal: + custom: myDF + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:receive + steps: + - unmarshal: + custom: myDF + variableReceive: bye + - to: + uri: mock:after + - setBody: + simple: + expression: "${variable:bye}" + - to: + uri: mock:result + - route: + from: + uri: direct:sendAndReceive + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - unmarshal: + custom: myDF + variableReceive: bye + variableSend: hello + - to: + uri: mock:result + ''' + + withMock('mock:before') { + expectedBodiesReceived 'World' + expectedVariableReceived("hello", "Camel") + } + withMock('mock:result') { + expectedBodiesReceived 'Bye Camel' + expectedVariableReceived("hello", "Camel") + } + + when: + context.registry.bind("myDF", new MyByeDataFormat()) + context.start() + + withTemplate { + to('direct:send').withBody('World').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + + + def "unmarshalVariable receive"() { + setup: + loadRoutes ''' + - route: + from: + uri: direct:send + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - unmarshal: + custom: myDF + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:receive + steps: + - unmarshal: + custom: myDF + variableReceive: bye + - to: + uri: mock:after + - setBody: + simple: + expression: "${variable:bye}" + - to: + uri: mock:result + - route: + from: + uri: direct:sendAndReceive + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - unmarshal: + custom: myDF + variableReceive: bye + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:foo + steps: + - transform: + simple: + expression: "Bye ${body}" + ''' + + withMock('mock:after') { + expectedBodiesReceived 'World' + expectedVariableReceived("bye", "Bye World") + } + withMock('mock:result') { + expectedBodiesReceived 'Bye World' + expectedVariableReceived("bye", "Bye World") + } + + when: + context.registry.bind("myDF", new MyByeDataFormat()) + context.start() + + withTemplate { + to('direct:receive').withBody('World').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + + def "unmarshalVariable sendAndReceive"() { + setup: + loadRoutes ''' + - route: + from: + uri: direct:send + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - unmarshal: + custom: myDF + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:receive + steps: + - unmarshal: + custom: myDF + variableReceive: bye + - to: + uri: mock:after + - setBody: + simple: + expression: "${variable:bye}" + - to: + uri: mock:result + - route: + from: + uri: direct:sendAndReceive + steps: + - setVariable: + name: hello + simple: + expression: Camel + - to: + uri: mock:before + - unmarshal: + custom: myDF + variableReceive: bye + variableSend: hello + - to: + uri: mock:result + - route: + from: + uri: direct:foo + steps: + - transform: + simple: + expression: "Bye ${body}" + ''' + + withMock('mock:before') { + expectedBodiesReceived 'World' + expectedVariableReceived("hello", "Camel") + } + withMock('mock:result') { + expectedBodiesReceived 'World' + expectedVariableReceived("bye", "Bye Camel") + } + + when: + context.registry.bind("myDF", new MyByeDataFormat()) + context.start() + + withTemplate { + to('direct:sendAndReceive').withBody('World').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + + static class MyByeDataFormat extends ServiceSupport implements DataFormat { + + @Override + void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { + // noop + } + + @Override + Object unmarshal(Exchange exchange, InputStream stream) throws Exception { + return "Bye " + exchange.getContext().getTypeConverter().convertTo(String.class, exchange, stream); + } + } + +}