Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Soap Web-Service (Java) - code first?

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>
like image 430
CrisV Avatar asked Sep 08 '16 15:09

CrisV


People also ask

How do you call a SOAP web service from a spring boot?

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.


1 Answers

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)

like image 66
rhorvath Avatar answered Sep 22 '22 02:09

rhorvath