Spring Book – Chapter 16 – Web Services – Spring WS

Server-side Integration Testing

Similar to client-side, the core class for doing server-side integration testing is the org.springframework.ws.test.server.MockWebServiceClient. It sends request and validates response using fake clients. It also allows to fully testing the org.springframework.ws.server.MessageDispatcher class configuration in all aspects.

MockWebServiceClient class creates a request message and then sends it over to the endpoint(s) that are configured in a standard MessageDispatcherServlet application context. These endpoints will then handle the message, and create appropriate response. The client then receives this response, and verifies it against registered expectations.

The various steps involved in using MockWebServiceClient can be summarized as below in bullet points:

  • Create an instance of MockWebServiceClient using one of its factory methods.
  • Now send messages by calling the “sendRequest()” method with a org.springframework.ws.test.server.RequestCreator callback.
  • Now setup the response expectation(s) by calling “andExpect” method with a org.springframework.ws.test.server.ResponseMatcher callback.
  • You can now repeat the previous step for multiple assertions according to your application requirement.

Just so that you don’t want to turn pages back, here is Listing 16-22 which shows the same EndPoint for the booking service repeated.

Listing 16-22. Java class for configuring endpoint

Listing 16-23 shows a complete test class which works you through the various steps summarized as above and gives you a full example in action.

Listing 16-23. Server side integration test case for the created web service

Summary

After reading this chapter, you should now have a clear idea of what a web service is along with various terminologies and concepts. You should also have a clear idea of the support provided by Spring WS in developing web service for your application.

Spring WS is a contract-first way of creating web services using XML schema. It has robust implementation using XPath which is very key in its adoption. It has easy and simple annotation based programming model as well.

Being contract-first is both its strength and weakness. It doesn’t haven any code generation and is made exclusively for and by the Spring Framework. It supports two WS-security implementations namely WSS4J and XWSS in all aspects and securing your web service is as easy as configuring your Spring beans. It supports different XML marshalling and handling technologies, making it ideal to configure according to your application requirement. It also has a capability of generating WSDL from the declared XSD as handling XSD is much easy compared to WSDL. One of the weaknesses of Spring WS is that it required programmatic processing of XML message payloads which could be development intensive to some extend.

The chapter provided a step by step approach of creating and end to end web service, which would have given you hands-on experience on creating a web service using Spring WS. Later on we covered some advanced topics like interceptors and testing capabilities which Spring WS gives you to use in your application. You should now have a clear picture of these advanced topics as well.

I hope you have enjoyed reading this Chapter to the last page and would be ready in all aspects to write your own web service in your application.

Page Visitors: 8452

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.

Leave a Reply

Your email address will not be published. Required fields are marked *