This sample explains how to validate the content of an XML resource uploaded to WSO2 Governance Registry using XPath and regular expressions in a few easy steps. This is useful to introduce additional validation to files such as WSDL, Schema and Policy. We will be reusing the code of the Handler Sample in this example. This sample requires Apache Maven. See Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux See Installation Prerequisites for links on how to install it.
Instructions
1. Navigate to GREG_HOME/
samples/handler/src
to find the source code of the Handler Sample.
...
Code Block |
---|
mvn clean install |
Info | ||
---|---|---|
| ||
The command |
A successful run of Apache Maven will generate a report similar to the following:
...
Code Block | ||
---|---|---|
| ||
<handler class="org.wso2.carbon.registry.samples.handler.XPathValidationHandler"> <property name="xPath">//wsdl:service</property> <property name="attribute">name</property> <property name="regEx">SimpleStockQuoteService</property> <property name="namespaces">wsdl:http://schemas.xmlsoap.org/wsdl/</property> <filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.MediaTypeMatcher"> <property name="mediaType">application/wsdl+xml</property> </filter> </handler> |
Info | ||
---|---|---|
| ||
The configuration above is used to validate a WSDL file as to whether the service defined in it has the name |
...
5. Start the WSO2 Governance Registry. See See Running the Product on Windows or Installing on Linux and Solaris for more information.
XPath is a powerful language that can be used to retrieve a subset of elements from an XML document. This in combination with regular expressions can be used to validate content of XML files uploaded into the WSO2 Governance Registry
...