Schema Validation In Mule 4
In this article, see what a schema validation in Mule 4 looks like.
Join the DZone community and get the full member experience.Join For Free
What Is a Schema Validation Filter?
The Schema Validation component takes XML inputs and approves these against a referenced XSD pattern.
Ordinarily, you can put this component before another message processor, for example, a connector, to decide if the approaching message or occasion ought to be dealt with or not, enabling the message to possibly proceed along the stream when the channel approvals are met and the included XML is viewed as legitimate.
- Path to XSD schema location.
- The Schema Validation Filter utilizes the JAXP libraries to approve a message against a pattern. You should give the way, record name, and expansion of the outline or constructions in the Schema Locations property.
- Alternatively, you can set Schema Language to the pattern language to utilize. If not indicated, the property defaults to XML Schema.
- For the situation you need to get an exemption or potentially call another stream when the approval comes up short, you could wrap the construction approval channel inside a message channel and afterward use "on Unaccepted" and "throwOnUnaccepted" setup ascribes to determinate the conduct.
You might also be interested in: Mule 4: JSON Schema Validation
Example of Schema Validation in Mule 4
See how to validate an XML payload using the Schema validation component.
Please follow the below steps:
Create a new Mule Project as XML_Schema_Validation
Intuitive an HTTP listener connector to get a solicitation for your servers and give the host and port numbers. Here, the host is set to localhost and port to 8081. Test your association and check if the port is being used or not and test it effectively.
Set the path as /schema.
Drag the schema validator Component
Select the schema language and add module configuration also.
NOTE: Example for X12 Schema:
The schema is in the form of (file.xsd) extension
Drag the logger component and check the payload and whether the validation is successful or not.
Run the project
Open the postman and hit your service URL request as shown. http://localhost:8081/schema
Our Output Payload as
Now, we look about the entire flow of a Mule project i.e XML schema validation.
NOTE: Entire code of the example:
Mule 4 accompanies several upgrades and improvements. Validate schema component in Mule 3 was different compared to Mule 4, and it has been rearranged for developers. In this way, it is simple to execute and gives some additional highlights.
Opinions expressed by DZone contributors are their own.