By Alx: June 2019
Soap with Spring boot - WSDL First
Goal
In this tutorial we want to show how to build a saop web serivce with spring boot. Spring boot uses Spring-WS, which allows only contract-first. Hence we need to start from a contract definition, either from axml schema (xsd)
or from WSDL
. We will flow the contract-first with wsdl approach
Used technologies
JDK 1.8Maven 3.2
WSDL First
The wsdl document contains the five standard elements: types, message, portType, binding and service.
The wsdl provides 3 operations: deleteTutorial, updateTutorial and getTutorials
Maven file
The only used dependency isspring-boot-starter-web-services
, it includes the needed dependencies for using Spring-WS
Maven plugin
maven-jaxb2-plugin
for generating Java sources from WSDL
schemaDirectory
: Directory where WSDL file can be found.schemaIncludes
: Here we can specify which file should be used. In our case a WSDL file- generateDirectory - Target directory for the generated code, In our case is unspecified, so the default generateDirectory will be used
target/generated-sources/xjc
- generatePackage is not set, consequently the package name will be derived from the wsdl. Exactly from targetNamespace
Let's generate code
Implementing the endpoint
A simple implemenation with dummy dataConfiguration
Notes:
@EnableWs
: Provides spring web service configuration- We define DefaultWsdl11Definition with
@Bean(name = "tutorialService")
. tutorialService will be the name of the WSDL in the URLwsdl11Definition.setWsdl
, spicify the localtion of the wsdl
- MessageDispatcherServlet will be used to handle the http requests
- Setting *ApplicationContext* is required
- The
ServletRegistrationBean
maps all the incoming requests with URI/wsdlfirst/*
to the servlet
- The url of the wsdl will be: http://localhost:8080/wsdlfirst/tutorialService.wsdl