本文主要是介绍一、使用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看得懂,wsimport是JDK自带的,可以根据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: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的服务端和客户端的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!