I want to make a SpringBoot Application in Java with the following Soap Web-Service:
@WebService
public class HelloWorld
{
@WebMethod
public String sayHello(String name)
{
return "Hello world, " + name;
}
}
I want to get the WSDL... I think I have to create endpoints or mapping the service? How can I do that?
Without spring-boot it works, because the file in the WEB-INF folder with the code:
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint name='HelloWorld' implementation='web.service.soap.HelloWorld' url-pattern='/HelloWorld'/>
</endpoints>
and
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Steps to Consume a SOAP service :Create spring boot project and Get the WSDL from the provider . Convert the WSDL to Stub. Understand the request ,response and the types ,operations using any tool like SOAP UI. Form the request object by mapping data and call the soap uri with marshal the java objects as XML.
Add spring-boot-starter-ws and org.apache.cxf cxf-bundle dependency to your project.
And create a configuration file to expose your web services. Example of such config:
@Configuration
@EnableWs
public class WebServicesConfig {
@Autowired
private HelloWorld helloWorld; // your web service component
@Bean
public ServletRegistrationBean wsDispatcherServlet() {
CXFServlet cxfServlet = new CXFServlet();
return new ServletRegistrationBean(cxfServlet, "/services/*");
}
@Bean(name="cxf")
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public Endpoint helloWorldEndpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), helloWorld);
endpoint.publish("helloWorld");
return endpoint;
}
}
To access your wsdl: http://localhost:8080/services/helloWorld?wsdl (path may be different)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With