What is SOAP API?
- SOAP (Simple Object Access Protocol) is a protocol for exchanging structured data between systems over a network.
- It uses XML as the message format and typically runs over HTTP/HTTPS.
- SOAP APIs are often used in enterprise applications (like banking, telecom, insurance) because they enforce strict standards for security, structure, and messaging.
- Message format → Always XML (not JSON).
- Transport → Usually HTTP/HTTPS (but can also use SMTP, TCP, etc.).
- WSDL (Web Services Description Language) → An XML document that describes the service (endpoints, operations, request/response structure).
- Highly standardized → Supports security (WS-Security), transactions, and reliable messaging.
RestAssured.get().- Get the SOAP endpoint URL and know which operations are available.
- Review the WSDL (it defines the request/response XML structure).
- Create the SOAP envelope (the wrapper XML with <Envelope>, <Header>, and <Body> tags).
- Add the operation and required parameters inside <Body>.
- Use an HTTP method (usually POST) to send the SOAP envelope as the request body.
- Set the appropriate headers (like Content-Type: text/xml or application/soap+xml).
- The server returns a SOAP response envelope in XML.
- Extract values using XMLPath (similar to JSONPath but for XML).
- Verify status code (e.g., 200 OK).
- Check that the SOAP response contains expected elements and values.
Key Concepts:
SOAP (Simple Object Access Protocol) is a protocol for exchanging structured XML data.
WSDL (Web Services Description Language) is used to describe SOAP services.
SOAP API is generally tested using POST, but for some services (like fetching WSDL), GET is used.
Example SOAP GET Use Case:
Fetch the WSDL file or perform a test GET to an endpoint.
Let’s use this public SOAP service for currency conversion WSDL (GET example):
http://www.dneonline.com/calculator.asmx?WSDL
This WSDL can be fetched using a GET request.
Step-by-step: Testing SOAP GET using Rest Assured:
Maven Dependency:
<dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>5.3.1</version> <scope>test</scope> </dependency>
import io.restassured.RestAssured; import io.restassured.response.Response; public class SoapGetTest { public static void main(String[] args) { // Base URI for the SOAP service String url = "http://www.dneonline.com/calculator.asmx?WSDL"; // Send GET request Response response = RestAssured .given() .when() .get(url) .then() .extract() .response(); // Print status code and response System.out.println("Status Code: " + response.getStatusCode()); System.out.println("Content-Type: " + response.getContentType()); System.out.println("Response Body:\n" + response.getBody().asString()); } }
Code explanation:
- Set the base URI
- Send GET request
- Print status code and response on console
We can assert response also by below code.
Optional: Add Test Assertion
import static io.restassured.RestAssured.*; import static org.hamcrest.Matchers.*; public class SoapGetTest { public static void main(String[] args) { given() .when() .get("http://www.dneonline.com/calculator.asmx?WSDL") .then() .statusCode(200) .contentType("text/xml; charset=utf-8") .body(containsString("definitions")); } }
Suggested Posts:
1. Validate Keys of API in RestAssured
2. Test Form Authentication in RestAssured
3. Test DELETE API in RestAssured
4. First RestAssured Code to Test API
5. Validate API Response from Database in RestAssured
No comments:
Post a Comment