由于项目要用到webservice,我自己用springboot来整合试了下,遂有了下述的记录。
1.什么是webservice
简单来说,webservice
就是远程调用技术,也叫XML Web Service
. WebService
是一种可以接收从Internet
上其它系统中传递过来的请求,轻量级的独立的通讯技术。
XML:(Extensible Markup Language
)扩展型可标记语言。面向短期的临时数据处理、面向万维网络,是SOAP的基础。
SOAP:(Simple Object Access Protocol
)简单对象存取协议。是XML Web Service
的通信协议。当用户通过UDDI找到你的WSDL描述文档后,他通过可以SOAP调用你建立的Web服务中的一个或多个操作。SOAP是XML文档形式的调用方法的规范,它可以支持不同的底层接口,像HTTP(S)或者SMTP。
WSDL:(Web Services Description Language
) WSDL 文件是一个 XML 文档,用于说明一组 SOAP 消息以及如何交换这些消息。大多数情况下由软件自动生成和使用。
我们一般是在具体平台开发 webservice 接口,以及调用 webservice 接口,每种开发语言都有自己的 webservice 实现框架。比如 Java 就有 Apache Axis1、Apache Axis2、Codehaus XFire、Apache CXF、Apache Wink、Jboss RESTEasyd 等等。其中 Apache CXF 用的比较多,它也可以和 Spring Boot 整合。
2、集成webservice
1、新建一个springboot
项目,引入相关依赖:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.6</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.6</version> </dependency> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
2、服务端接口定义
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 @WebService (name = "ContentDeployResult" )public interface CDNResponse { @WebMethod CommonXmlResponse ContentDeployResult (@WebParam(name = "CMSID" , targetNamespace = "iptv" ) String CMSID, @WebParam (name = "SOPID" , targetNamespace = "iptv" ) String SOPID, @WebParam (name = "CorrelateID" , targetNamespace = "iptv" ) String CorrelateID, @WebParam (name = "ResultCode" , targetNamespace = "iptv" ) Integer ResultCode, @WebParam (name = "ErrorDescription" , targetNamespace = "iptv" ) String ErrorDescription, @WebParam (name = "ResultFileURL" , targetNamespace = "iptv" ) String ResultFileURL, @WebParam (name = "XMLURLQC" , targetNamespace = "iptv" ) String XMLURLQC, @WebParam (name = "Encrypt" , targetNamespace = "iptv" ) String Encrypt) ; }
3、服务端接口的实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 @Slf 4jpublic class CDNResponseImpl implements CDNResponse { @Override public CommonXmlResponse ContentDeployResult (String CMSID, String SOPID, String CorrelateID, Integer ResultCode, String ErrorDescription, String ResultFileURL, String XMLURLQC, String Encrypt) { return null ; } }
4、cxf 服务配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 package com.zhjt.cms.config;import com.zhjt.cms.intf.webservice.cdn.CDNResponse;import org.apache.cxf.Bus;import org.apache.cxf.bus.spring.SpringBus;import org.apache.cxf.jaxws.EndpointImpl;import org.apache.cxf.transport.servlet.CXFServlet;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.web.servlet.ServletRegistrationBean;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import javax.xml.ws.Endpoint;@Configuration public class CxfConfig { @Autowired private CDNResponse cdnResponse; @Bean (name = "cxfServlet" ) public ServletRegistrationBean<CXFServlet> cxfServlet () { return new ServletRegistrationBean<>(new CXFServlet(),"/*" ); } @Bean (name = Bus.DEFAULT_BUS_ID) public SpringBus springBus () { return new SpringBus(); } @Bean (name = "ContentDeployResult" ) public Endpoint sweptPayEndpoint () { EndpointImpl endpoint = new EndpointImpl(springBus(), cdnResponse); endpoint.publish("/ContentDeployResult" ); return endpoint; } }
5、启动项目,用soapui来模拟请求即可。