How To Produce Multiple SOAP WSDL documents for Different Services in Spring Boot
1 min readMay 30, 2020
Today i will show how you can create a different WSDL documents for services created for different purposes. In our example below, consider that you have several services used for Yahoo and Google. You want to create different WSDL documents for Yahoo and Google. For this, the code will be as follows.
import java.util.Properties;import org.springframework.boot.web.servlet.ServletRegistrationBean;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.core.io.ClassPathResource;import org.springframework.ws.config.annotation.EnableWs;import org.springframework.ws.config.annotation.WsConfigurerAdapter;import org.springframework.ws.soap.server.endpoint.SoapFaultDefinition;import org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver;import org.springframework.ws.transport.http.MessageDispatcherServlet;import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;import org.springframework.xml.xsd.SimpleXsdSchema;import org.springframework.xml.xsd.XsdSchema;/**** @author Celal KARTAL**/@EnableWs@Configurationpublic class SoapWebServiceConfig extends WsConfigurerAdapter {@Beanpublic ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {MessageDispatcherServlet servlet = new MessageDispatcherServlet();servlet.setApplicationContext(applicationContext);servlet.setTransformWsdlLocations(true);return new ServletRegistrationBean(servlet, “/servicesoap/*”);}@Bean(name = “googleWsdl”)public DefaultWsdl11Definition defaultWsdl11Definition() {DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();wsdl11Definition.setPortTypeName(“GooglePort”);wsdl11Definition.setLocationUri(“/servicesoap/google”);wsdl11Definition.setTargetNamespace(“http://www.celalkartal.com/playerpool/ soap/schema/google”);wsdl11Definition.setSchema(googleSchema());return wsdl11Definition;}@Bean(name = “googleSchema”)public XsdSchema googleSchema() {return new SimpleXsdSchema(new ClassPathResource(“xsd/GoogleSchema.xsd”));}@Bean(name = “Yahoo”)public DefaultWsdl11Definition yahooWsdl11Definition() {DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();wsdl11Definition.setPortTypeName(“YahooPort”);wsdl11Definition.setLocationUri(“/servicesoap/yahoo”);wsdl11Definition.setTargetNamespace(“http://www.celalkartal.com/playerpool/ soap/schema/yahoo”);wsdl11Definition.setSchema(yahooSchema());return wsdl11Definition;}@Bean(name = “yahooSchema”)public XsdSchema yahooSchema() {return new SimpleXsdSchema(new ClassPathResource(“xsd/YahooSchema.xsd”));}}
How To Find SOAP WSDL documents in Spring Boot
Your WSDL document url will be contextPath+setLocationUri value+”/”+bean name+”.wsdl”
Example google wsdl in our application;
- contextPath = http://www.celalkartal.com/playerpool
- setLocationUri value =/servicesoap/google
wsdl11Definition.setLocationUri(“/servicesoap/google”);
- Bean name=googleWsdl
@Bean(name = “googleWsdl”)
RESULT;
WSDL document url address is
http://www.celalkartal.com/playerpool/servicesoap/google/googleWsdl.wsdl
- Good lucks…