{
body : {
ns0#OrderTshirtResponse: {
orderId: "I got a request from "
++ payload.body.ns0#OrderTshirt.name
++ " using the following auth header "
++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
}
} write "application/xml"
}
Set a SOAP Header
Add SOAP headers declared in your WSDL to outbound responses from an APIkit for SOAP application. This walkthrough extends the OrderTshirt flow and DataWeave so the response includes header data such as APIUsageInformation. Download tshirt2.wsdl, complete prerequisites for Using APIkit for SOAP, and create an APIkit for SOAP project before you begin.
-
In Anypoint Studio, open
tshirt2.wsdlinsrc/main/resources/apiand scroll to theAPIUsageInformationelement, which is the element expected by the contract. -
On the canvas, select
Transform Messagein theOrderTshirt:/soapkit-configflow.The following DataWeave code is available:
-
Add the following
APIUsageInformationheader declaration:{ body : { ns0#OrderTshirtResponse: { orderId: "I got a request from " ++ payload.body.ns0#OrderTshirt.name ++ " using the following auth header " ++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "") } } write "application/xml", headers: { (1) header: { ns0#APIUsageInformation: { } } write "application/xml" } }1 This DataWeave code adds headers to the output of the Transform Messagecomponent. -
Add the
apiCallsRemainingheader to theAPIUsageInformationelement:{ body : { ns0#OrderTshirtResponse: { orderId: "I got a request from " ++ payload.body.ns0#OrderTshirt.name ++ " using the following auth header " ++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "") } } write "application/xml", headers: { header: { ns0#APIUsageInformation: { apiCallsRemaining: 10 (1) } } write "application/xml" } }1 Set apiCallsRemainingto10. -
Save and run the project again.
-
In SoapUI, execute the
OrderTshirtrequest again.The response envelope from APIkit for SOAP is:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns0:APIUsageInformation xmlns:ns0="http://mulesoft.org/tshirt-service">
<apiCallsRemaining>10</apiCallsRemaining>
</ns0:APIUsageInformation>
</soap:Header>
<soap:Body>
<ns0:OrderTshirtResponse xmlns:ns0="http://mulesoft.org/tshirt-service">
<orderId>I got a request from John, using the following auth header 987654321</orderId>
</ns0:OrderTshirtResponse>
</soap:Body>
</soap:Envelope>



