Membrane API Gateway returns 500 Internal Server Error when the xml2Json plugin cannot convert the XML response of the backend into JSON. The backend labeled its response as XML, but the body cannot be parsed.
The response contains the status 500 Internal Server Error, 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. In development mode, the charset-from-header field shows the charset from the Content-Type header of the backend response. Because the error occurs in the response flow, the client gets a 500. In production mode, the title is replaced by Internal Server Error and the details are left out.
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 request flow is described under Could not transform XML to JSON in the request.
The response is labeled as XML but its body is not well-formed XML. A typical case is an HTML error page or an empty body with an XML content type.
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 response body cannot be read or decoded, because the Content-Encoding is wrong or the backend aborted the transfer.
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 title then reads Internal Server Error, and the details and the link to this page are left out. If the response contains a log key, search the gateway log for it to find the full error message.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.