Probem with custom mediator to trigger SOAP fault

cheehoo84.gmail.com's picture
Hi All, May i know is there anyway to use custom mediator to trigger SOAP faults ? Currently i have a requirement which i need to perform some validation for the incoming requests and if validation fails it need to return some SOAP fault in defined in a xml. Is there any approach for it ? Thanks. Regards Chee Hoo.
indika's picture

Hi Schema based XML

Hi Schema based XML validation can be done through the validate mediator.  Sample 7 [1] demonstrates this. However, out makefault mediator cannot read a XML file and find the SOAP fault to be sent form a set of faults. However, there is an option to set a XML as fault detail elements, <makefault><detail>XML</detail></makefault> … but Fault mediator itself cannot correlate an exception occurred to a particular fault detail element. Therefore, you have to use a filter mediator.  You should be able to use the example shown bellow. A custom mediator can also be used. Put it inside on-fail of the validate mediator.   <validate>     <schema key="validate_schema"/>     <on-fail>           <!-- if the request does not validate againt schema throw a fault -->         <switch source="xpath to differentiate requests">             <case regex="regex1">                 <makefault>                     <code value="tns:Receiver"                           xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>                     <reason expression="get-property('ERROR_DETAIL')"/>                     <detail>XML 1</detail>                 </makefault>             </case>             <case regex="regex2">                 <makefault>                     <code value="tns:Receiver"                           xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>                       <reason expression="get-property('ERROR_DETAIL')"/>                     <detail>XML 2</detail>                 </makefault>             </case>             <default>                 <makefault>                     <code value="tns:Receiver"                           xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>                       <reason expression="get-property('ERROR_DETAIL')"/>                     <detail>XML default</detail>                 </makefault>             </default>         </switch>         <property name="RESPONSE" value="true"/>         <header name="To" expression="get-property('ReplyTo')"/>     </on-fail> </validate>   Thanks  Indika  [1] http://wso2.org/project/esb/java/2.1.3/docs/samples/message_mediation_samples.html#Sample7   
cheehoo84.gmail.com's picture

Thanks for your hasty

Thanks for your hasty response. So is that means it cannot be achieve using a custom mediator in java only ? Because the requirement need it to be reused for other webservices and if we gonna have it created in this way then we might need to create all the mediator validators, custom mediator, etc for each set of webservices hosted. Thanks. Regards, Chee Hoo
indika's picture

Hi Chee If you are going to

Hi Chee If you are going to write a mediator that do work of validator , makefault , etc + your custom work , it will be a lot of work. Can you use the validate mediator for validating XMLs ...? If so / cannot, what is the improvement you need ... Can you use the makefault mediator for creating faults ...? if so / cannot, what is the improvement you need ... Let's try to identify and do only the required improvement. Thanks Indika
cheehoo84.gmail.com's picture

Hi Indika, The reason for

Hi Indika, The reason for trying to write the custom mediator instead of chaining up the validator and makefault is because there will be alot webservice using this same logic (which is the validating the request then throw soap fault if there is an error). So we do prefer to have only one instance of custom mediator for each webservice. As in future if we need to change some different logic for all the webservices we just need to replace the custom mediator instead of changing all the mediators so that the workload can be minimize in maintenance stage. Is that is not feasible in doing it in custom mediator ? Thanks, Regards, Chee Hoo
cheehoo84.gmail.com's picture

Hi Indika, Besides the

Hi Indika, Besides the above, can i know is that anyway to set the value into the property in custom mediator so that i can get back the value using the expression such as () in other mediators. Thanks, Regards. Chee Hoo
indika's picture

Hi Chee if you have put the

Hi Chee if you have put the value as a synapse message context property , it can be accessed through the get-property XPath function... get-property('key') .... But ...In many existing mediators , the only string value of the get-property('key') is used. Thanks Indika
indika's picture

Hi Chee So, your problem is

Hi Chee So, your problem is that you have to specify 10 validate mediators if there are 10 web services ...same for make fault.... In order to use a one validator config , do you think what short of improvements should be done? a composite validator where a child validator select based on the information in the message (some xpath) ... If we can identify required improvement to do , we may be able to improve existing mediators to support your requirement. BTW , for your question - Is that is not feasible in doing it in custom mediator ? You should definitely be able to do it ... you may have to merge some logic of validate / make-fault-filter, etc ... But , my preference is to check feasibility to improve existing mediators to support your requirement. Thanks Indika
cheehoo84.gmail.com's picture

Hi Indika, In my case i

Hi Indika, In my case i can't seems to use the validator mediator because my validation wasn't only the datatypes. As our requirement need to validate the request value against datastore value to determine to throw which kind of soap fault error. Since i can set the value into the get-Property in custom mediator, it seems that my requirement can be achieved by mixing and matching with the filter mediator to decide to throw which soap-fault. However using filter to satify mutliple condition is undesirable because it require to chain many filter mediator and i discovered that switch mediator was only supporting xpath source but not regular expression which i could pass the (get-Property) into it for conditioning. Is there any suggestion to do that ? For the validator mediator improvement, how about using the same concept of dynamic sequence which we dynamically load the .xsd into the validator mediator. Thanks Regards Chee Hoo
cheehoo84.gmail.com's picture

In addition to above. We

In addition to above. We trying to choose any possible solution at this point of time due to timeline constraint. Besides that i have an error when the message returned from the esb. Error : ------------------------------ soapenv:Receiver namespace mismatch require http://example.ws found http://www.w3.org/2003/05/soap-envelope Fragment of synapse.xml -------------------------------- May i know what i need to set in the fault mediator to throw the soapfault to client ? Thanks Chee Hoo
indika's picture

Hi Chee >>>However using

Hi Chee >>>However using filter to satify mutliple condition is undesirable because it require to chain many filter mediator and i discovered that switch mediator was only supporting xpath source but not regular expression which i could pass the (get-Property) into it for conditioning. Is there any suggestion to do that ? Switch cases have regex .... switch mediator extracts the data using the given source XPath and try to match the resulted value with the regex in switch cases ... ... If you have to pass a regex to a get-property , you have to extend GetPropertyFunction ... I hope you can do conditioning using existing standard XPath functions >>>For the validator mediator improvement, how about using the same concept of dynamic sequence which we dynamically load the .xsd into the validator mediator. Validate mediator already can load XSD for registry (dynamic)...but in the validate mediator , there is only one schema instance ... if the resource related to the key has changed , then the schema is reloaded again... Validate mediator has the capability of the specifying any number of keys ... you may be able to use this feature ....
indika's picture

The error is related with

The error is related with your request's name spaces ...please check with service WSDL .. and sent requests according to the WSDL to know about how to send faults look at [1].... [1] http://wso2.org/project/esb/java/2.1.3/docs/samples/message_mediation_samples.html#Sample4
cheehoo84.gmail.com's picture

This soap problem was solved.

This soap problem was solved. I forgot to put the send mediator right after the fault mediator. Thanks.
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)