<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <title>WSO2 ESB - Validate Mediator </title>
  <link href="css/esb-docs.css" rel="stylesheet" />
  <link href="styles/dist-docs.css" rel="stylesheet" type="text/css"
  media="all" />
</head>

<body>
<h2>Validate Mediator</h2>

<p>This mediator is used for schema validation of messages. </p>

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

<h3>Syntax</h3>
<pre xml:space="preserve"> &lt;validate [source="xpath"]&gt;
   &lt;property name="validation-feature-id" value="true|false"/&gt;*
   &lt;schema key="string"/&gt;+
   &lt;resource location="string" key="string"/&gt; +
   &lt;on-fail&gt;
     mediator+
   &lt;/on-fail&gt;
 &lt;/validate&gt;</pre>

<p></p>

<p>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) </p>
 <p>
  The &lt;resource&gt;  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 &lt;resource&gt;
  user could point the specified localentries.
 </p>
<h3>UI Configuration</h3>

<p><img alt="Validate Mediator"
src="../validate-mediator/docs/images/validate.png" /> </p>

<h4>Key</h4>

<p>Schema location</p>

<h4>Source</h4>

<p>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</p>

<h4>Features</h4>

<p>Here is the only mandatory feature supported by the validator, "http://javax.xml.XMLConstants/feature/secure-processing".
    For more information please refer <a href="http://java.sun.com/javase/6/docs/api/constant-values.html#javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING"> this.</a>
    </p>
<h3>Example</h3>
<ol>
  <li><pre>&lt;validate&gt;
    &lt;schema key="schema\sample.xsd"/&gt;
         &lt;on-fail&gt;
                &lt;makefault&gt;
                    &lt;code value="tns:Receiver"
                            xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/&gt;
                    &lt;reason value="Invalid Request!!!"/&gt;
                &lt;/makefault&gt;
                &lt;property name="RESPONSE" value="true"/&gt;
                &lt;header name="To" expression="get-property('ReplyTo')"/&gt;
         &lt;/on-fail&gt;
&lt;/validate&gt;
    </pre>
    In the above validate mediator configuration, the required schema for
    validating message going through the validate mediator has been given as a
    registry key, <strong>schema\sample.xsd</strong>. In this sample
    configuration, there is no <strong>source</strong> attribute. Therefore, in
    this case, validate mediator takes source as the first child of SOAP Body.
    Within <strong>on-fail</strong>, it is possible to specify mediation logic
    that should to be happened if the validation is failed. In the above
    configuration, it creates a SOAP fault using <strong>makefault</strong>
    mediator and send back that to requested party. </li>
</ol>
<p> <strong>Note: </strong>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.
</p>
<p><strong>
synapse.schema.resolver=org.wso2.carbon.mediation.initializer.RegistryXmlSchemaURIResolver
</strong>
</p>

</body>
</html>
