Validate JSON Schema in Mule | JSON Schema in Mule
Validate JSON Schema component in used to validate JSON input with JSON schema.
flow of Validate JSON Schema Component :
JSON Schema is located in src/main/resources with name json_schema.json
Validate JSON Schema configuration :
json_schema.json :
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "integer"
}
},
"required": [
"id"
]
}
URL : http://localhost:8085/api/testschema
Method : POST
Input :
Output :
If input is validated by schema then it will pass through it as payload.
XML project code :
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" basePath="/api" doc:name="HTTP Listener Configuration"/>
<flow name="test_schemafilterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/testschema" doc:name="HTTP"/>
<json:validate-schema schemaLocation="json_schema.json" doc:name="Validate JSON Schema"/>
</flow>
</mule>
No comments:
Post a Comment