Skip to content

Commit

Permalink
docs: adds SOAP fault example.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Oct 17, 2024
1 parent 55c6f5a commit e43468e
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/soap/fault-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Return a SOAP fault

This example returns a SOAP fault for a particular operation.

Start mock server:

```bash
imposter up
```

Send request:

```bash
curl --data '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header/>
<env:Body>
<getPetByIdRequest xmlns="urn:com:example:petstore">
<id>10</id>
</getPetByIdRequest>
</env:Body>
</env:Envelope>' http://localhost:8080/pets/
```

Response:

```xml
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header/>
<env:Body>
<urn:getPetFault xmlns:urn="urn:com:example:petstore">
<code>3</code>
<description>string</description>
</urn:getPetFault>
</env:Body>
</env:Envelope>
```

## Notes

This example can be extended to use conditional matching with resources to only return a fault under specific conditions.
8 changes: 8 additions & 0 deletions examples/soap/fault-example/imposter-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugin: soap
wsdlFile: service.wsdl

resources:
- binding: SoapBinding
operation: getPetById
response:
statusCode: 500
84 changes: 84 additions & 0 deletions examples/soap/fault-example/service.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>

<definitions name="PetService" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="urn:com:example:petstore"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
targetNamespace="urn:com:example:petstore">

<documentation>
A pet store service with a single operation and SOAP binding.
</documentation>

<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:com:example:petstore"
targetNamespace="urn:com:example:petstore">

<xs:complexType name="petType">
<xs:all>
<xs:element name="id" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
</xs:all>
</xs:complexType>

<xs:complexType name="getPetByIdRequest">
<xs:all>
<xs:element name="id" type="xs:int"/>
</xs:all>
</xs:complexType>

<xs:complexType name="fault">
<xs:all>
<xs:element name="code" type="xs:int" />
<xs:element name="description" type="xs:string" />
</xs:all>
</xs:complexType>

<xs:element name="getPetByIdRequest" type="getPetByIdRequest"/>
<xs:element name="getPetByIdResponse" type="petType"/>
<xs:element name="getPetFault" type="fault"/>
</xs:schema>
</types>

<message name="getPetByIdRequest">
<part element="tns:getPetByIdRequest" name="parameters"/>
</message>
<message name="getPetByIdResponse">
<part element="tns:getPetByIdResponse" name="parameters"/>
</message>
<message name="getPetFault">
<part element="tns:getPetFault" name="parameters"/>
</message>

<portType name="PetPortType">
<operation name="getPetById">
<input message="tns:getPetByIdRequest" name="getPetByIdRequest"/>
<output message="tns:getPetByIdResponse" name="getPetByIdResponse"/>
<fault message="tns:getPetFault" name="getPetFault" />
</operation>
</portType>

<binding name="SoapBinding" type="tns:PetPortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/soap"/>

<operation name="getPetById">
<soap12:operation soapAction="getPetById" style="document"/>
<input name="getPetByIdRequest">
<soap12:body use="literal"/>
</input>
<output name="getPetByIdResponse">
<soap12:body use="literal"/>
</output>
<fault name="getPetFault">
<soap12:body use="literal"/>
</fault>
</operation>
</binding>

<service name="PetService">
<port name="SoapEndpoint" binding="tns:SoapBinding">
<soap12:address location="http://www.example.com/pets/"/>
</port>
</service>
</definitions>

0 comments on commit e43468e

Please sign in to comment.