加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

采用CXF 构建webservice

发布时间:2020-12-17 00:57:45 所属栏目:安全 来源:网络整理
导读:一般接口开发都会使用如 webservice,ftp,sftp 的方式实现,如java 程序访问.net 程序,就不的不涉及到soa 开发步骤: 1.下载cxf 相关jar 包 2.在spring context配置文件中引入以下cxf配置 import resource="classpath*:META-INF/cxf/cxf.xml" /import resour

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读