webservice axis2客户端调用设置超时时间

axis2版本 :1.6.2

 

import java.rmi.RemoteException;

import nc.pubitf.para.SysInitQuery;
import nc.vo.pub.BusinessException;

import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;
import org.tempuri.HQSWcfServiceCallHQSWcfServiceCallSoapStub;

import com.yonyou.yh.nhis.bd.util.SysConfigParamUtil;
import com.yonyouhealth.uaph.framework.comm.util.StringUtils;


public class ChinaShineUtils {

    private static HQSWcfServiceCallHQSWcfServiceCallSoapStub stub;
    private static HQSWcfServiceCallHQSWcfServiceCallSoapStub getServiceStub() throws AxisFault, BusinessException{
        try {
            stub = null==stub? new HQSWcfServiceCallHQSWcfServiceCallSoapStub() : stub;
            
            Options options = stub. _getServiceClient().getOptions();
            options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 2 * 1000);//设置服务端方法超时时间(单位是毫秒)
            options.setProperty(HTTPConstants.SO_TIMEOUT, 3 * 1000);//设置等待客户连接的超时时间(单位是毫秒)
            
            stub._getServiceClient().setOptions(options);//设置

            
        } catch (AxisFault e) {
            throw new AxisFault("接口调用超时,接口返回信息:"+ e.getMessage());
        }catch(Exception e){
            throw new BusinessException("接口调用失败,接口返回信息:"+ e.getMessage());
        }
        return stub;
    }
    
    private static HQSWcfServiceCallHQSWcfServiceCallSoapStub getServiceStub(String pk_group) throws AxisFault, BusinessException{
        try {
            if(StringUtils.hasText(pk_group)){
                String url = SysInitQuery.getParaString(pk_group, "NHISPV014");
                if(StringUtils.hasText(url) ){
                    stub = null==stub? new HQSWcfServiceCallHQSWcfServiceCallSoapStub(url) : stub;
                    
                    String conn_timeout_str = new SysConfigParamUtil().getPubSysInitByGroup(pk_group, "NHISPV022");
                    Integer connection_timeout = StringUtils.hasText(conn_timeout_str)? Integer.valueOf( conn_timeout_str) : 2000 ;
                    
                    String so_timeout_str = new SysConfigParamUtil().getPubSysInitByGroup(pk_group, "NHISPV023");
                    Integer so_timeout = StringUtils.hasText(so_timeout_str)?  Integer.valueOf(so_timeout_str) : 3000;
                    
                    Options options = stub._getServiceClient().getOptions();
                    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, connection_timeout);//设置服务端方法超时时间(单位是毫秒)
                    options.setProperty(HTTPConstants.SO_TIMEOUT, so_timeout);//等待客户连接的超时时间(单位是毫秒)
                    
                    stub._getServiceClient().setOptions(options);//设置

                }else{
                    stub = getServiceStub();
                }
            }else{
                stub = getServiceStub();
            }
        } catch (AxisFault e) {
            throw new AxisFault("接口调用超时,接口返回信息:"+ e.getMessage());
        }catch(Exception e){
            throw new BusinessException("接口调用失败,接口返回信息:"+ e.getMessage());
        }
        return stub;
    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值