validating soap request in mule
TRANSCRIPT
![Page 1: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/1.jpg)
Validating a SOAP Request in Mule
![Page 2: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/2.jpg)
We often come across SOAP web services in our project and often face different challenges in handling SOAP web services. One such challenge is SOAP request validation.
.
![Page 3: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/3.jpg)
In Mule ESB we can expose a SOAP webservices and can handle the request validation in very simple way.
.
![Page 4: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/4.jpg)
Yes, I am talking about using message filter to validate a SOAP request against a given XSD file
In simple words if we have the XSD file of web service we can validate the request of the web service against that XSD using a schema validation filter in Mule..
![Page 5: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/5.jpg)
Let’s see how…
Let consider we have a SOAP webs ervice exposed in Mule by following way :-
![Page 6: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/6.jpg)
Now, if we want to validate the request with an XSD file of the web service and want to throw a custom message in case if the SOAP request is invalid or incorrect, we need to use schema validation filter
![Page 7: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/7.jpg)
So after adding schema validation filter in our flow, our flow looks like the following
![Page 8: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/8.jpg)
We can also add a subflow which will throw custom message if the SOAP request is invalid as follow :-
![Page 9: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/9.jpg)
So, if we test the webservice with a wrong SOAP request in SoapUI we will get a custom message :-
![Page 10: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/10.jpg)
This is how the flow works:-
![Page 11: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/11.jpg)
<mulexml:schema-validation-filter name="Schema_Validation" schemaLocations="MainData.xsd" returnResult="true" doc:name="Schema Validation" />
The code:-You need to use schema validation filter which will refer to your XSD files for validating a SOAP request as follows:-
The Schema Validation Filter uses the JAXP libraries to validate a message against a schema. You must provide the path, file name, and extension of the schema or schemas in the Schema Locations property.
![Page 12: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/12.jpg)
<flow name="ServiceFlow" doc:name="ServiceFlow"><http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/><message-filter onUnaccepted="ValidationFailFlow" doc:name="filter to validate xml against xsd" throwOnUnaccepted="true" > <filter ref="Schema_Validation"/> </message-filter><cxf:jaxws-service validationEnabled="true" serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP"/> <component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/></flow>
A code snipped of the Mule config:-
![Page 13: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/13.jpg)
To get the full code access for implementing a SOAP Request validator in Mule, please visit :-http://anirbansenchowdhary.com/blog/?p=131
You can also visit Mule documentation on Schema Validation :- http://www.mulesoft.org/documentation/display/current/Schema+Validation+Filter
![Page 14: Validating soap request in mule](https://reader036.vdocument.in/reader036/viewer/2022083105/5877f8191a28ab91178b515b/html5/thumbnails/14.jpg)
Thank You