Configure Spring WS
To configure Spring WS in a Spring MVC application, do the following steps as detailed in the following section.
First, configure MessageDispatcherServlet in web.xml – Listing 16-3 shows configuring Spring WS servlet, org.springframework.ws.transport.http.MessageDispatcherServlet in web.xml file as shown below.
Listing 16-3. MessageDispatcherServlet configuration in web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<servlet> <servlet-name>spring-ws</servlet-name> <servlet-class> org.springframework.ws.transport.http.MessageDispatcherServlet </servlet-class> <init-param> <!-- Transforms the value of the 'location' of all the WSDL that it exposes to reflect the URL of the incoming request.--> <param-name>transformWsdlLocations</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>spring-ws</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> |
Next, configure Spring configuration file – Configure the various configuration in the Spring configuration files as beans. Configure the following beans as shown in Listing 16-4 below.
Listing 16-4. Configuraing Spring configuration beans
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<!-- Specify the XSD details as a bean --> <bean id=”schema” p:xsd="classpath:/booking.xsd" /> </bean> <!-- Publish the WSDL --> <bean id=”” class=””> <property name=”schema” ref=”schema”/> <property name=”portTypeName” value=”BookingResourcePort”/> <property name=”locationUri” value=”http://localhost:8080/spring- ws/loyalty/CreateBookingService”/> <property name=”targetNamespace” value=”http://www.apress.com/loyalty/definitions”/> </bean> |
Endpoints
There are various endpoints available which can be configured according to your application requirement. They are as below:
- DOM endpoints
- Marshalling endpoints
- XPath endpoints
Based on the message the web services receive, the endpoints can be categorized as follows:
- Message endpoints – full message will be delivered
- Payload endpoints – only payload will be delivered
Once you decide on the appropriate endpoint for your application, you will have to configure the endpoint in your Spring configuration file as shown in Listing 16-5 below. XPath endpoint will be used as an example for defining endpoints. Listing 16- 6 shows the endpoint Java class using XPath endpoint. Spring will use your endpoint PayloadRoot annotation to match WS request with appropriate method.
Listing 16-5. Java class for configuring endpoint
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import org.springframework.ws.server.endpoint.annotation.Endpoint; import org.springframework.ws.server.endpoint.annotation.PayloadRoot; @Endpoint public class BookingEndpoint{ @PayloadRoot(localPart = “bookingRequest”, namespace = “http://www.apress.com/loyalty”) public BookingResponse createBookingRequest(BookingRequest request){ //… Creation of booking logic BookingResponse result = new BookingResponse(); result.setResponse( “Request was: “ + request.getRequest() ); return result; } } |
Listing 16-6. Configuring endpoint in Spring configuration file
1 2 3 4 5 6 7 8 9 |
<!-- Declare enpoint --> <bean id=“bookingEndpoint” class=“com.apress.loyalty.ws.BookingEndpoint”/> <!-- Endpoint mapping. Scans for @PayloadRoot --> <bean id=“payloadMapping” class=“org.springframework.ws.server.endpoint.mapping. PayloadRootAnnotationMethodEndpointMapping” /> |
Page Visitors: 10556

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023