Validating JSON requests in the WSO2 Micro Integrator (MI) is a truly remarkable and meticulously engineered process. This robust validation mechanism ensures that all incoming JSON data meticulously adheres to the predefined schemas, safeguarding the integrity and reliability of the integration workflows.
By rigorously verifying the structure and content of the JSON payloads, the WSO2 MI empowers developers to build resilient and fault-tolerant systems that can seamlessly process a wide range of JSON-based data. This remarkable attention to detail and commitment to data validation is a testament to the engineering excellence that underpins the WSO2 Micro Integrator, making it a powerful and trustworthy platform for complex integration tasks.
Walk Through
Create a new project in the integration studio: File > New > Integration Project, and give the project a name.
After creating the project, right-click on local entries > New > Local Entry > Create a new local entry, and provide the required fields as Name and content type > Finish.
Schema for validating the incoming JSON payload.
Configure local entry Properties: Local Entry Name: Sample Test
Local Entry Creation Type: In-Line Text Entry
Advanced Configuration: The JSON schema is mentioned below.
“$schema”: “http://json-schema.org/draft-04/schema#”,
“type”: “object”,
“properties”: {
“getQuote”: {
“type”: “object”,
“properties”: {
“request”: {
“type”: “object”,
“properties”: {
“symbol”: {
“type”: “string”
}
},
“required”: [
“symbol”
]
}
},
“required”: [
“request”
]
}
},
“required”: [
“getQuote”
]
}
Right-click on the API, select New > RestAPI. Create a new artifact by providing the required fields as Name and Context, then click Finish. Drag and drop the Validate mediator.
The JSON schema file is placed in local entries, and its path is referred to in the validate mediator.
It validates the input JSON according to the JSON file available in the local entry.
In the payload factory, the error message will be displayed by the ERROR MESSAGE property.
Drag and drop log will log the message after the payload.
Drag and drop property: Set the HTTP status code to “400 Bad Request” within the Axis2 context.
Build and run the artifacts
Right-click Validation-JSON-RequestCompositeExporter and click Export Project Artifacts and Run.
You will see the following dialog box. Select the validation-JSON-RequestConfig folder in the artifact list and click Finish.
After a successful deployment, it will generate a URL.
If there is any mismatch or change in the JSON that does not conform to the schema, it will display a message in the validate mediator.
For more information, please write to [email protected].