Open Source API Gateway

400 Bad Request: REST to SOAP Conversion Failed

Membrane API Gateway returns an error when the rest2Soap plugin cannot convert a REST request into a SOAP request, or the SOAP response back into a REST response. The cause can be the request, the backend response or the stylesheets of the mapping.

The Error Response

The response contains the title User error., the exception, the problem type https://membrane-api.io/problems/user and a link to this page. Status and detail depend on the direction:

Request Conversion Failed

The status is 400 Bad Request and the detail is Could not covert REST to SOAP!. The request did not reach the backend.

Response Conversion Failed

The detail is Could not covert SOAP to REST!. The error happens in the response flow, so the client receives 500 Internal Server Error. In production mode, the title is replaced by Internal Server Error.

What the rest2Soap Plugin Does

The rest2Soap plugin offers a REST interface for a SOAP service. For each mapping, a regex selects the requests, soapURI and soapAction address the SOAP operation, and two XSLT stylesheets do the conversion. Membrane turns the REST request into an XML document and applies requestXSLT to create the SOAP message. The SOAP response is converted with responseXSLT, and to JSON if the client asked for JSON.

Common Causes

The Request Cannot Be Converted to XML

The request URI cannot be parsed, or the request body is declared as XML or JSON in its Content-Type but is not well-formed. Membrane then cannot build the XML document for the stylesheet.

The Stylesheet Cannot Be Loaded

The stylesheet in requestXSLT or responseXSLT cannot be found or does not compile. Stylesheets are loaded on first use, so this shows up when the first request arrives, not at startup.

The Stylesheet Fails

The stylesheet fails at runtime, for example through an xsl:message terminate="yes" or an error in an XPath expression.

The Backend Response Is Not Well-Formed XML

In the response flow, the backend returns something other than a SOAP message, for example an HTML error page, or the conversion to JSON for a client that sent a JSON Accept header fails.

How to Fix It

  1. Check the log. Membrane logs the full exception at error level.
  2. As a client, send a correctly encoded URI and, if you send a body, one that matches its Content-Type.
  3. As an operator, check the requestXSLT and responseXSLT locations of the mapping, and test the stylesheets against sample messages.
  4. If the backend returns non-XML errors, check the backend and the soapURI of the mapping.

For new projects, consider the SOAP to REST Gateway, which generates the REST API from the WSDL without stylesheets.

Hide Details in Production

By default, Membrane runs in development mode and adds details to error responses that help you find the problem. These details may reveal information about your setup. In production, turn them off:

configuration:
production: true
configuration:
  production: true

Add the configuration document to your apis.yaml and separate it from the APIs with ---.

Related Documentation

Configuration reference:

← All Membrane error messages

Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.