Closed KyrillosNageh closed 2 months ago
can you kindly share a native rest assured code snippet that works?
String requestXml="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <tem:Multiply>\n" +
" <tem:intA>10</tem:intA>\n" +
" <tem:intB>2</tem:intB>\n" +
" </tem:Multiply>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
Response response = given()
.header("Content-Type", "text/xml")
//.contentType(ContentType.XML)
.header("SOAPAction", "http://tempuri.org/" + "Multiply")
.body(requestXml)
.when()
.post("http://www.dneonline.com/calculator.asmx")
.then()
.statusCode(200) // Validate status code directly
.extract().response();
String Result =RestActions.getResponseXMLValue(response, "AddResponse/AddResult");
SHAFT.Report.log(">>>>>>>>>>>> Test result >>>> " + Result);
@MohabMohie
The issue occurs when we set Content-Type using api.addHeader("Content-Type", "application/json");
Where in this example when we use this api.addHeader("Content-Type", "application/json");
give the error that exist on screenshot
but with this, it works fine .setContentType(ContentType.JSON)
the main reason for it until now I think:
public void testCreateUser() { String requestBody= " {\n" + " \"name\": \"Test user1\",\n" + " \"job\": \"leader\"\n" + " }";
api = new SHAFT.API("https://reqres.in/api/");
api.addHeader("Content-Type", "application/json");
Response response = api.post("users")
//.setContentType(ContentType.JSON)
.setRequestBody(requestBody)
.performRequest();
System.out.println("Response Body: " + response.getBody().asString());
}
Describe the bug
When attempting to send a SOAP request with an XML body, the request fails due to an improper encoding of the content type text/xml. The system throws a java.lang.IllegalArgumentException indicating that it doesn't know how to encode the SOAP envelope as a byte stream
Environment
To Reproduce
Steps to reproduce the behavior:
Example code:
api = new SHAFT.API("http://www.dneonline.com/calculator.asmx"); String requestXml="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">\n" + " \n" +
" \n" +
" \n" +
" 10</tem:intA>\n" +
" 2</tem:intB>\n" +
" </tem:Multiply>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
api.addHeader("Content-Type", "text/xml"); api.addHeader("SOAPAction", "http://tempuri.org/Multiply"); Response response = api.post("") .setRequestBody(requestXml) .performRequest();
Expected behavior
The SOAP request should be properly encoded and sent to the server, with the XML body being handled as text/xml content.
Actual behavior
The system throws a java.lang.IllegalArgumentException, indicating that it does not know how to encode the SOAP envelope as a byte stream, causing the request to fail.
Link to SHAFT_Engine Console logs
https://gist.github.com/KyrillosNageh/086244efc9d26761bfc34e03c58a78e7