CodeSVby CA Technologies

SOAP Virtualization

< Back

Both examples use an application generated from WSDL by Spring Boot called HelloWorldClient, that uses SOAP. This client is set to receive a SOAP request with name and surname and responds with a greeting that includes these details.
TestRealService shows the request created by HelloWorldClient as it hits the real WebService, and as it sends back a simple greeting.
In TestVirtualService, a virtual service is configured to catch a request before it reaches the real WebService, and to send back a defined response. Although the same method is used with the same parameters, the request never gets to the endpoint. Instead, this is answered by our virtual service. POST requests are caught to virtualize the SOAP call.

SOAP request

@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
public class SpringWsApplicationTests {

	private HelloWorldClient helloWorldClient;

	public VirtualServerRule serverRule = new VirtualServerRule();

	public void setUp() throws Exception {

	public void testRealService() throws InterruptedException {
		assertThat(helloWorldClient.sayHello("John", "Doe")).isEqualTo("Hello John Doe!");

	public void testVirtualizedService() {
                String virtualizedResponse = "Greeting from virtualized service, John Doe!";
		String body =	
            "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"\">\n"
						+ "   <SOAP-ENV:Header/>\n"
						+ "   <SOAP-ENV:Body>\n"
						+ "      <ns2:greeting xmlns:ns2=\"\">\n"
						+ "         <ns2:greeting>Greeting from virtualized service, John Doe!\n"
						+ "      </ns2:greeting>\n"
						+ "   </SOAP-ENV:Body>\n"
						+ "</SOAP-ENV:Envelope>";

						.withContentType("text/xml; charset=utf-8")

		String responseGreeting = helloWorldClient.sayHello("John", "Doe");
		assertEquals(responseGreeting, vitrualizedResponse);

For a complete example see: SOAPExample