I have a problem with mapping outgoing data to a SOAP response using ApiKit for SOAP.
This is what the response SHOULD look like:
<Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<getPricesResponse xmlns:ns4="http://sax.xml.org/xsd" xmlns:ns3="http://sql.java/xsd" xmlns:ns2="http://some.soap.service.pl" xmlns="http://some.soap.service.pl/xsd">
<return>
<dealerNoNabywca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<dealerNoOdbiorca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<errorType>
VIN_NOT_FOUND
</errorType>
<price1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<price2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<price3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<resultStatus>
0
</resultStatus>
</return>
</getPricesResponse>
</Body>
</Envelope>
But this is how the response looks like:
<Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<getPricesResponse xmlns:ns0="http://some.soap.service.pl">
<return>
<dealerNoNabywca xmlns:ns01="http://some.soap.service.pl/xsd" />
<dealerNoOdbiorca xmlns:ns01="http://some.soap.service.pl/xsd" />
<errorType xmlns:ns01="http://some.soap.service.pl/xsd">
VIN_NOT_FOUND
</errorType>
<price1 xmlns:ns01="http://some.soap.service.pl/xsd" />
<price2 xmlns:ns01="http://some.soap.service.pl/xsd" />
<price3 xmlns:ns01="http://some.soap.service.pl/xsd" />
<resultStatus xmlns:ns01="http://some.soap.service.pl/xsd">
0
</resultStatus>
</return>
</getPricesResponse>
</Body>
</Envelope>
This is the DataWeave transformer:
output application/java
ns ns0 http://some.soap.service.pl
ns ns01 http://some.soap.service.pl/xsd
---
{
body: {
ns0#getPricesResponse: {
ns0#return: {
ns01#dealerNoNabywca: payload.return.dealerNoNabywca,
ns01#dealerNoOdbiorca: payload.return.dealerNoOdbiorca,
ns01#errorType: payload.return.errorType,
ns01#price1: payload.return.price1,
ns01#price2: payload.return.price2,
ns01#price3: payload.return.price3,
ns01#resultStatus: payload.return.resultStatus
}
}
} write "application/xml"
}
As I understand there is some kind of problem with the XML namespaces, but I have no idea how to make the response look like it should, with correct namespaces... Is there even a way to make my current response look like the expected response?
The only problem I see is that your script is not using the same namespace as the expected result for getPricesResponse. That is easily resolved by using ns01 in your script. Adding the XSI attribute and namespace gives you a semantically equivalent result.
There are some differences that don't affect the semantics. Namespaces ns2, ns3, ns4 are not used so there is no reason for DataWeave to add them and they are not in the script.
The other difference is that DataWeave doesn't seem to allow a default namespace. That is just syntax sugar and doesn't change the meaning for any standard XML parser.
Example: