SlideShare a Scribd company logo
Ankit Lawaniya
9/3/2017 Ankit Lawaniya 1
The Schema Validation filter takes XML inputs and validates these against a
referenced XSD schema. Typically, we’ll place it at the start of the Mule flow
to determine whether the incoming message or event should be handled or
not, allowing the message to only continue on along the flow when the filter
validations are met and the included XML is considered valid. Schema
Validator is provided out of the box with Mule.
9/3/2017 Ankit Lawaniya 2
A common use case in Mule ESB flows is validating if an XML document is
valid against a corresponding XSD, so we can make sure we are receiving the
correct XML, and will forward it for the further processing.
Syntax:
<mulexml:schema-validation-filter
schemaLocations="src/main/resources/File/Process/Schema.xsd"
returnResult="true" name="OrderData_Schema_Validation"
doc:name="Schema Validation" />
9/3/2017 Ankit Lawaniya 3
The "standard" way of Validating XML schema in Mule is by using the
schema-validation-filter and especially in combination with the message-
filter.
In a case when you want to get an exception and/or call another flow when
the validation fails, you could wrap the schema validation filter inside a
message filter and then use "onUnaccepted" and "throwOnUnaccepted"
configuration attributes to determine the behavior.
Here we have wrapped the schema-validation-filter in a message-filter and
set throwOnUnaccepted to "true.“
<message-filter throwOnUnaccepted="true" >
<mulexml:schema-validation-filter
schemaLocations="/File/Process/Schema.xsd" returnResult="true"
name="OrderData_Schema_Validation"
doc:name="Schema Validation" />
</message-filter>
9/3/2017 Ankit Lawaniya 4
In order to allow a valid XML to pass the filter, you need to set the
returnResult to false in your schema-validation-filter. This way, the payload
of the message that is passed onwards to the next element in your flow will
retain the XML content.
Let’s walk through how to use All Validator in a Mule application. In this
example, we are receiving the XML file through file connector, which will be
validated against an XSD schema file defined in the application. If validation
fails, then we catch the exception and print the "Schema Not Validated"
message along with the exception.
9/3/2017 Ankit Lawaniya 5
9/3/2017 Ankit Lawaniya 6
9/3/2017 Ankit Lawaniya 7
9/3/2017 Ankit Lawaniya 8
9/3/2017 Ankit Lawaniya 9
Now in the XSD XML if we change the any of the element against the schema defined ,we
will be getting the below exception.
ERROR 2017-08-08 21:01:19,585 [[schemavalidation1].SchemaValidationFLow.stage1.02]
org.mule.exception.CatchMessagingExceptionStrategy:
********************************************************************************
Message : Message has been rejected by filter.
Filter : org.mule.module.xml.filters.SchemaValidationFilter@39c5e4bb (null)
Payload : <?xml version="1.0" encoding="UTF-8"?>
Element XML : <message-filter throwOnUnaccepted="true" doc:name="Message">
<mulexml:schema-validation-filter
schemaLocations="src/main/resources/File/Process/Schema.xsd" returnResult="true"
name="OrderData_Schema_Validation" doc:name="Schema Validation"></mulexml:schema-
validation-filter>
</message-filter>
Payload Type : org.apache.xerces.dom.DocumentImpl
Element : /SchemaValidationFLow/processors/2 @
schemavalidation1:schemavalidation1.xml:23 (Message)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.routing.filter.FilterUnacceptedException: Message has been rejected by filter.
9/3/2017 Ankit Lawaniya 10
9/3/2017 Ankit Lawaniya 11

More Related Content

PPT
Spring security integrate with mule
PPT
Mule with spring security manager
PPTX
Mule message processor or routers
PPTX
Validate json schema component
PPT
Mule security - spring security manager
PPTX
Mulesoft idempotent Message Filter
PPTX
Mule esb
PPTX
Mule message processor or routers
Spring security integrate with mule
Mule with spring security manager
Mule message processor or routers
Validate json schema component
Mule security - spring security manager
Mulesoft idempotent Message Filter
Mule esb
Mule message processor or routers

Similar to Schema validation filter (xml schema validation) (20)

PPTX
First successful-router
PPTX
Message processor in mule
PPTX
Improving performance with cache scope in mule
PPTX
Elements in a mule flow
PDF
Mule ESB
PPTX
Elements in a muleflow
PPTX
Send email attachment using smtp in mule esb
PPTX
Mule esb mule message
PPT
Mule esb presentation 2015
PPTX
Email using mule
PPTX
Send email attachment using smtp in mule esb
PPTX
Send email attachment using smtp in mule esb
PPTX
Send email attachment using smtp in mule esb
PPTX
Send email attachment using smtp in mule esb
PPTX
Send email attachment using smtp in mule esb
PDF
XML Schema Computations: Schema Compatibility Testing and Subschema Extraction
PPTX
Send email attachment using smtp in mule esb
PDF
Spring ws
PDF
InforUMobile SMS API
PPTX
Mule ESB Tutorial Part 2
First successful-router
Message processor in mule
Improving performance with cache scope in mule
Elements in a mule flow
Mule ESB
Elements in a muleflow
Send email attachment using smtp in mule esb
Mule esb mule message
Mule esb presentation 2015
Email using mule
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
XML Schema Computations: Schema Compatibility Testing and Subschema Extraction
Send email attachment using smtp in mule esb
Spring ws
InforUMobile SMS API
Mule ESB Tutorial Part 2
Ad

More from Ankit Lawaniya (9)

PPTX
Content based routing using mule choice flow control
PPTX
Until successful scope in mule
PPTX
Iterative processing using the for each scope in
PPTX
Cors (cross origin request sharing) in mule
PPTX
Content enrichment using mule message enricher
PPTX
Validation module in mule
PPTX
Parse template transformer mule
PPTX
Active mq read and write flow in mule
PPTX
Composite source in mule
Content based routing using mule choice flow control
Until successful scope in mule
Iterative processing using the for each scope in
Cors (cross origin request sharing) in mule
Content enrichment using mule message enricher
Validation module in mule
Parse template transformer mule
Active mq read and write flow in mule
Composite source in mule
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
sap open course for s4hana steps from ECC to s4
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Schema validation filter (xml schema validation)

  • 2. The Schema Validation filter takes XML inputs and validates these against a referenced XSD schema. Typically, we’ll place it at the start of the Mule flow to determine whether the incoming message or event should be handled or not, allowing the message to only continue on along the flow when the filter validations are met and the included XML is considered valid. Schema Validator is provided out of the box with Mule. 9/3/2017 Ankit Lawaniya 2
  • 3. A common use case in Mule ESB flows is validating if an XML document is valid against a corresponding XSD, so we can make sure we are receiving the correct XML, and will forward it for the further processing. Syntax: <mulexml:schema-validation-filter schemaLocations="src/main/resources/File/Process/Schema.xsd" returnResult="true" name="OrderData_Schema_Validation" doc:name="Schema Validation" /> 9/3/2017 Ankit Lawaniya 3
  • 4. The "standard" way of Validating XML schema in Mule is by using the schema-validation-filter and especially in combination with the message- filter. In a case when you want to get an exception and/or call another flow when the validation fails, you could wrap the schema validation filter inside a message filter and then use "onUnaccepted" and "throwOnUnaccepted" configuration attributes to determine the behavior. Here we have wrapped the schema-validation-filter in a message-filter and set throwOnUnaccepted to "true.“ <message-filter throwOnUnaccepted="true" > <mulexml:schema-validation-filter schemaLocations="/File/Process/Schema.xsd" returnResult="true" name="OrderData_Schema_Validation" doc:name="Schema Validation" /> </message-filter> 9/3/2017 Ankit Lawaniya 4
  • 5. In order to allow a valid XML to pass the filter, you need to set the returnResult to false in your schema-validation-filter. This way, the payload of the message that is passed onwards to the next element in your flow will retain the XML content. Let’s walk through how to use All Validator in a Mule application. In this example, we are receiving the XML file through file connector, which will be validated against an XSD schema file defined in the application. If validation fails, then we catch the exception and print the "Schema Not Validated" message along with the exception. 9/3/2017 Ankit Lawaniya 5
  • 10. Now in the XSD XML if we change the any of the element against the schema defined ,we will be getting the below exception. ERROR 2017-08-08 21:01:19,585 [[schemavalidation1].SchemaValidationFLow.stage1.02] org.mule.exception.CatchMessagingExceptionStrategy: ******************************************************************************** Message : Message has been rejected by filter. Filter : org.mule.module.xml.filters.SchemaValidationFilter@39c5e4bb (null) Payload : <?xml version="1.0" encoding="UTF-8"?> Element XML : <message-filter throwOnUnaccepted="true" doc:name="Message"> <mulexml:schema-validation-filter schemaLocations="src/main/resources/File/Process/Schema.xsd" returnResult="true" name="OrderData_Schema_Validation" doc:name="Schema Validation"></mulexml:schema- validation-filter> </message-filter> Payload Type : org.apache.xerces.dom.DocumentImpl Element : /SchemaValidationFLow/processors/2 @ schemavalidation1:schemavalidation1.xml:23 (Message) -------------------------------------------------------------------------------- Root Exception stack trace: org.mule.api.routing.filter.FilterUnacceptedException: Message has been rejected by filter. 9/3/2017 Ankit Lawaniya 10