如何使用Spring WS创建基于WSDL的独立Web服务?

时间:2015-05-07 15:05:18

标签: web-services soap wsdl spring-ws

请帮助我使用Spring WS和现有的wsdl在本地计算机上运行独立的Web服务。 我是Spring WS的新手。有我的代码: 包com.mayacomp.ws;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

网络服务终点:

package com.mayacomp.endpoint;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.mayacomp.pack.intRequest;
import com.mayacomp.pack.IntResponse;


@Endpoint
public class WsEndpoint {

    private static final String NAMESPACE_URI = "http://new.webservice.namespace";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "intRequest")
    @ResponsePayload
    public IntResponse getIntHist(@RequestPayload intRequest request) {
        try {
com.mayacomp.pack.IntResponse _return = new com.mayacomp.pack.IntResponse();
        /*a lot of setters for _return object*/
            return _return;
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

}

和webservie config:

package com.mayacomp.ws;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.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.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;

@EnableWs
@Configuration
@EnableAutoConfiguration
public class WebServiceConfig extends WsConfigurerAdapter {
      @Bean
      public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
      }

      @Bean(name = "MayaService")
      public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("MayaService.wsdl"));
        return wsdl11Definition;
      }
}

我的pom文件如下:

<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>


    <artifactId>maya-ws</artifactId>

    <dependencies>
        <!-- tag::springws[] -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-ws</artifactId>
            <version>1.2.3.RELEASE</version>
        </dependency>
    <!-- end::springws[] -->

        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我需要运行应用程序(我可以运行)并通过localhost:8080 / ws / MayaService等链接获取Web服务?wsdl 我会很高兴任何建议。

0 个答案:

没有答案