Open Source API Gateway

500 Internal Server Error: XML Error in the XML Content Filter

Membrane API Gateway returns 500 Internal Server Error with the title XML Error when the xmlContentFilter plugin fails while removing XML nodes from a message in the request or response flow.

The Error Response

The response contains the status 500 Internal Server Error, the title XML Error, the problem type https://membrane-api.io/problems/internal and a link to this page. The type internal means that the gateway could not complete the processing of the message. In production mode, the title is replaced by Internal Server Error and the details are left out.

What the XML Content Filter Does

The xmlContentFilter plugin removes all nodes that its xPath expression selects from an XML message, for example to strip internal information from responses. A body that is not well-formed XML does not lead to this error: it is passed on unchanged.

Common Causes

The XPath Selects Nodes That Cannot Be Removed

The xPath selects nodes without a parent element, such as attributes (//@id) or the document node (/). Removing them fails. Only elements and other child nodes can be removed.

The XPath Expression Fails

The XPath expression fails when it is evaluated, for example because it uses a function or namespace prefix that is not available.

The Body Cannot Be Read

The message body cannot be read or decoded, for example because the Content-Encoding is wrong or the sender aborted the transfer.

The Result Cannot Be Written

The modified document cannot be serialized again. This is rare.

An Unexpected Exception in the Plugin

The same link also appears when the xmlContentFilter plugin throws an exception that it does not turn into an error response itself. Membrane then aborts the exchange with 500 Internal Server Error, and the detail reads Aborting! Exception caused in xml-content-filter during … flow. with the request URI and the flow. Membrane logs every occurrence with the full stack trace. Unless the exception points to your configuration or to the message content, this usually indicates a bug in Membrane.

How to Fix It

Make xPath select elements only. This filter removes all stacktrace elements from responses, regardless of their namespace:

api:
port: 2000
flow:
- response:
- xmlContentFilter:
xPath: "//*[local-name()='stacktrace']"
target:
url: https://api.predic8.de
api:
  port: 2000
  flow:
    - response:
        - xmlContentFilter:
            xPath: "//*[local-name()='stacktrace']"
  target:
    url: https://api.predic8.de
  1. For body read errors, check the sender's Content-Encoding and whether the connection was interrupted.
  2. The exception is logged at error level. If the causes above do not explain it, report the problem with the stack trace on GitHub Issues.

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 ---. 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.

If the plugin is nested inside a request, response or abort element and fails with an unexpected exception there, the exception message, the stack trace and the link to this page are currently sent even in production mode. Fix the failing plugin rather than relying on production mode to hide them.

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.