一般接口开发都会使用如 webservice,ftp,sftp 的方式实现,如java 程序访问.net 程序,就不的不涉及到soa
开发步骤:
1.下载cxf 相关jar 包
2.在spring context配置文件中引入以下cxf配置
<import resource="classpath*:meta-inf/cxf/cxf.xml" /> <import resource="classpath*:meta-inf/cxf/cxf-extension-soap.xml" /> <import resource="classpath*:meta-inf/cxf/cxf-servlet.xml" />
3.在web.xml中添加过滤器:
<servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/webservices/*</url-pattern> </servlet-mapping> 4.定义服务端WebService接口(下面直接使用了类定义,当然也可用接口定义) package com.jumbo.webservice.biaogan.service; import java.util.List; import javax.jws.WebParam; import javax.jws.WebService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import com.jumbo.manager.warehouse.WareHouseManagerProxy; import com.jumbo.mq.MarshallerUtil; ............................. /*** 使用@WebService将接口中的所有方法输出为Web Service. * 可用annotation对设置方法、参数和返回值在WSDL中的定义.下面是定义了两个带参数的方法 * Please modify this class to meet your needs This class is not complete */ @WebService(serviceName = "BgService",targetNamespace = "http://www.jumbomart.cn/webservice/") public class BGWebService { protected static final Logger log = LoggerFactory.getLogger(BGService.class); public String outboundToBz(@WebParam(name = "request") String xml) { } public String inboundToBz(@WebParam(name = "request") String xml) { } } 5.webservice 服务端配置 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> <bean id="jaxbBean" class="org.apache.cxf.jaxb.JAXBDataBinding" scope="prototype" /> <context:component-scan base-package="com.jumbo.webservice.biaogan.service"> <context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect" /> </context:component-scan> <bean id="bgService" class="com.webservice.service.BGWebService " /> <jaxws:endpoint id="bgAddress" implementor="#bgService" address="/bg" /> 最后可以通过http://localhost:8080/testws/services/bg?wsdl 查看自动生成的wsdl 文件 wsdl 文档太长,略 6.可以通过eclipse webservice 插件来通过wsdl 文件自动构建客服端,从而向服务器发消息
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。