By Marone: July 2019 | last update: July 2020

Soap with Spring boot - Schema first

Goal

In the previous article we saw how to use Spring boot contract-first approach starting from a wsdl file. We will flow the contract-first with schema approach. Just keep in mind Spring boot is using Spring-WS under the hood

Used technologies

JDK 1.8
Maven 3.2

XSD First


Info! According to Spring WS documentation the Resquest/Response/Fault elements should be marked with suffix. We are using the default ones:
updateTutorialRequest
updateTutorialResponse
tutorialFault

Maven dependencies


The spring-boot-starter-web-services dependency includes the needed dependencies for using Spring-WS
WSDL4J The Web Services Description Language for Java Toolkit allows the creation, representation, and manipulation of WSDL documents.

In Order to use schema elements in Endpoint class we need at first to generate Java classes from the xsd file The jaxb2-maven-plugin will be used to handle the code generation.

     The Plugin looks in the path defined in <source> to find any XSD file
     The<outputDirectory> is the location where the java classes will be generated

Generate code

The generated java classes are under /src and looks like:

xml schema

Configuration

Notes:



Implementing the Endpoint

After expsoing the wsdl now we need some implementation to handle incoming XML messages, in order to do that we need a class with one or more handling methods. In this tutorial we will implement only two methods Details:
@Endpoint, this class becomes web service Endpoint
The method annotated with @PayloadRoot becomes an Endpoint method. Depending on the attributes namespace and localPart Spring-WS will forward the incoming request to a appropriate method
@RequestPayload and @ResponsePayload are for mapping request and response values


Run the SOAP Web Service



Big picture

big picture

Test with soapUI

According to application.properties the application is running on port 8090
The WSDL is now located at http://localhost:8090/ws/tutorials.wsdl and the endpoint URL is http://localhost:8090/ws soapUI

References