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 Installation Prerequisites for more information on downloading this.
Instructions
1. Navigate to GREG_HOME/
samples/handler/src
to find the source code of the Handler Sample.
2. Add a new Java Class named XPathValidationHandler
at
GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/handler/XPathValidationHandler.java
with the following source:
...
Code Block |
---|
mvn clean install |
Info | title | Note
---|
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 | title | Note
---|
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 Installing Running the Product on Windows or Installing Running the Product on Linux and Solaris.
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
...