Claus Ibsen created CAMEL-27052:
-----------------------------------

             Summary: camel-jaxb - use the part class and namespace headers 
only when allowed
                 Key: CAMEL-27052
                 URL: https://issues.apache.org/jira/browse/CAMEL-27052
             Project: Camel
          Issue Type: Improvement
          Components: camel-jaxb
            Reporter: Claus Ibsen
            Assignee: Claus Ibsen
             Fix For: 4.24.0, 4.22.3, 4.18.6


h3. Today

{{JaxbDataFormat}} in camel-jaxb always reads the {{CamelJaxbPartClass}} and 
{{CamelJaxbPartNamespace}} message headers. When set, they take precedence over 
the configured {{partClass}} and {{partNamespace}} options, on unmarshal (the 
class to bind the XML to) and on marshal (the partial class and the element 
name). There is no option to turn this off, so a data format configured with a 
fixed {{partClass}} can still be switched to another class of its JAXB context 
by a header on the message.

Other data formats with a similar header already make it opt-in: camel-jackson, 
camel-jacksonxml, camel-gson and others read their 
{{CamelJacksonUnmarshalType}} style header only when 
{{allowUnmarshallType=true}} (default {{false}}).

h3. After the change

A new boolean option on the JAXB data format (proposed name 
{{allowPartClassFromHeader}}, label advanced, default {{false}}), in line with 
{{allowUnmarshallType}}:
* {{false}} (default): the {{CamelJaxbPartClass}} and 
{{CamelJaxbPartNamespace}} headers are ignored on unmarshal and marshal; the 
configured {{partClass}} and {{partNamespace}} apply.
* {{true}}: today's behaviour, the headers take precedence.

Routes that set these headers themselves enable the option.

h3. Code changes

* 
{{components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java}}:
 the new option; {{unmarshal}}, {{doMarshal}} and {{toElement}} read the two 
headers only when it is enabled.
* {{core/camel-core-model/.../model/dataformat/JaxbDataFormat.java}} 
(attribute, copy constructor, builder) and 
{{core/camel-core-reifier/.../reifier/dataformat/JaxbDataFormatReifier.java}}, 
following the shape of {{allowUnmarshallType}} in {{JsonDataFormat}}.
* Regenerated files: the camel-jaxb configurer and JSON metadata, the model 
JSON, the catalog, the XML and YAML DSL parsers and schemas, and the camel-main 
configuration metadata.
* Docs: {{jaxb-dataformat.adoc}}, the section on the part class and namespace 
headers says they apply only when the new option is enabled.
* Upgrade guide: an entry in {{camel-4x-upgrade-guide-4_24.adoc}} (and the 4.22 
/ 4.18 guides if backported), because routes that rely on the headers must 
enable the option.

h3. Tests

* New {{JaxbPartClassHeaderOptionTest}} in camel-jaxb: the header is ignored by 
default and the configured {{partClass}} is used; the header is used when the 
option is enabled; the same for {{CamelJaxbPartNamespace}} on marshal; a header 
alone does not turn on partial unmarshalling by default.
* Existing tests that set the header in the route enable the option: 
{{JaxbDataFormatPartClassHeaderTest}} and 
{{JaxbPartClassHeaderStatePollutionTest}} (camel-jaxb), 
{{RestJettyNoContentTest}} and {{RestJettyNoContentRestConfigTest}} 
(camel-jetty), {{RestServletNoContentTest}} and 
{{RestServletNoContentRestConfigTest}} (camel-servlet).

h3. Backports

* camel-4.22.x: same change.
* camel-4.18.x: first CAMEL-24164 (the header no longer changes the shared data 
format), which is not on that branch yet, then this change.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to