This mediator is used for schema validation of messages.
The portion of the message that needs to be validated is chooses by evaluating the XPath expression. Then this message is validated against the schema spcecified. User can specify a sequence to be executed in case of a validation failure. This mediator provide an extension point by providing properties to configure the underline validation engine.
<validate [source="xpath"]> <property name="validation-feature-id" value="true|false"/>* <schema key="string"/>+ <resource location="string" key="string"/> + <on-fail> mediator+ </on-fail> </validate>
The validate mediator validates the result of the evaluation of the source xpath expression, against the schema specified. If the source attribute is not specified, the validation is performed against the first child of the SOAP body of the current message. If the validation fails, the on-fail sequence of mediators is executed. Properties could be used to turn on/off some of the underlying features of the validator (See http://xerces.apache.org/xerces2-j/features.html)
The <resource> can be used to specify external schema resources, which can be used to validate the messages. External schema resources can be defined as localentries and with <resource> user could point the specified localentries.
XPath expression to extract the XML that need to be validated. If not specified validation is performed against the first child of the SOAP body
Here is the only mandatory feature supported by the validator, "http://javax.xml.XMLConstants/feature/secure-processing". For more information please refer this.
<validate> <schema key="schema\sample.xsd"/> <on-fail> <makefault> <code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/> <reason value="Invalid Request!!!"/> </makefault> <property name="RESPONSE" value="true"/> <header name="To" expression="get-property('ReplyTo')"/> </on-fail> </validate>
Note: If user configure WSO2 ESB with WSO2 Governance Registry and if he uploads all the required files as *.gar file (described in WSO2 GREG documentation), uer can provide only the base schema when he provides schemas. There is no need to provide all required imported schemas since ESB is able to resolve the imported resources using only the base schema. Please note that for the above function user needs to uncomment the following lines @ synapse.properties file which is avilable in ESB_HOME/lib/core/WEB_INF/classes folder.
synapse.schema.resolver=org.wso2.carbon.mediation.initializer.RegistryXmlSchemaURIResolver