Loading

WSC Connector | How to Define an Expression Response Validator Using DataWeave for HTTP Transport

Fecha de publicación: Oct 17, 2025
Descripción

There's a requirement to customise the response code validation for a HTTP request operation to have different error handling for each scenario. For example, to treat certain scenarios as a successful or unsuccessful response regardless of the response status code received. 

A good example here's the WSC Connector. It uses HTTP request operation either implicitly (by default) or explicitly (in customised configuration). The problem arises from the fact that, the HTTP transport propagates all response codes to the WSC Connector to make a decision on how to treat the response. In some cases, ‌the connector can receive several different faulty responses. For example: 

  • WSC:SOAP_FAULT with the HTTP response code 500:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>Server</faultcode>
      <faultstring>Missing operation for soapAction [http://www.cleverbuilder.com/BookService/GetBook] and body element [{http://www.cleverbuilder.com/BookService/}GetBook1] with SOAP Version [SOAP 1.1]</faultstring>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>

  • A response envelope, which isn't described in WSDL with response 500 INTERNAL_SERVER_ERROR:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <con:fault xmlns:con="http://example.com/context">
            <con:errorCode>SOME_ERROR</con:errorCode>
<!-- TRUNCATED --> 
        </con:fault>
    </soap:Body>
</soapenv:Envelope>

By default, or when a response validator is set as explained in this article, both SOAP_FAULT and INTERNAL_SERVER_ERROR will be propagated to the WSC Connector. The connector, in turn, will catch the SOAP_FAULT, as expected, but skip the INTERNAL_SERVER_ERROR, which will be treated as a successful response with code 200. 

Solución

To catch both responses with code 500 and ensure they produce different errors, an expression response validator can be used as: 

        <http:response-validator >
            <http:expression-response-validator expression="#[attributes.statusCode == 200 or (attributes.statusCode == 500 and read(payload, 'text/xml').Envelope.Body.fault.errorCode == null)]" />
        </http:response-validator>

The above will allow it to propagate:

  • The SOAP fault to the WSC Connector with WSC:SOAP_FAULT thrown;
  • The INTERNAL_SERVER_ERROR with WSC:CANNOT_DISPATCH thrown;
  • Any expected successful response from the remote web service.

Note, the validator passes the validation if the final result of the expression execution is true.

Note, the complexity of identifying which expressions to use arises from the fact that any error within the HTTP transport may not be shown when the WSC Connector processes the error. To know what needs to be included into the exp[ression, as in the above example, it is recommended to:

  1. Build another flow with HTTP request operation, i.e. without WSC Connector, sending the same envelope and getting the response back
  2. Run the app in DEBUG mode and extract all required fields using "Evaluate DataWeave Expression" feature:  

Note, this may also be applicable to any connector which uses an HTTP connector as a transport and where the customised response validation is required.

Disclaimers

  • This solution provides a suggestion that should be considered in conjunction with your specific use-case and requirements and does not represent a complete solution for all circumstances.
  • This example is provided as a reference for your own usage and is not to be considered a MuleSoft product. This example should be considered as a custom solution. The custom solution is not a Supported MuleSoft product.
Número del artículo de conocimiento

005226745

 
Cargando
Salesforce Help | Article