采用CXF 构建webservice

一般接口开发都会使用如 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 文件自动构建客服端,从而向服务器发消息



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值