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

webService客户端工具类

发布时间:2020-12-16 23:47:05 所属栏目:安全 来源:网络整理
导读:package com.dg11185.zhjy.commonUtils;import javax.xml.namespace.QName;import org.apache.axis2.AxisFault;import org.apache.axis2.addressing.EndpointReference;import org.apache.axis2.client.Options;import org.apache.axis2.rpc.client.RPCServi
package com.dg11185.zhjy.commonUtils;


import javax.xml.namespace.QName;


import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.log4j.Logger;


/*******************************************************************************
 * web Service 客户端工具类
 * 
 ******************************************************************************/
public class WebServiceClient {

	private static final Logger log = Logger.getLogger(WebServiceClient.class);


	
	/**
	 * WebService客户端请求
	 * 
	 * @param wsURL
	 * @param nameSpace
	 * @param mehtod
	 * @param xml
	 ***/
	public static String findWebSerivceResultAsString(String wsURL,String nameSpace,String method,String xml){
		log.info("-------------findWebSerivceResultAsString-->method:"+method+",URL:"+wsURL);
		log.info("-------------findWebSerivceResultAsString-->xml:"+xml);
		return findWebSerivceResultAsString(wsURL,nameSpace,method,new Object[]{xml});
	}
	
	/**
	 * WebService客户端请求
	 * 
	 * @param wsURL
	 * @param nameSpace
	 * @param mehtod
	 * @param args
	 ***/
	public static String findWebSerivceResultAsString(String wsURL,Object[] args) {
		long startTime = System.currentTimeMillis();
		try {
			RPCServiceClient client = new RPCServiceClient();
			Options options = client.getOptions();
			// 设置调用WebService的URL
			EndpointReference epf = new EndpointReference(wsURL);
			//设置超时
			options.setTimeOutInMilliSeconds(Long.parseLong("1000*8"));
			options.setTo(epf);
			//查看wsdl的空间名targetNamespace
			QName qname = new QName(nameSpace,method);
			Object[] result = client.invokeBlocking(qname,args,new Class[] { String.class });
			if (null != result && result.length > 0) {
				String rs = (String) result[0];
				log.info("---------------->result:"+rs);
				return rs;
			}
		} catch (AxisFault e) {
			e.printStackTrace();
			log.error("--------------Exception-->msg:"+e.getMessage());
		}finally{
			log.info("--------------useTimes:"+(System.currentTimeMillis()-startTime));
		}
		return null;
	}
}

(编辑:李大同)

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

    推荐文章
      热点阅读