davsclaus opened a new pull request, #30583: URL: https://github.com/apache/camel/pull/30583
## What was wrong [CAMEL-27372](https://issues.apache.org/jira/browse/CAMEL-27372): a route behind a `cxf:` consumer with `dataFormat=PAYLOAD` that replies with a `<soap:Fault>` element as a `String` (or DOM) body sent it to the client inside a normal response, with HTTP 200 (and with schema validation on, the client got a confusing validation error instead). It only worked when the body was a `CxfPayload` or the route threw a `SoapFault`. `CxfConsumer.checkFailure` looked for a Fault element only in a `CxfPayload` body. `DefaultCxfBinding.populateCxfResponseFromExchange` converts other bodies into a `CxfPayload` for the response it writes, but does not set the result on the message, so the second fault check, after that conversion, still saw the `String`. ## The fix `CxfConsumer` now also checks a `String`, a DOM `Node` (`Document` or `Element`) or a `DOMSource` body for a SOAP Fault element, only in PAYLOAD mode, and builds the `SoapFault` from it in the same way as for a `CxfPayload` (fault code, fault string or reason, detail; SOAP 1.1 and SOAP 1.2 namespaces). To keep normal responses cheap and safe: - a `String` is only parsed when it contains `Fault` and a SOAP envelope namespace, - a stream body is never read for the check, as that would consume it, - POJO, RAW and CXF_MESSAGE modes are unchanged (a `String` can be a valid POJO return value). The component doc ("How to throw a SOAP Fault from Camel") now has a PAYLOAD paragraph with a YAML example; the catalog copy of the doc is updated. ## Tests New `CxfConsumerPayLoadStringFaultTest` (camel-cxf-soap) posts raw SOAP requests over HTTP and checks the status code and body: - SOAP 1.1 Fault as a `String` body: HTTP 500 with faultcode and faultstring - the same with `schemaValidationEnabled=true`: HTTP 500 - SOAP 1.1 Fault as a DOM `Document` body: HTTP 500 - SOAP 1.2 Fault as a `String` body on the SOAP 1.2 port: HTTP 500 with Code/Value and Reason/Text - a normal `String` response: still HTTP 200 Without the fix the four fault cases fail (HTTP 200); with it all 5 pass. - `mvn test` in `components/camel-cxf/camel-cxf-soap`: 216 tests, 0 failures, 0 errors, 4 skipped - `mvn test` in `components/camel-cxf/camel-cxf-spring-soap` (against this change of camel-cxf-soap): 161 tests, 0 failures, 0 errors, 3 skipped A JAX-WS client (`CxfConsumerPayLoadFaultMessageTest` with a String body) already raised the declared fault before the fix, because the CXF client reads a Fault element in the body as a fault regardless of the HTTP status; that is why the new test checks the raw HTTP response. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
