How to use WSDL with spring-boot?

I have WSDL and schema files provided by the client. I need to create a Spring-boot SOAP web service with this WSDL file. I have google and all the examples that I can find, they automatically generate wsdl using spring. How can I use WSDL to create a SOAP service?

+12
soap spring-boot spring-ws
source share
6 answers

The following are general steps for using existing wsdl with Spring -Ws and Spring-boot.

Configuration class

@EnableWs @Configuration public class WebServiceConfig extends WsConfigurerAdapter { @Bean public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { MessageDispatcherServlet servlet = new MessageDispatcherServlet(); servlet.setApplicationContext(applicationContext); servlet.setTransformWsdlLocations(true); return new ServletRegistrationBean(servlet, "/ws/*"); } //http://localhost:8080/ws/services.wsdl --bean name is set to 'services' @Bean(name = "services") public Wsdl11Definition defaultWsdl11Definition() { SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); wsdl11Definition.setWsdl(new ClassPathResource("/schema/MyWsdl.wsdl")); //your wsdl location return wsdl11Definition; } } 
  1. In your pom.xml, use the jaxb2-maven-plugin plugin to generate classes from your wsdl.
  2. In Spring-WS, you need to write the endpoint yourself. No code generation for endpoints. It is easy to write. You can follow the guide / guide on the spring website.
+14
source share

There are several ways to present a web service, starting with a WSDL file and using Spring Boot. You usually generate your Java classes from the WSDL definition. There are a number of JAXB Maven plugins to help you with this.

Also, when using Spring Boot, make sure that you take advantage of the spring bootloaders to automatically manage the various required dependencies.

One approach is to use Spring Web Services in conjunction with the maven-jaxb2-plugin plugin. I created a walkthrough that explains how to do this using Spring-WS, starting with a consumer and provider WSDL file .

Another alternative is to use a framework like Apache CXF in combination with the cxf-codegen-plugin plugin. CXF also comes with its own CXF Spring Boot starter called cxf-spring-boot-starter-jaxws . To get started, I compiled an example that uses the CXF starter in conjunction with Spring Boot to create a web service starting with a WSDL file .

+6
source share

SOAP (originally Simple Object Access Protocol) is a protocol specification for exchanging structured information when implementing web services on computer networks. SOAP allows you to process processes running on disparate operating systems (such as Windows and Linux) using an extensible markup language (XML). SOAP can be used in conjunction with WSDL, which is standardized, which means that people who know the standard (WSDL) can learn from it what operations the web service offers and how data is exchanged. This knowledge can be used to create tools that generate safe types / type binding objects from a WSDL file. These generated classes (for creating RPC) can be used without the need for manual implementation of queries and coding / analysis of data exchanged.
Using maven-jaxb2-plugin , we can generate the required classes needed from wsdl.

  <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>${maven-jaxb2-plugin.version}</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory> <schemaIncludes> <include>*.wsdl</include> </schemaIncludes> </configuration> </plugin> 

Next, using the ServletRegistrationBean, we register the MessageDispatcherServlet using the Spring Boot. During this registration, the URI template for the servlet is set to / javainuse / ws / *. Using this path, the web container will display incoming HTTP requests in the MessageDispatcherServlet. DefaultWsdl11Definition provides standard WSDL 1.1 using the specified Hello World WSDL file. MessageDispatcherServlet also automatically detects any WsdlDefinition defined in the application context.

A detailed explanation along with the video tutorial is available here: Spring First example of a download contract and web services SOAP

+1
source share

The easiest way is to simply use cxf-spring-boot-starter incl. This is an addition to the Maven plugin , they will take care of generating basically everything you need from your wsdl and schema files . Here is a complete example: https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple .

Using the starter in your pom.xml , you just need to put the wsdl & schema files in src/main/resources and you basically did everything. Here is the complete pom.xml example:

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>de.codecentric.soap</groupId> <artifactId>cxf-boot-simple</artifactId> <version>2.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>cxf-boot-simple</name> <description>Demo project for using Spring Boot Starter CXF</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>cxf-spring-boot-starter</artifactId> <version>2.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>de.codecentric</groupId> <artifactId>cxf-spring-boot-starter-maven-plugin</artifactId> <version>2.0.0.RELEASE</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> 
0
source share

You can create the WebServiceConfiguration Java class in your packages.

 @EnableWs @Configuration public class WebServiceConfig extends WsConfigurerAdapter { @Bean public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { MessageDispatcherServlet servlet = new MessageDispatcherServlet(); servlet.setApplicationContext(applicationContext); servlet.setTransformWsdlLocations(true); return new ServletRegistrationBean(servlet, "/ProjectName/*"); } @Bean(name = "wsdlname") public DefaultWsdl11Definition defaultWsdl11Definition (XsdSchema cityRequestSchema) { DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); wsdl11Definition.setRequestSuffix("ByCountry"); wsdl11Definition.setResponseSuffix("City"); wsdl11Definition.setPortTypeName("Hotelport"); wsdl11Definition.setLocationUri("/ProjectName"); wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service"); wsdl11Definition.setSchema(cityRequestSchema); return wsdl11Definition; } @Bean public XsdSchema cityRequestSchema() { return new SimpleXsdSchema(new ClassPathResource("CityRequest.xsd")); } 

After running as a spring boot application ... then copy this url to your browser. http: // localhost: 8080 / ProjectName / wsdlname.wsdl

noted: localhost: 8080 replace with your tomcat port

0
source share

The easiest way is to simply use cxf-spring-boot-starter incl. This is an addition to the Maven plugin , they will take care of generating basically everything you need from your wsdl and schema files . Here is a complete example: https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple .

Using the starter in your pom.xml , you just need to put the wsdl & schema files in src/main/resources and you basically did everything. Here is the complete pom.xml example:

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>de.codecentric.soap</groupId> <artifactId>cxf-boot-simple</artifactId> <version>2.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>cxf-boot-simple</name> <description>Demo project for using Spring Boot Starter CXF</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>cxf-spring-boot-starter</artifactId> <version>2.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>de.codecentric</groupId> <artifactId>cxf-spring-boot-starter-maven-plugin</artifactId> <version>2.0.0.RELEASE</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> 
0
source share

All Articles