'Karate 0.9.6 - 1.1.0 upgrade issue - blank xmlns attribute getting added in the request body when reading from a xml file in a put request
I have a put request for one API call whose body looks like this:
<?xml version="1.0"?>
<marginCalls xmlns="create.margincall.api.xxx.com">
<marginCall>
<currency>USD</currency>
<totalCallAmount>1000</totalCallAmount>
<callType>Netted</callType>
<deliveryType>Deliver</deliveryType>
<subAccount>Bye</subAccount>
<valuationDate>
<day>{date}</day>
<month>{month}</month>
<year>{year}</year>
</valuationDate>
<marginAgreementShortName>F 1030 - Seg IA</marginAgreementShortName>
</marginCall>
</marginCalls>
This body is read with the following lines in my test:
* def datafile = 'classpath:MM/PayloadFiles/CreateCall.xml'
* def payload = read(datafile)
* xml xmlPayload = payload
In Karate 0.9.6, this worked perfectly well without issues. When I upgraded it to Karate 1.1.0, the same test shows the following XML Validation Error:
classpath:MM/ExpectedCalls/CreateCall.feature:10
status code was: 400, expected: 200, response time in milliseconds: 463, url: https://nw-qa-mihir.xxx.net/amp/marginCall/create?v=4.0, response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<amp:webServiceError xmlns:amp="error.api.xxx.com">
<amp:ampErrorCode>5002</amp:ampErrorCode>
<amp:ampErrorDescription>JAXB Unmarshaling Error</amp:ampErrorDescription>
<amp:errorMessage>XML Validation exception occured at line [2], column [24], with error message [cvc-complex-type.2.4.a: Invalid content was found starting with element 'marginCall'. One of '{"create.margincall.api.xxx.com":skip, "create.margincall.api.xxx.com":max, "create.margincall.api.xxx.com":totalCount, "create.margincall.api.xxx.com":marginCall}' is expected.]</amp:errorMessage>
<amp:httpStatusCode>400</amp:httpStatusCode>
<amp:httpStatusDescription>Bad Request</amp:httpStatusDescription>
</amp:webServiceError>
In short, this gives me a bad request 400 error. I investigated in the Karate logs and this is what I found in the request body :
<marginCalls xmlns="create.margincall.api.xxx.com">
<marginCall xmlns="">
<currency>USD</currency>
<totalCallAmount>1000</totalCallAmount>
<callType>Netted</callType>
<deliveryType>Deliver</deliveryType>
<subAccount>Bye</subAccount>
<valuationDate>
<day>16</day>
<month>5</month>
<year>2020</year>
</valuationDate>
<marginAgreementShortName>F 1030 - Seg IA</marginAgreementShortName>
</marginCall>
</marginCalls>
The issue is on the 2nd line of the request body:
<marginCall xmlns="">
For some reason, the xlmns attribute is getting added in the 2nd line of request payload which is originally not present(as seen from the request payload above) and this causes the request to be treated as a bad request. I verified and this was not happenning in the 0.9.6 version. The only thing I changed was to update the pom file and change the testrunner file to reflect on the changes from 0.9.6 to 1.1.0.
Any help or suggestions will be helpful.
Solution 1:[1]
Karate 1.2.0 (now RC6 is available) has a configure xmlNamespaceAware
option. So please try this:
* configure xmlNamespaceAware = true
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter Thomas |