Open Source API Gateway

400 Bad Request: XSLT Transformation Failed

Membrane API Gateway returns an error when the transform plugin cannot apply its XSLT stylesheet to the message body. In the request flow, the client's body is the usual cause. In the response flow, the backend's body or the stylesheet is the cause.

The Error Response

The response contains the problem type https://membrane-api.io/problems/user and a link to this page. The status is 400 Bad Request in the request flow. In the response flow, the client receives 500 Internal Server Error, and in production mode the title is replaced by Internal Server Error. Title and detail depend on the case:

Content Not Allowed in Prolog

The title is Content not allowed in prolog of XML input. and the detail is Check for extra characters before the XML declaration <?xml ... ?>. The response also shows the beginning of the body.

Content Not Allowed in Trailing Section

The title is Content not allowed in trailing section of XML input. and the detail is Check for extra characters after the XML root element (after the final closing tag like </root>). The response also shows the end of the body.

XML Parsing Failed

The title is XML parsing failed and the detail contains the message of the XML parser.

Error Transforming Message

The title is User error. and the detail is Error transforming message!, together with the exception and the flow.

What the transform Plugin Does

The transform plugin applies an XSLT stylesheet to the XML body of a request or response and replaces the body with the result:

api:
port: 2000
flow:
- request:
- transform:
xslt: convert-request.xslt
- response:
- transform:
xslt: convert-response.xslt
target:
url: https://api.predic8.de
api:
  port: 2000
  flow:
    - request:
        - transform:
            xslt: convert-request.xslt
    - response:
        - transform:
            xslt: convert-response.xslt
  target:
    url: https://api.predic8.de

Common Causes

Characters Before the Root Element

The body has characters before the XML declaration or root element, for example a byte order mark, whitespace before <?xml, or a body that is not XML at all, such as JSON, HTML or plain text.

Characters After the Root Element

The body has characters after the closing tag of the root element, for example a second root element or appended text.

The Body Is Not Well-Formed XML

The body contains an unclosed tag, a missing quotation mark or an invalid character.

The Stylesheet Fails

The stylesheet fails at runtime, for example through an xsl:message terminate="yes", a type error or a failed document() call.

The Body Cannot Be Read

The body cannot be read or decoded, for example because of a broken Content-Encoding or an invalid XOP package.

How to Fix It

  1. Read the title and detail to find out which case applies. The status tells you whether the request (400) or the response (500) failed.
  2. As a client, send a well-formed XML document with nothing before the declaration and nothing after the root element.
  3. If the backend body is the problem, fix the backend, or make sure transform only runs on XML responses.
  4. Test the stylesheet against sample messages. The log contains the exception of the transformer.

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:

Tutorials with runnable examples:

← All Membrane error messages

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