mule soap
TRANSCRIPT
![Page 1: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/1.jpg)
MULE-SOAP
![Page 2: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/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: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/3.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 4: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/4.jpg)
Let’s see how…
Let consider we have a SOAP webs ervice exposed in Mule by following way :-
![Page 5: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/5.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 6: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/6.jpg)
So after adding schema validation filter in our flow, our flow looks like the following
![Page 7: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/7.jpg)
We can also add a subflow which will throw custom message if the SOAP request is invalid as follow :-
![Page 8: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/8.jpg)
So, if we test the webservice with a wrong SOAP request in SoapUI we will get a custom message :-
![Page 9: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/9.jpg)
This is how the flow works:-
![Page 10: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/10.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 11: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/11.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 12: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/12.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 13: Mule soap](https://reader033.vdocuments.us/reader033/viewer/2022042907/5877f7681a28ab91178b4f4f/html5/thumbnails/13.jpg)
Thank You