How to throw Soap Fault manually in mule

旧时模样 提交于 2020-01-02 07:27:49

问题


I'm face with a situation where we cannot use schema to validate incoming request (basically schema is there but it accepts any String in request, wsdl designers have their own reasons to do that to accept request from different sources and flexibility). But when the request is received, I validate that the child element of request wrapper is what we expect (using XPath for that). Now if the child element is not what expected, I'd like to throw Soap Fault with Client code and may be include error message that schema validation failed, request doesn't contain valid element.

I'm using Mule 3.3 and doing my XPath validation in <choice> element and I want to throw exception in <otherwise> block.

  1. Is there a way to throw Soap Fault manually in mule flow and
  2. How to add custom fault string. I'm not sure if an outInterceptor will solve the purpose as I'm not using schemaValidation attribute of <cxf:proxyService>.

Here is part of my flow

<http:inbound-endpoint address="${service.address}" exchange-pattern="request-response">
  <cxf:proxy-service wsdlLocation="classpath:service.wsdl" namespace="http://company.com/services/service" service="CompanyService" />
</http:inbound-endpoint>
<choice>
  <when>.....</when>
  <otherwise><!-- Here I want to throw Soap Fault ---></otherwise>
</choice>
<catch-exception-strategy>
  <flow-ref name="generateErrorResponse" />
</catch-exception-strategy>

回答1:


Since you are using a cxf:proxy-service you have complete control on the response. For example, if you add the following in your otherwise block, you'll be able to create whatever SOAP fault you want:

<expression-component><![CDATA[
 message.payload = '<soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
                 + '<faultcode>A code</faultcode><faultstring>A string</faultstring>'
                 + '</soap:Fault>';
]]></expression-component>


来源:https://stackoverflow.com/questions/14383639/how-to-throw-soap-fault-manually-in-mule

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!