Membrane API Gateway returns 400 Bad Request when the xml2Json plugin cannot convert the XML request body into JSON. The client labeled the request as XML, but the body cannot be parsed.
The response contains the status 400 Bad Request, a detail that starts with Could not transform XML to JSON: followed by the parser's message, the problem type https://membrane-api.io/problems/internal and a link to this page. Although the type is internal, the status 400 tells you that the client's request body caused the problem. In development mode, the charset-from-header field shows the charset from the Content-Type header.
The xml2Json plugin converts message bodies with an XML Content-Type into JSON, for example to offer a JSON interface for an XML backend. Messages that are not labeled as XML are passed on unchanged. The same error in the response flow is described under Could not transform XML to JSON in the response.
The request is labeled as XML but its body is not well-formed XML, for example because it is truncated, has unclosed tags or is not XML at all. The parser's message is in the detail.
The XML declaration names an encoding that Java does not support, for example <?xml version="1.0" encoding="foo"?>. The detail then starts with Unsupported encoding:.
The request body cannot be read or decoded, because the Content-Encoding is wrong or the client aborted the transfer.
UTF-8.Content-Type header matches the actual encoding of the body.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: trueconfiguration: production: true
Add the configuration document to your apis.yaml and separate it from the APIs with ---. The status and title stay the same, but the details and the link to this page are left out.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.