Croway commented on code in PR #30212:
URL: https://github.com/apache/camel/pull/30212#discussion_r4587353830


##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc:
##########
@@ -121,6 +121,21 @@ nodes, and XInclude is not processed. Before, the Flowable 
7 deserializer parsed
 An event that relies on an external DTD or an external entity no longer gets 
their content. A channel that sets
 `deserializerDelegateExpression` keeps its own deserializer, which can parse 
such events.
 
+=== camel-jaxb - the part class and namespace headers are used only when 
allowed
+
+The JAXB data format has a new option `allowPartClassFromHeader` (default 
`false`). The `CamelJaxbPartClass` and
+`CamelJaxbPartNamespace` headers are now used only when this option is `true`; 
otherwise they are ignored, and the
+`partClass` and `partNamespace` options of the data format apply. Before, the 
headers were always used, and took
+precedence over these options.
+
+Routes that set these headers to choose the part class or namespace per 
message must enable the option, for example
+`jaxb.setAllowPartClassFromHeader(true)` in Java, 
`allowPartClassFromHeader="true"` on `<jaxb>` in XML, or
+`allowPartClassFromHeader: true` in YAML. With REST binding, set the data 
format property
+`xml.out.allowPartClassFromHeader=true` on the REST configuration.

Review Comment:
   This fits a REST service, where `xml.out` marshals the response. For the 
`rest:` producer it is the other way round: `RestProducerBindingProcessor` 
marshals the request with the `xml.in` data format and unmarshals the response 
with `xml.out`.
   
   Reproduced on 6a285ab with 
`rest:post:order?inType=org.apache.camel.example.Address&outType=org.apache.camel.example.PurchaseOrder`
 (xml binding, a stub `RestProducerFactory` that answers `<purchaseOrder 
.../>`), and `CamelJaxbPartClass`/`CamelJaxbPartNamespace` set on the exchange 
as in `JaxbDataFormatPartClassHeaderTest`:
   - `xml.out.allowPartClassFromHeader=true`, as written here: the headers are 
not used for the request, and the call fails with 
`NoTypeConversionAvailableException: No type converter available to convert 
from type: org.apache.camel.example.Address to the required type: 
java.io.InputStream`. When the request body is already XML text, the response 
is unmarshalled with the part-class header left over from the request: 
`org.apache.camel.example.Address is not known to this context`.
   - `xml.in.allowPartClassFromHeader=true`: the request is written as 
`address` in the `http://www.camel.apache.org/jaxb/example/address/1` 
namespace, and the response is a `PurchaseOrder`.
   
   Maybe: "With REST binding, set the data format property 
`xml.out.allowPartClassFromHeader=true` for a REST service (the response), or 
`xml.in.allowPartClassFromHeader=true` for the `rest` producer (the request)."
   
   _Claude Code on behalf of Croway_



##########
core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/SoapDataFormat.java:
##########
@@ -66,6 +66,12 @@ public class SoapDataFormat extends DataFormatDefinition {
     @Metadata(label = "advanced", javaType = "java.lang.Boolean",
               description = "Whether to ignore headers that were not 
unmarshalled.")
     private String ignoreUnmarshalledHeaders;
+    @XmlAttribute
+    @Metadata(label = "advanced", javaType = "java.lang.Boolean",
+              description = "Whether the CamelJaxbPartClass and 
CamelJaxbPartNamespace headers are used, when set, instead of"
+                            + " the partClass and partNamespace options when 
marshalling and unmarshalling."
+                            + " This should only be enabled when desired to be 
used.")
+    private String allowPartClassFromHeader;

Review Comment:
   On SOAP the header breaks unmarshalling: `SoapDataFormat.unmarshal` calls 
`super.unmarshal` on the whole envelope, so with this option on, the envelope 
is bound to the class of the header, and `Soap11DataFormatAdapter` then rejects 
anything that is not an `Envelope`.
   
   Reproduced on 6a285ab: `SoapDataFormat` on `com.example.customerservice` 
with `setAllowPartClassFromHeader(true)`, the `request.xml` of 
`SoapUnMarshalTest`, and the header 
`CamelJaxbPartClass=com.example.customerservice.GetCustomersByName` (for 
example left by an earlier JAXB step):
   
   ```
   org.apache.camel.RuntimeCamelException: Expected Soap Envelope but got class 
com.example.customerservice.GetCustomersByName
   ```
   
   With the option off it unmarshals to `GetCustomersByName`. Since there is no 
case where enabling it works, I'd leave it off the SOAP data format (which then 
always ignores the headers) rather than add it to the SOAP DSL and recommend it 
in the upgrade guide.
   
   _Claude Code on behalf of Croway_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to