Saturday, 12 October 2019

ESB 10 WSO2 ESB Tutorial: Introduction to Local Registry Entries & Using Schema Validation

ESB 10
WSO2 ESB Tutorial:
Introduction to
Local Registry Entries &
Using Schema Validation

Index


1. Introduction

2. EI configuration Example

3. Running Example

4. Conclusion


1. Introduction


The validation of incoming messages is very important task. It is the way to avoid to process messages bad formatted or with no sense. Following the good practices those invalid messages must to be redirected to an Invalid Message Channel. For now we are going to study how to use an XSD schema file to validate its XML file related.

2. EI configuration Example


As you know EI (Enterprise Integrator) is our middleware. The client, can be SOAPUI, sends a request to the backend SimpleStockQuoteService through the EI. In the in sequence there is a validate mediator (for XML schema validation) that filter those inconsistent messages. The mediator uses an XSD schema of the XML request and validates the content of the first child of the message with the following path:
getQueote > request > stocksymbol.
The problem is that the request contains this other path:
getQueote > request > symbol
and because it is not the same path an error message is returned to the client. On the other hand, the XSD schema is stored statically as a localEntry. In general, the resources defined in the local registry are static (never changes over the lifetime of the configuration) and may be specified as a source URL, inline text or inline XML.



3. Running Example

After starting SimpleStockQuoteService send the following request with SOAPUI:


This is a screenshot of SOAPUI with the request and response from EI:


Because the request is using a wrong element name the response from EI is an error message:


4. Conclusion


The validation mediator is key to follow good practices when integration applications. It is a way to minimize the time lost in processing erroneous requests. The Validate mediator validates XML/JSON messages against a specified schema. You can specify an XPath/JSONPath to extract and validate a specific part of the message. Otherwise, the mediator validates the first child of the SOAP body of the current message or the complete content of the current message for a JSON request.

No comments:

Post a Comment