description |
---|
This page provides the technical details of the XML Validation policy |
You can use the xml-validation
policy to validate XML using an XSD schema. This policy uses javax.xml
. A 400 BAD REQUEST error is received with a custom error message body when validation fails. Injects processing report messages into request metrics for analytics.
Functional and implementation information for the xml-validation
policy is organized into the following sections:
{% hint style="warning" %} This policy can be applied to v2 APIs and v4 HTTP proxy APIs. It cannot be applied to v4 message APIs or v4 TCP proxy APIs. {% endhint %}
{% tabs %} {% tab title="HTTP proxy API example" %} Sample policy configuration:
{
"errorMessage":"XML payload is improperly formatted",
"xsdSchema":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" attributeFormDefault=\"unqualified\"\n elementFormDefault=\"qualified\">\n <xs:element name=\"root\" type=\"rootType\">\n </xs:element>\n\n <xs:complexType name=\"rootType\">\n <xs:sequence>\n <xs:element name=\"companies\" type=\"companiesType\"/>\n </xs:sequence>\n </xs:complexType>\n\n <xs:complexType name=\"companiesType\">\n <xs:sequence>\n <xs:element name=\"company\" type=\"companyType\" maxOccurs=\"unbounded\" minOccurs=\"0\"/>\n </xs:sequence>\n </xs:complexType>\n\n <xs:complexType name=\"companyType\">\n <xs:sequence>\n <xs:element type=\"xs:string\" name=\"name\"/>\n <xs:element type=\"xs:integer\" name=\"employeeNumber\"/>\n <xs:element type=\"xs:long\" name=\"sales\"/>\n <xs:element type=\"xs:string\" name=\"CEO\"/>\n </xs:sequence>\n </xs:complexType>\n</xs:schema>"
}
{% endtab %} {% endtabs %}
The phases checked below are supported by the xml-validation
policy:
v2 Phases | Compatible? | v4 Phases | Compatible? |
---|---|---|---|
onRequest | false | onRequest | false |
onResponse | false | onResponse | false |
onRequestContent | true | onMessageRequest | false |
onResponseContent | false | onMessageResponse | false |
The xml-validation
policy can be configured with the following options:
Property | Required | Description | Type | Default |
---|---|---|---|---|
errorMessage | false | Custom error message in XML format. Spel is allowed. | string | validation/internal |
xsdSchema | true | Xsd schema. | string |
The following is the compatibility matrix for APIM and the xml-validation
policy:
Plugin Version | Supported APIM versions |
---|---|
1.x | All |
HTTP status code | Message |
---|---|
400 | * Invalid payload * Invalid XSD schema * Invalid error message XML format |