微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webService客户端工具类

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;
	}
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐