Developing SOAP Web Services With Spring Boot - A Comprehensive Guide - by Extio Technology - Medium
Developing SOAP Web Services With Spring Boot - A Comprehensive Guide - by Extio Technology - Medium
Be part of a better internet. Get 20% off membership for a limited time
Introduction
In today’s interconnected world, web services play a crucial role in facilitating
communication between different applications. SOAP (Simple Object Access
Protocol) is a widely adopted protocol for creating web services. When it comes to
building SOAP web services in Java, Spring Boot provides an efficient and developer-
friendly framework. In this blog post, we will explore the fundamentals of
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 1/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
developing SOAP web services using Spring Boot and discuss the steps involved in
building a robust SOAP-based application.
Table of Contents:
1. Understanding SOAP Web Services
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 2/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
Example
Here’s an example of a simple Spring Boot SOAP web service implementation:
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 3/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/soap-web-service"
xmlns:tns="http://example.com/soap-web-service">
<message name="GetHelloRequest">
<part name="name" type="xsd:string"/>
</message>
<message name="GetHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="HelloPortType">
<operation name="getHello">
<input message="tns:GetHelloRequest"/>
<output message="tns:GetHelloResponse"/>
</operation>
</portType>
<binding name="HelloBinding" type="tns:HelloPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/so
<operation name="getHello">
<soap:operation soapAction="http://example.com/soap-web-service/get
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HelloService">
<port name="HelloPort" binding="tns:HelloBinding">
<soap:address location="http://localhost:8080/soap-api"/>
</port>
</service>
</definitions>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/soap-web-service"
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 4/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
targetNamespace="http://example.com/soap-web-service"
elementFormDefault="qualified">
<element name="GetHelloRequest">
<complexType>
<sequence>
<element name="name" type="string"/>
</sequence>
</complexType>
</element>
<element name="GetHelloResponse">
<complexType>
<sequence>
<element name="greeting" type="string"/>
</sequence>
</complexType>
</element>
</schema>
import org.example.soap_web_service.GetHelloRequest;
import org.example.soap_web_service.GetHelloResponse;
import org.springframework.stereotype.Component;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
@Endpoint
@Component
public class HelloEndpoint {
private static final String NAMESPACE_URI = "http://example.com/soap-web-se
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "GetHelloRequest")
@ResponsePayload
public GetHelloResponse getHello(@RequestPayload GetHelloRequest request) {
GetHelloResponse response = new GetHelloResponse();
String name = request.getName();
String greeting = "Hello, " + name + "!";
response.setGreeting(greeting);
return response;
}
} Open in app
Search
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 5/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdap
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public DefaultMethodEndpointAdapter defaultMethodEndpointAdapter() {
return new DefaultMethodEndpointAdapter();
}
@Bean
public MessageDispatcherServlet messageDispatcherServlet() {
return new MessageDispatcherServlet();
}
@Bean(name = "hello")
public Wsdl11Definition helloWsdl11Definition() {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(
wsdl11Definition.setPortTypeName("HelloPortType");
wsdl11Definition.setLocationUri("/soap-api");
wsdl11Definition.setTargetNamespace("http://example.com/soap-web-servic
wsdl11Definition.setSchema(helloSchema());
return wsdl11Definition;
}
@Bean
public SimpleXsdSchema helloSchema() {
return new SimpleXsdSchema(new ClassPathResource("hello.xsd"));
}
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 6/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
@SpringBootApplication
public class SoapWebServiceApplication {
public static void main(String[] args) {
SpringApplication.run(SoapWebServiceApplication.class, args);
}
}
Congratulations! You have successfully created a simple SOAP web service using
Spring Boot. The web service will be available at http://localhost:8080/soap-api and
can be accessed using the defined WSDL ( hello.wsdl ). You can test the web service
using SOAP clients or tools like SoapUI.
When you run the application, Spring Web Services uses the provided WSDL and XSD files
to generate the necessary Java classes for the request and response objects. The generated
classes will be located in the appropriate package based on the target namespace specified
in the WSDL.
In this case, the GetHelloResponse class will be automatically generated based on the
GetHelloResponse message defined in the WSDL ( hello.wsdl ) and the associated XML
schema definition ( hello.xsd ). You can use it in the HelloEndpoint class as shown in the
example.
Since the generation of these classes is handled by Spring Web Services at runtime, there’s
no explicit GetHelloResponse.java file in the example code. The class is generated
dynamically based on the WSDL and XSD files provided.
Conclusion
In this blog post, we explored the essentials of developing SOAP web services with
Spring Boot. We discussed the fundamental concepts, walked through the steps
involved in building a SOAP-based application, and covered important aspects such
as testing, error handling, security, and deployment. By leveraging the power of
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 7/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
Spring Boot and its ecosystem, developers can create robust and scalable SOAP web
services with ease.
WSDL Elements
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 8/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
WSDL Structure
Follow
Building the next generation virtualization layer for the cloud, virtual Kubernetes clusters.
Extio Technology
Introduction
Extio Technology
Extio Technology
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 10/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
Extio Technology
Aug 2, 2023 16
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 11/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
Jan 16 1K 14
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 12/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
Nithidol Vacharotayan
Apr 26 1 1
Lists
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 13/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
Mar 6 168
May 16 2K 83
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 14/16
7/2/24, 4:43 AM Developing SOAP Web Services with Spring Boot: A Comprehensive Guide | by Extio Technology | Medium
Oliver Foster
Jun 17 655 10
LORY
Explained in 3 mins.
May 12 3.8K 39
https://medium.com/@extio/developing-soap-web-services-with-spring-boot-a-comprehensive-guide-1d4f89bc3127 16/16