一、使用cxf的JaxWsServerFactoryBean创建webservice的服务端和客户端

本文主要是介绍一、使用cxf的JaxWsServerFactoryBean创建webservice的服务端和客户端,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

A。创建服务端

配置文件:


import com.enn.cn.util.PropertiesUtil;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;/*** Created by Administrator on 2017/10/30.*/
public class ExecServer {public static void main(String[] args) {try {PropertiesUtil util=new PropertiesUtil("/config.properties");JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();bean.setAddress(util.getProperty("deployAddress"));bean.setServiceClass(GetHbaseDate.class);bean.setServiceBean(new GetHbaseDateImpl());bean.create();System.err.println("服务启动成功");
//            gethbaseall("2011",1476054000000L,1509325844000L);} catch (Exception e) {e.printStackTrace();}}
}
接口类:
import javax.jws.WebService;/*** Created by Administrator on 2017/10/30.*/
@WebService
public interface GetHbaseDate {String GetPipeposition(String userid,long startStr, long endStr);
}

实现类:

import com.enn.cn.trail.MongPosition;
import com.enn.cn.util.CommonContent;
import com.enn.cn.util.HBaseUtil;
import com.enn.cn.util.KerberosUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;/*** Created by Administrator on 2017/10/30.*/
public class GetHbaseDateImpl implements GetHbaseDate {@Overridepublic String GetPipeposition(String userid, long startStr, long endStr) {
          
System.out.println(
userid
);
}

客户端生成,生产完之后删除.class文件,拷贝.java文件到指定目录:

——你看不懂 ,JDK看得懂,wsimportJDK自带的,可以根据WSDL文档生成客户端调用代码的工具。无论服务器端WebService使用什么语言编写的,豆浆在客户端生成Java代码。所以服务器用什么语言编写的并不重要。

wsimport.exe(jdk/bin文件夹中)命令参数熟知:

    -d:生成class文件。默认参数。

    -s:生成Java文件

   -p:自定义包结构

 

生成文件到指定盘:

WSDL文件内容:
 
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://interfaces.cn.enn.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="GetHbaseDateService" targetNamespace="http://interfaces.cn.enn.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://interfaces.cn.enn.com/" elementFormDefault="unqualified" targetNamespace="http://interfaces.cn.enn.com/" version="1.0">
<xs:element name="GetPipeposition" type="tns:GetPipeposition"/>
<xs:element name="GetPipepositionResponse" type="tns:GetPipepositionResponse"/>
<xs:complexType name="GetPipeposition">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element name="arg1" type="xs:long"/>
<xs:element name="arg2" type="xs:long"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GetPipepositionResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetPipeposition">
<wsdl:part element="tns:GetPipeposition" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="GetPipepositionResponse">
<wsdl:part element="tns:GetPipepositionResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="GetHbaseDate">
<wsdl:operation name="GetPipeposition">
<wsdl:input message="tns:GetPipeposition" name="GetPipeposition"></wsdl:input>
<wsdl:output message="tns:GetPipepositionResponse" name="GetPipepositionResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GetHbaseDateServiceSoapBinding" type="tns:GetHbaseDate">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetPipeposition">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="GetPipeposition">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetPipepositionResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GetHbaseDateService">
<wsdl:port binding="tns:GetHbaseDateServiceSoapBinding" name="GetHbaseDatePort">
<soap:address location="http://10.11.85.137:8080/getpipepositions"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
客户端调用服务端:
public class Client {public static void main(String[] args) {/* URL wsdlUrl = new URL("http://localhost:8080/getpipepositions?wsdl");
            Service s = Service.create(wsdlUrl, new QName("http://interfaces.cn.enn.com/","GetHbaseDateService"));
            GetHbaseDate hs = s.getPort(new QName("http://interfaces.cn.enn.com/","GetHbaseDatePort"), GetHbaseDate.class);
            String res=hs.GetPipeposition("2011",1476054000000L,1509325844000L);
            System.out.println(res);*/
            GetHbaseDateService sd=new GetHbaseDateService();
            com.enn.cn.interfaces.client.GetHbaseDate fs=sd.getGetHbaseDatePort();
            String res=fs.getPipeposition("2011",1476054000000L,1509325844000L);
        System.out.println(res);
    }
}


这篇关于一、使用cxf的JaxWsServerFactoryBean创建webservice的服务端和客户端的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1083728

相关文章

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断

C++中assign函数的使用

《C++中assign函数的使用》在C++标准模板库中,std::list等容器都提供了assign成员函数,它比操作符更灵活,支持多种初始化方式,下面就来介绍一下assign的用法,具有一定的参考价... 目录​1.assign的基本功能​​语法​2. 具体用法示例​​​(1) 填充n个相同值​​(2)

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

IntelliJ IDEA2025创建SpringBoot项目的实现步骤

《IntelliJIDEA2025创建SpringBoot项目的实现步骤》本文主要介绍了IntelliJIDEA2025创建SpringBoot项目的实现步骤,文中通过示例代码介绍的非常详细,对大家... 目录一、创建 Spring Boot 项目1. 新建项目2. 基础配置3. 选择依赖4. 生成项目5.

Linux线程之线程的创建、属性、回收、退出、取消方式

《Linux线程之线程的创建、属性、回收、退出、取消方式》文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthr... 目录1. 线程号2. 线程的创建3. 线程属性4. 线程的回收5. 线程的退出6. 线程的取消7.

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

深入理解Go语言中二维切片的使用

《深入理解Go语言中二维切片的使用》本文深入讲解了Go语言中二维切片的概念与应用,用于表示矩阵、表格等二维数据结构,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录引言二维切片的基本概念定义创建二维切片二维切片的操作访问元素修改元素遍历二维切片二维切片的动态调整追加行动态

prometheus如何使用pushgateway监控网路丢包

《prometheus如何使用pushgateway监控网路丢包》:本文主要介绍prometheus如何使用pushgateway监控网路丢包问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录监控网路丢包脚本数据图表总结监控网路丢包脚本[root@gtcq-gt-monitor-prome

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数

创建Java keystore文件的完整指南及详细步骤

《创建Javakeystore文件的完整指南及详细步骤》本文详解Java中keystore的创建与配置,涵盖私钥管理、自签名与CA证书生成、SSL/TLS应用,强调安全存储及验证机制,确保通信加密和... 目录1. 秘密键(私钥)的理解与管理私钥的定义与重要性私钥的管理策略私钥的生成与存储2. 证书的创建与