How do I raise a fault from a soap response, and then convert it to json?

Not applicable

In my Soap proxy the server can respond with:

<soap:Envelope 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>Invalid Service ID</faultstring>
      <detail/>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

How can do I raise a fault, capture the fault string and return it as JSON. I'm having a hard time even getting the fault raised, at the moment I've got the following but its not saving, giving a server error.

<Response>
  <Step>
    <FaultRules>
      <FaultRule>
        <Step>
          <Name>Raise-Fault-1</Name>
          <Condition>response.status.code = 500</Condition>
        </Step>
      </FaultRule>
    </FaultRules>
    <Name>Raise-Fault-Step-Name</Name>
  </Step>
</Response>

Raise-Fault-1 is the name of my Fault policy added to the response flow of my proxy.

What am I doing wrong?

Then I would like to respond in the Fault with JSON payload, which should be the easy bit?

Thanks in advance for any help.

Solved Solved
1 1 1,404
1 ACCEPTED SOLUTION

Not applicable

The issue here is that when backend raises a fault, normal proxy flow is bypassed. Hence your policy is ignored.

So you may need to add your policy to play with the response in the FaultRule section of the response.

<DefaultFaultRule name="DefaultFaultRule">
    <Step>
        <FaultRules/>
        <Condition>response.status.code = 500</Condition>
        <Name>Raise-Fault-1</Name>
    </Step>
    <Step>
        <FaultRules/>
        <Name>OtherErrorResponse</Name>
    </Step>
</DefaultFaultRule>

View solution in original post

1 REPLY 1

Not applicable

The issue here is that when backend raises a fault, normal proxy flow is bypassed. Hence your policy is ignored.

So you may need to add your policy to play with the response in the FaultRule section of the response.

<DefaultFaultRule name="DefaultFaultRule">
    <Step>
        <FaultRules/>
        <Condition>response.status.code = 500</Condition>
        <Name>Raise-Fault-1</Name>
    </Step>
    <Step>
        <FaultRules/>
        <Name>OtherErrorResponse</Name>
    </Step>
</DefaultFaultRule>