Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use WSDL with spring-boot?

Tags:

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

like image 646
user3496599 Avatar asked Nov 18 '15 06:11

user3496599


2 Answers

Here are the common steps to follow to use your existing wsdl with Spring-Ws and Spring-boot.

Config 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 'jaxb2-maven-plugin' plugin to generate classes from your wsdl.
  2. In Spring-WS, you have to write endpoint yourself. No code generation for endpoints. Its easy to write. you can follow tutorial/guide on spring website.
like image 129
Ketan Avatar answered Sep 20 '22 13:09

Ketan


There are a number of options for exposing a web service starting from a WSDL file and using Spring Boot. You would typically generate your Java classes from the WSDL definition. There are a number of JAXB Maven plugins that will support you in doing this.

In addition when using Spring Boot make sure you take advantage of the spring-boot-starters in order to automatically manage the different needed dependencies.

One approach is to use Spring Web Services in combination with the maven-jaxb2-plugin plugin. I've created a step by step tutorial which explains how to do this using Spring-WS starting from a WSDL file for both consumer and provider.

Another alternative is to use a framework like Apache CXF in combination with the cxf-codegen-plugin plugin. CXF also comes with it's own CXF Spring Boot starter called cxf-spring-boot-starter-jaxws. In order to get you started I've compiled an example which uses the CXF starter in combination with Spring Boot to create a web service starting from a WSDL file.

like image 27
CodeNotFound Avatar answered Sep 19 '22 13:09

CodeNotFound