Wednesday, August 26, 2015

Using Validate Mediator with source defined

In WSO2 ESB, you can use validate mediator to define your custom xsd, and validate the input you are getting. If it doesn't comply to the given xsd, you can execute a custom flow and send a fault message. Most examples available is where you don't define the source property so that the first child of the SOAP request will be evaluated. This is just a sample proxy that shows how you can add the xpath to source property.

<proxy xmlns=""
         <log level="full">
            <property name="Message" value="Inside Insequance"/>
         <validate xmlns:nfs=""
            <schema key="conf:/validateCustomer.xsd"/>
               <log level="custom">
                  <property name="MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
               <makefault version="soap11">
                  <code xmlns:tns="" value="tns:Receiver"/>
                  <reason value="Invalid request received"/>
               <property name="RESPONSE" value="true"/>
               <header name="To" expression="get-property('ReplyTo')"/>

A sample request for above would be like,
<soapenv:Envelope xmlns:soapenv="" xmlns:nfs="">
<nfs:CustomerReq  xmlns:nfs="">

Finally you can add your xsd file to mentioned location in schema key. (Under browse->resources->config ->add resource)

No comments:

Post a Comment