This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch backport/30212-to-camel-4-18-x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7b8a9cf6d1a350f852fb3a785b12cf8110139921 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Nov 18 21:03:37 2026 +0100 CAMEL-27052: camel-jaxb - the part class and namespace headers are used only when allowPartClassFromHeader is enabled (#30212) The JAXB data format always read the CamelJaxbPartClass and CamelJaxbPartNamespace headers, on unmarshal and marshal, and when set they took precedence over the partClass and partNamespace options. A new option allowPartClassFromHeader (default false) makes them opt-in, in line with allowUnmarshallType of the Jackson, Gson and JSON-B data formats. When disabled, the headers are ignored and the configured partClass and partNamespace apply. - The SOAP data format extends the JAXB data format and always ignores these headers; it has no such option, as a part class from a header always fails there with "Expected Soap Envelope". - The Rest DSL binding does not take allowPartClassFromHeader from the JAXB data format on the CamelContext (it is in RestBindingAdviceFactory.NOT_INHERITED_OPTIONS, next to partClass); set it with the xml.in./xml.out. data format property when the binding needs it. - Docs, the 4.24 upgrade guide and the regenerated metadata, catalog and DSL parsers and schemas. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit f8036a4c935488138414bdc53d575aa4c4208d4b) Signed-off-by: Claus Ibsen <[email protected]> --- .../org/apache/camel/catalog/dataformats/jaxb.json | 15 +-- .../org/apache/camel/catalog/models/jaxb.json | 15 +-- .../apache/camel/catalog/schemas/camel-spring.xsd | 11 ++ .../apache/camel/catalog/schemas/camel-xml-io.xsd | 11 ++ .../converter/jaxb/JaxbDataFormatConfigurer.java | 7 ++ .../org/apache/camel/converter/jaxb/jaxb.json | 15 +-- .../camel-jaxb/src/main/docs/jaxb-dataformat.adoc | 32 ++++-- .../camel/converter/jaxb/JaxbDataFormat.java | 24 +++- .../jaxb/JaxbDataFormatPartClassHeaderTest.java | 1 + .../jaxb/JaxbPartClassHeaderOptionTest.java | 124 +++++++++++++++++++++ .../JaxbPartClassHeaderStatePollutionTest.java | 2 + .../rest/RestJettyNoContentRestConfigTest.java | 3 +- .../jetty/rest/RestJettyNoContentTest.java | 3 +- .../rest/RestServletNoContentRestConfigTest.java | 3 +- .../servlet/rest/RestServletNoContentTest.java | 3 +- .../camel/dataformat/soap/SoapUnMarshalTest.java | 15 +++ .../org/apache/camel/model/dataformat/jaxb.json | 15 +-- .../camel/model/dataformat/JaxbDataFormat.java | 39 +++++++ .../reifier/dataformat/JaxbDataFormatReifier.java | 1 + .../java/org/apache/camel/xml/in/ModelParser.java | 1 + .../java/org/apache/camel/xml/out/ModelWriter.java | 1 + .../org/apache/camel/yaml/out/ModelWriter.java | 1 + .../dsl/yaml/deserializers/ModelDeserializers.java | 6 + .../generated/resources/schema/camelYamlDsl.json | 6 + 24 files changed, 309 insertions(+), 45 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json index ba39d5a62b9b..7d0d1464c978 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json @@ -30,12 +30,13 @@ "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To turn on marshalling XML fragment trees. By default JAXB looks for XmlRootElement annotation on given class to operate on whole XML tree. This is useful but not always - sometimes generated code does n [...] "partClass": { "index": 12, "kind": "attribute", "displayName": "Part Class", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class used for fragment parsing. See more details at the fragment option." }, "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part Namespace", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "XML namespace to use for fragment parsing. See more details at the fragment option." }, - "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] - "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, - "schemaLocation": { "index": 16, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, - "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, - "jaxbProviderProperties": { "index": 18, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, - "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] - "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] + "allowPartClassFromHeader": { "index": 14, "kind": "attribute", "displayName": "Allow Part Class From Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and partNamespace options when marshalling and unmarshal [...] + "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] + "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, + "schemaLocation": { "index": 17, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, + "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, + "jaxbProviderProperties": { "index": 19, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, + "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] + "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json index e59e07fc6fc6..4f7f4aa67263 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json @@ -27,12 +27,13 @@ "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To turn on marshalling XML fragment trees. By default JAXB looks for XmlRootElement annotation on given class to operate on whole XML tree. This is useful but not always - sometimes generated code does n [...] "partClass": { "index": 12, "kind": "attribute", "displayName": "Part Class", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class used for fragment parsing. See more details at the fragment option." }, "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part Namespace", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "XML namespace to use for fragment parsing. See more details at the fragment option." }, - "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] - "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, - "schemaLocation": { "index": 16, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, - "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, - "jaxbProviderProperties": { "index": 18, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, - "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] - "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] + "allowPartClassFromHeader": { "index": 14, "kind": "attribute", "displayName": "Allow Part Class From Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and partNamespace options when marshalling and unmarshal [...] + "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] + "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, + "schemaLocation": { "index": 17, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, + "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, + "jaxbProviderProperties": { "index": 19, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, + "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] + "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] } } 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 369cbaf34618..61c75accacac 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 @@ -9429,6 +9429,17 @@ Name of class used for fragment parsing. See more details at the fragment option <xs:documentation xml:lang="en"> <![CDATA[ XML namespace to use for fragment parsing. See more details at the fragment option. +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="allowPartClassFromHeader" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and +partNamespace options when marshalling and unmarshalling. Enable it only when the route sets these headers itself, not +on routes that receive them from external systems. Default value: false ]]> </xs:documentation> </xs:annotation> diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd index 2320af84ae96..978f4e954553 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd @@ -8102,6 +8102,17 @@ Name of class used for fragment parsing. See more details at the fragment option <xs:documentation xml:lang="en"> <![CDATA[ XML namespace to use for fragment parsing. See more details at the fragment option. +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="allowPartClassFromHeader" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and +partNamespace options when marshalling and unmarshalling. Enable it only when the route sets these headers itself, not +on routes that receive them from external systems. Default value: false ]]> </xs:documentation> </xs:annotation> diff --git a/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java b/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java index 82d228749d68..92829bdc5b76 100644 --- a/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java +++ b/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java @@ -23,6 +23,7 @@ public class JaxbDataFormatConfigurer extends org.apache.camel.support.component static { Map<String, Object> map = new CaseInsensitiveMap(); map.put("AccessExternalSchemaProtocols", java.lang.String.class); + map.put("AllowPartClassFromHeader", boolean.class); map.put("ContentTypeHeader", boolean.class); map.put("ContextPath", java.lang.String.class); map.put("ContextPathIsClassName", boolean.class); @@ -51,6 +52,8 @@ public class JaxbDataFormatConfigurer extends org.apache.camel.support.component switch (ignoreCase ? name.toLowerCase() : name) { case "accessexternalschemaprotocols": case "accessExternalSchemaProtocols": target.setAccessExternalSchemaProtocols(property(camelContext, java.lang.String.class, value)); return true; + case "allowpartclassfromheader": + case "allowPartClassFromHeader": target.setAllowPartClassFromHeader(property(camelContext, boolean.class, value)); return true; case "contenttypeheader": case "contentTypeHeader": target.setContentTypeHeader(property(camelContext, boolean.class, value)); return true; case "contextpath": @@ -100,6 +103,8 @@ public class JaxbDataFormatConfigurer extends org.apache.camel.support.component switch (ignoreCase ? name.toLowerCase() : name) { case "accessexternalschemaprotocols": case "accessExternalSchemaProtocols": return java.lang.String.class; + case "allowpartclassfromheader": + case "allowPartClassFromHeader": return boolean.class; case "contenttypeheader": case "contentTypeHeader": return boolean.class; case "contextpath": @@ -145,6 +150,8 @@ public class JaxbDataFormatConfigurer extends org.apache.camel.support.component switch (ignoreCase ? name.toLowerCase() : name) { case "accessexternalschemaprotocols": case "accessExternalSchemaProtocols": return target.getAccessExternalSchemaProtocols(); + case "allowpartclassfromheader": + case "allowPartClassFromHeader": return target.isAllowPartClassFromHeader(); case "contenttypeheader": case "contentTypeHeader": return target.isContentTypeHeader(); case "contextpath": diff --git a/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json b/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json index ba39d5a62b9b..7d0d1464c978 100644 --- a/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json +++ b/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json @@ -30,12 +30,13 @@ "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To turn on marshalling XML fragment trees. By default JAXB looks for XmlRootElement annotation on given class to operate on whole XML tree. This is useful but not always - sometimes generated code does n [...] "partClass": { "index": 12, "kind": "attribute", "displayName": "Part Class", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class used for fragment parsing. See more details at the fragment option." }, "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part Namespace", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "XML namespace to use for fragment parsing. See more details at the fragment option." }, - "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] - "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, - "schemaLocation": { "index": 16, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, - "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, - "jaxbProviderProperties": { "index": 18, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, - "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] - "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] + "allowPartClassFromHeader": { "index": 14, "kind": "attribute", "displayName": "Allow Part Class From Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and partNamespace options when marshalling and unmarshal [...] + "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] + "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, + "schemaLocation": { "index": 17, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, + "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, + "jaxbProviderProperties": { "index": 19, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, + "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] + "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] } } diff --git a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc index aed39ed82b6c..c709b3d20424 100644 --- a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc +++ b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc @@ -95,24 +95,36 @@ need to unmarshall only part of the tree. In that case, you can use partial unmarshalling. To enable this behavior, you need set property `partClass` on the `JaxbDataFormat`. Camel will pass this class -to the JAXB unmarshaller. If `JaxbConstants.JAXB_PART_CLASS` is set as -one of the exchange headers, its value is used to override the `partClass` property -on the `JaxbDataFormat`. +to the JAXB unmarshaller. For marshalling you have to add the `partNamespace` attribute with the `QName` of the destination namespace. -If `JaxbConstants.JAXB_PART_NAMESPACE` is set as -one of the exchange headers, its value is used to override the `partNamespace` property -on the `JaxbDataFormat`. +==== Choosing the part class with headers -While setting `partNamespace` through `JaxbConstants.JAXB_PART_NAMESPACE`, please +To choose the part class and namespace per message, enable the `allowPartClassFromHeader` option +(default `false`). Then the following exchange headers, when set, are used instead of the +`partClass` and `partNamespace` options on the `JaxbDataFormat`: + +* `CamelJaxbPartClass`: the class name used instead of `partClass`, when marshalling and unmarshalling. +* `CamelJaxbPartNamespace`: the namespace used instead of `partNamespace`, when marshalling. + +When `allowPartClassFromHeader` is `false`, these headers are ignored. + +While setting `partNamespace` through the `CamelJaxbPartNamespace` header, please note that you need to specify its value in the format `\{namespaceUri\}localPart`, as per the example below. [source,java] --------------------------------------------------------------------------------------- -.setHeader(JaxbConstants.JAXB_PART_NAMESPACE, constant("{http://www.camel.apache.org/jaxb/example/address/1}address")); --------------------------------------------------------------------------------------- +---- +JaxbDataFormat jaxb = new JaxbDataFormat("com.mycompany.model"); +jaxb.setAllowPartClassFromHeader(true); + +from("direct:start") + .setHeader("CamelJaxbPartClass", constant("com.mycompany.model.Address")) + .setHeader("CamelJaxbPartNamespace", constant("{http://www.camel.apache.org/jaxb/example/address/1}address")) + .marshal(jaxb) + .to("mock:result"); +---- === Fragment diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java index 6ef18ca80983..c6dfa101989f 100644 --- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java +++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java @@ -99,6 +99,7 @@ public class JaxbDataFormat extends ServiceSupport // partial support private QName partNamespace; private Class<?> partClass; + private boolean allowPartClassFromHeader; private Map<String, String> namespacePrefix; private JaxbNamespacePrefixMapper namespacePrefixMapper; private JaxbXmlStreamWriterWrapper xmlStreamWriterWrapper; @@ -189,8 +190,12 @@ public class JaxbDataFormat extends ServiceSupport Object element = graph; QName partNamespaceOnDataFormat = getPartNamespace(); - String partClassFromHeader = exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class); - String partNamespaceFromHeader = exchange.getIn().getHeader(JaxbConstants.JAXB_PART_NAMESPACE, String.class); + String partClassFromHeader = null; + String partNamespaceFromHeader = null; + if (allowPartClassFromHeader) { + partClassFromHeader = exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class); + partNamespaceFromHeader = exchange.getIn().getHeader(JaxbConstants.JAXB_PART_NAMESPACE, String.class); + } if ((partClass != null || partClassFromHeader != null) && (partNamespaceOnDataFormat != null || partNamespaceFromHeader != null)) { element = toElement(graph, partClassFromHeader, partNamespaceFromHeader, partNamespaceOnDataFormat); @@ -331,7 +336,8 @@ public class JaxbDataFormat extends ServiceSupport xmlReader = typeConverter.convertTo(XMLStreamReader.class, exchange, is); } } - String partClassFromHeader = exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class); + String partClassFromHeader = allowPartClassFromHeader + ? exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class) : null; Class<?> effectivePartClass = partClass; if (partClassFromHeader != null) { try { @@ -495,6 +501,18 @@ public class JaxbDataFormat extends ServiceSupport this.partClass = partClass; } + public boolean isAllowPartClassFromHeader() { + return allowPartClassFromHeader; + } + + /** + * Whether the {@link JaxbConstants#JAXB_PART_CLASS} and {@link JaxbConstants#JAXB_PART_NAMESPACE} headers are used, + * when set, instead of the partClass and partNamespace options when marshalling and unmarshalling. + */ + public void setAllowPartClassFromHeader(boolean allowPartClassFromHeader) { + this.allowPartClassFromHeader = allowPartClassFromHeader; + } + public Map<String, String> getNamespacePrefix() { return namespacePrefix; } diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java index 0c224bf7a047..536c25047b02 100644 --- a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java +++ b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java @@ -75,6 +75,7 @@ public class JaxbDataFormatPartClassHeaderTest extends CamelTestSupport { jaxbDataFormat.setPartNamespace( new QName("http://www.camel.apache.org/jaxb/example/address/123", "addressToBeOverriden")); jaxbDataFormat.setPrettyPrint(true); + jaxbDataFormat.setAllowPartClassFromHeader(true); from("direct:marshall") .setHeader(JaxbConstants.JAXB_PART_CLASS, simple("org.apache.camel.example.Address")) diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderOptionTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderOptionTest.java new file mode 100644 index 000000000000..3ab41f1acd41 --- /dev/null +++ b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderOptionTest.java @@ -0,0 +1,124 @@ +/* + * 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.converter.jaxb; + +import javax.xml.namespace.QName; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.example.Address; +import org.apache.camel.example.Partial; +import org.apache.camel.example.PurchaseOrder; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * The CamelJaxbPartClass and CamelJaxbPartNamespace headers are used only when allowPartClassFromHeader is enabled. + */ +public class JaxbPartClassHeaderOptionTest extends CamelTestSupport { + + private static final String ADDRESS_NAMESPACE = "http://www.camel.apache.org/jaxb/example/address/1"; + + private static final String PARTIAL_XML = "<partial name=\"foo\"><location>Here</location></partial>"; + + private static final String PURCHASE_ORDER_XML = "<purchaseOrder name=\"foo\" price=\"1.23\" amount=\"2.0\"/>"; + + @Test + public void partClassHeaderIgnoredByDefault() { + Object body = template.requestBodyAndHeader("direct:unmarshal", PARTIAL_XML, + JaxbConstants.JAXB_PART_CLASS, Address.class.getName()); + + Partial partial = assertInstanceOf(Partial.class, body); + assertEquals("foo", partial.getName()); + assertEquals("Here", partial.getLocation()); + } + + @Test + public void partClassHeaderUsedWhenAllowed() { + Object body = template.requestBodyAndHeader("direct:unmarshalAllowed", PARTIAL_XML, + JaxbConstants.JAXB_PART_CLASS, Address.class.getName()); + + assertInstanceOf(Address.class, body); + } + + @Test + public void partClassHeaderAloneDoesNotEnablePartialUnmarshalByDefault() { + Object body = template.requestBodyAndHeader("direct:unmarshalNoPartClass", PURCHASE_ORDER_XML, + JaxbConstants.JAXB_PART_CLASS, Address.class.getName()); + + PurchaseOrder order = assertInstanceOf(PurchaseOrder.class, body); + assertEquals("foo", order.getName()); + } + + @Test + public void partNamespaceHeaderIgnoredByDefaultOnMarshal() { + String xml = template.requestBodyAndHeader("direct:marshal", createAddress(), + JaxbConstants.JAXB_PART_NAMESPACE, "{" + ADDRESS_NAMESPACE + "}shippingAddress", String.class); + + assertTrue(xml.contains("<address:address"), xml); + assertFalse(xml.contains("shippingAddress"), xml); + } + + @Test + public void partNamespaceHeaderUsedWhenAllowed() { + String xml = template.requestBodyAndHeader("direct:marshalAllowed", createAddress(), + JaxbConstants.JAXB_PART_NAMESPACE, "{" + ADDRESS_NAMESPACE + "}shippingAddress", String.class); + + assertTrue(xml.contains("<address:shippingAddress"), xml); + } + + private static Address createAddress() { + Address address = new Address(); + address.setStreet("Main Street"); + address.setStreetNumber("3a"); + address.setZip("65843"); + address.setCity("Sulzbach"); + return address; + } + + private static JaxbDataFormat createDataFormat(Class<?> partClass, boolean allowPartClassFromHeader) { + JaxbDataFormat jaxb = new JaxbDataFormat(); + jaxb.setContextPath(Address.class.getPackage().getName()); + jaxb.setPartClass(partClass); + jaxb.setAllowPartClassFromHeader(allowPartClassFromHeader); + return jaxb; + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:unmarshal").unmarshal(createDataFormat(Partial.class, false)); + from("direct:unmarshalAllowed").unmarshal(createDataFormat(Partial.class, true)); + from("direct:unmarshalNoPartClass").unmarshal(createDataFormat(null, false)); + + JaxbDataFormat marshal = createDataFormat(Address.class, false); + marshal.setPartNamespace(new QName(ADDRESS_NAMESPACE, "address")); + from("direct:marshal").marshal(marshal); + + JaxbDataFormat marshalAllowed = createDataFormat(Address.class, true); + marshalAllowed.setPartNamespace(new QName(ADDRESS_NAMESPACE, "address")); + from("direct:marshalAllowed").marshal(marshalAllowed); + } + }; + } +} diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderStatePollutionTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderStatePollutionTest.java index 5dd38078f532..a7aeca2c5c03 100644 --- a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderStatePollutionTest.java +++ b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderStatePollutionTest.java @@ -122,6 +122,7 @@ public class JaxbPartClassHeaderStatePollutionTest extends CamelTestSupport { public void configure() { JaxbDataFormat jaxb = new JaxbDataFormat(); jaxb.setContextPath("org.apache.camel.example"); + jaxb.setAllowPartClassFromHeader(true); from("direct:unmarshal") .unmarshal(jaxb) @@ -130,6 +131,7 @@ public class JaxbPartClassHeaderStatePollutionTest extends CamelTestSupport { JaxbDataFormat jaxbMarshal = new JaxbDataFormat(); jaxbMarshal.setContextPath("org.apache.camel.example"); jaxbMarshal.setPrettyPrint(true); + jaxbMarshal.setAllowPartClassFromHeader(true); from("direct:marshal") .marshal(jaxbMarshal) diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java index bad2a6b73535..44112fcad041 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java @@ -140,7 +140,8 @@ public class RestJettyNoContentRestConfigTest extends BaseJettyTest { @Override public void configure() { restConfiguration().component("jetty").host("localhost").port(getPort()) - .bindingMode(RestBindingMode.auto).enableNoContentResponse(true); + .bindingMode(RestBindingMode.auto).enableNoContentResponse(true) + .dataFormatProperty("xml.out.allowPartClassFromHeader", "true"); rest("/v1/empty") .get("/country").to("direct:v1country") diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java index 30acebbfc74a..40c097747368 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java @@ -140,7 +140,8 @@ public class RestJettyNoContentTest extends BaseJettyTest { @Override public void configure() { restConfiguration().component("jetty").host("localhost").port(getPort()) - .bindingMode(RestBindingMode.auto); + .bindingMode(RestBindingMode.auto) + .dataFormatProperty("xml.out.allowPartClassFromHeader", "true"); rest("/v1/empty") .get("/country").to("direct:v1country") diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java index 78723c714759..2a05e63428bd 100644 --- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java +++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java @@ -106,7 +106,8 @@ public class RestServletNoContentRestConfigTest extends ServletCamelRouterTestSu @Override public void configure() { restConfiguration().component("servlet").host("localhost") - .bindingMode(RestBindingMode.auto).enableNoContentResponse(true); + .bindingMode(RestBindingMode.auto).enableNoContentResponse(true) + .dataFormatProperty("xml.out.allowPartClassFromHeader", "true"); rest("/v1/empty") .get("/country").to("direct:v1country") diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java index 65ee18339a89..46cdcddbf500 100644 --- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java +++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java @@ -105,7 +105,8 @@ public class RestServletNoContentTest extends ServletCamelRouterTestSupport { @Override public void configure() { restConfiguration().component("servlet").host("localhost") - .bindingMode(RestBindingMode.auto); + .bindingMode(RestBindingMode.auto) + .dataFormatProperty("xml.out.allowPartClassFromHeader", "true"); rest("/v1/empty") .get("/country").to("direct:v1country") diff --git a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java index 132e332b89fb..d2dfe2877731 100644 --- a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java +++ b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java @@ -18,6 +18,7 @@ package org.apache.camel.dataformat.soap; import java.io.IOException; import java.io.InputStream; +import java.util.Map; import jakarta.xml.ws.soap.SOAPFaultException; @@ -28,6 +29,7 @@ import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.converter.jaxb.JaxbConstants; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; @@ -60,6 +62,19 @@ public class SoapUnMarshalTest extends CamelTestSupport { assertEquals("Smith", request.getName()); } + @Test + public void testUnMarshalSoapIgnoresPartClassHeaders() throws IOException, InterruptedException { + resultEndpoint.expectedMessageCount(1); + InputStream in = this.getClass().getResourceAsStream("request.xml"); + producer.sendBodyAndHeaders(in, Map.of( + JaxbConstants.JAXB_PART_CLASS, GetCustomersByName.class.getName(), + JaxbConstants.JAXB_PART_NAMESPACE, "{http://customerservice.example.com/}getCustomersByName")); + resultEndpoint.assertIsSatisfied(); + Object body = resultEndpoint.getExchanges().get(0).getIn().getBody(); + assertEquals(GetCustomersByName.class, body.getClass()); + assertEquals("Smith", ((GetCustomersByName) body).getName()); + } + @Test public void testUnMarshalSoapFaultWithoutDetail() throws IOException, InterruptedException { InputStream in = this.getClass().getResourceAsStream("faultWithoutDetail.xml"); diff --git a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json index e59e07fc6fc6..4f7f4aa67263 100644 --- a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json +++ b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json @@ -27,12 +27,13 @@ "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To turn on marshalling XML fragment trees. By default JAXB looks for XmlRootElement annotation on given class to operate on whole XML tree. This is useful but not always - sometimes generated code does n [...] "partClass": { "index": 12, "kind": "attribute", "displayName": "Part Class", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of class used for fragment parsing. See more details at the fragment option." }, "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part Namespace", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "XML namespace to use for fragment parsing. See more details at the fragment option." }, - "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] - "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, - "schemaLocation": { "index": 16, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, - "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, - "jaxbProviderProperties": { "index": 18, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, - "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] - "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] + "allowPartClassFromHeader": { "index": 14, "kind": "attribute", "displayName": "Allow Part Class From Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and partNamespace options when marshalling and unmarshal [...] + "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": "Namespace Prefix", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the [...] + "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", "displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom xml stream writer." }, + "schemaLocation": { "index": 17, "kind": "attribute", "displayName": "Schema Location", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the schema" }, + "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", "displayName": "No Namespace Schema Location", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To define the location of the namespaceless schema" }, + "jaxbProviderProperties": { "index": 19, "kind": "attribute", "displayName": "Jaxb Provider Properties", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller." }, + "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": "Content Type Header", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshall [...] + "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", "displayName": "Access External Schema Protocols", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. E [...] } } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java index 5909248d6e06..217bc6d9d1a9 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java @@ -72,6 +72,9 @@ public class JaxbDataFormat extends DataFormatDefinition implements ContentTypeH @Metadata(label = "advanced") private String partNamespace; @XmlAttribute + @Metadata(label = "advanced", javaType = "java.lang.Boolean") + private String allowPartClassFromHeader; + @XmlAttribute @Metadata(label = "advanced", javaType = "java.util.Map") private String namespacePrefix; @XmlAttribute @@ -113,6 +116,7 @@ public class JaxbDataFormat extends DataFormatDefinition implements ContentTypeH this.fragment = source.fragment; this.partClass = source.partClass; this.partNamespace = source.partNamespace; + this.allowPartClassFromHeader = source.allowPartClassFromHeader; this.namespacePrefix = source.namespacePrefix; this.xmlStreamWriterWrapper = source.xmlStreamWriterWrapper; this.schemaLocation = source.schemaLocation; @@ -142,6 +146,7 @@ public class JaxbDataFormat extends DataFormatDefinition implements ContentTypeH this.fragment = builder.fragment; this.partClass = builder.partClass; this.partNamespace = builder.partNamespace; + this.allowPartClassFromHeader = builder.allowPartClassFromHeader; this.namespacePrefix = builder.namespacePrefix; this.xmlStreamWriterWrapper = builder.xmlStreamWriterWrapper; this.schemaLocation = builder.schemaLocation; @@ -314,6 +319,19 @@ public class JaxbDataFormat extends DataFormatDefinition implements ContentTypeH this.partNamespace = partNamespace; } + public String getAllowPartClassFromHeader() { + return allowPartClassFromHeader; + } + + /** + * Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass + * and partNamespace options when marshalling and unmarshalling. Enable it only when the route sets these headers + * itself, not on routes that receive them from external systems. + */ + public void setAllowPartClassFromHeader(String allowPartClassFromHeader) { + this.allowPartClassFromHeader = allowPartClassFromHeader; + } + public String getNamespacePrefix() { return namespacePrefix; } @@ -416,6 +434,7 @@ public class JaxbDataFormat extends DataFormatDefinition implements ContentTypeH private String fragment; private String partClass; private String partNamespace; + private String allowPartClassFromHeader; private String namespacePrefix; private String xmlStreamWriterWrapper; private String schemaLocation; @@ -619,6 +638,26 @@ public class JaxbDataFormat extends DataFormatDefinition implements ContentTypeH return this; } + /** + * Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the + * partClass and partNamespace options when marshalling and unmarshalling. Enable it only when the route sets + * these headers itself, not on routes that receive them from external systems. + */ + public Builder allowPartClassFromHeader(String allowPartClassFromHeader) { + this.allowPartClassFromHeader = allowPartClassFromHeader; + return this; + } + + /** + * Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the + * partClass and partNamespace options when marshalling and unmarshalling. Enable it only when the route sets + * these headers itself, not on routes that receive them from external systems. + */ + public Builder allowPartClassFromHeader(boolean allowPartClassFromHeader) { + this.allowPartClassFromHeader = Boolean.toString(allowPartClassFromHeader); + return this; + } + /** * When marshalling using JAXB or SOAP then the JAXB implementation will automatically assign namespace * prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java index 7bd50abbdf04..3eb6f4b27aee 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java @@ -40,6 +40,7 @@ public class JaxbDataFormatReifier extends DataFormatReifier<JaxbDataFormat> { properties.put("contextPathIsClassName", definition.getContextPathIsClassName()); properties.put("partClass", definition.getPartClass()); properties.put("partNamespace", definition.getPartNamespace()); + properties.put("allowPartClassFromHeader", definition.getAllowPartClassFromHeader()); properties.put("encoding", definition.getEncoding()); properties.put("namespacePrefix", asRef(definition.getNamespacePrefix())); properties.put("schema", definition.getSchema()); 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 5382e45188cf..6c83edbaec82 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 @@ -2009,6 +2009,7 @@ public class ModelParser extends BaseParser { protected JaxbDataFormat doParseJaxbDataFormat() throws IOException, XmlPullParserException { return doParse(new JaxbDataFormat(), (def, key, val) -> switch (key) { case "accessExternalSchemaProtocols": def.setAccessExternalSchemaProtocols(val); yield true; + case "allowPartClassFromHeader": def.setAllowPartClassFromHeader(val); yield true; case "contentTypeHeader": def.setContentTypeHeader(val); yield true; case "contextPath": def.setContextPath(val); yield true; case "contextPathIsClassName": def.setContextPathIsClassName(val); yield true; 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 e705bdda117e..34baab01d153 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 @@ -2739,6 +2739,7 @@ public class ModelWriter extends BaseWriter { doWriteAttribute("noNamespaceSchemaLocation", def.getNoNamespaceSchemaLocation(), null); doWriteAttribute("encoding", def.getEncoding(), null); doWriteAttribute("namespacePrefix", def.getNamespacePrefix(), null); + doWriteAttribute("allowPartClassFromHeader", def.getAllowPartClassFromHeader(), null); doWriteAttribute("fragment", def.getFragment(), null); doWriteAttribute("filterNonXmlChars", def.getFilterNonXmlChars(), null); doWriteAttribute("mustBeJAXBElement", def.getMustBeJAXBElement(), null); 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 970e347a27c3..fcbbd58402c4 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 @@ -2739,6 +2739,7 @@ public class ModelWriter extends BaseWriter { doWriteAttribute("noNamespaceSchemaLocation", def.getNoNamespaceSchemaLocation(), null); doWriteAttribute("encoding", def.getEncoding(), null); doWriteAttribute("namespacePrefix", def.getNamespacePrefix(), null); + doWriteAttribute("allowPartClassFromHeader", def.getAllowPartClassFromHeader(), null); doWriteAttribute("fragment", def.getFragment(), null); doWriteAttribute("filterNonXmlChars", def.getFilterNonXmlChars(), null); doWriteAttribute("mustBeJAXBElement", def.getMustBeJAXBElement(), null); 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 a0da686c8b19..aa856bb0a61a 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 @@ -8177,6 +8177,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { deprecated = false, properties = { @YamlProperty(name = "accessExternalSchemaProtocols", type = "string", description = "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. Examples of protocols are file, http, jar:file. empty, false or none to deny all access to external references; a specific protocol, such as file, to give permission to only the protocol; the keyword all [...] + @YamlProperty(name = "allowPartClassFromHeader", type = "boolean", defaultValue = "false", description = "Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and partNamespace options when marshalling and unmarshalling. Enable it only when the route sets these headers itself, not on routes that receive them from external systems.", displayName = "Allow Part Class From Header"), @YamlProperty(name = "contentTypeHeader", type = "boolean", defaultValue = "true", description = "Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON", displayName = "Content Type Header"), @YamlProperty(name = "contextPath", type = "string", required = true, description = "Package name where your JAXB classes are located.", displayName = "Context Path"), @YamlProperty(name = "contextPathIsClassName", type = "boolean", defaultValue = "false", description = "This can be set to true to mark that the contextPath is referring to a classname and not a package name.", displayName = "Context Path Is Class Name"), @@ -8219,6 +8220,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setAccessExternalSchemaProtocols(val); break; } + case "allowPartClassFromHeader": { + String val = asText(node); + target.setAllowPartClassFromHeader(val); + break; + } case "contentTypeHeader": { String val = asText(node); target.setContentTypeHeader(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 856259e88996..9e8eed087d0f 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 @@ -12044,6 +12044,12 @@ "title" : "Access External Schema Protocols", "description" : "Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. Examples of protocols are file, http, jar:file. empty, false or none to deny all access to external references; a specific protocol, such as file, to give permission to only the protocol; the keyword all to grant permission to all protocols." }, + "allowPartClassFromHeader" : { + "type" : "boolean", + "title" : "Allow Part Class From Header", + "description" : "Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, instead of the partClass and partNamespace options when marshalling and unmarshalling. Enable it only when the route sets these headers itself, not on routes that receive them from external systems.", + "default" : false + }, "contentTypeHeader" : { "type" : "boolean", "title" : "Content Type Header",
