Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

Code Block
mvn clean install
title
Info
Note

The command mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux See Installation Prerequisites for more information on downloading this.

A successful run of Apache Maven will generate a report similar to the following:

...

Code Block
languagehtml/xml
<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>
Note
Info
title

The configuration above is used to validate a WSDL file as to whether the service defined in it has the name SimpleStockQuoteService. All other WSDL files will fail to upload. For the validation to work before the WSDL has been added, this handler should be configured before the other handlers defined for the WSDL media type, which is why we added this handler as the very first handler in the registry.xml file.

...