zoukankan      html  css  js  c++  java
  • 记一次webservice的超时时间设置

    一次项目组中需要控制超时时间,前期习惯用CXF实现,熟悉的才是最好的。所以这次依然想用CXF实现。

    实现的方式代码如下:

    static{
      String fvpWebserviceUrl = PropertyUtil.getConfig("fvpWebserviceUrl");
      JaxWsProxyFactoryBean cxfFty = new JaxWsProxyFactoryBean();
      cxfFty.setServiceClass(IWaybillQueryExtService.class);
      if(StringUtils.isNotEmpty(fvpWebserviceUrl)){
        cxfFty.setAddress(fvpWebserviceUrl);
        service = (IWaybillQueryExtService) cxfFty.create();
        setTimeoutTime(service);
      }else{
        logger.info("interface url"+fvpWebserviceUrl);
      }
    }

    /**
    * 设置web service 连接超时和读取超时
    * @param service
    */
    private static void setTimeoutTime(Object service){
      Client proxy = ClientProxy.getClient(service);
      HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
      HTTPClientPolicy policy = new HTTPClientPolicy();
      try{
        policy.setConnectionTimeout(Integer.parseInt(PropertyUtil.getConfig("connectionTimeout")));
        policy.setReceiveTimeout(Integer.parseInt(PropertyUtil.getConfig("receiveTimeout")));
      }catch(Exception e){
        policy.setConnectionTimeout(3000);
        policy.setReceiveTimeout(5000);
        logger.error("",e);
      }
      conduit.setClient(policy);
    }

    需要用到的jar包为:

    如果单独运行超时机制和接口查询都是没有问题的,但放入项目组中就不行,后来才知是和spring的一些jar包冲突了。

    CXF不行我就换了axis框架:通过下图中的jar包程序生成了AXIS客户端代码,在网上下载的axis2的框架生成的代码少文件,不知是否有用。单我是用下图中做的。

    运行命令:Java -Djava.ext.dirs=D:axis org.apache.axis.wsdl.WSDL2Java http://xxxxx.com/ibs/services/realtime/addressClassification?wsdl -p com.my.module.ams.webservice -o e:20150531

    生成如下客户端代码文件:

    设置超时的代码处理,超时机制就能实现了。:

  • 相关阅读:
    14-Reverse Integer
    13.Merge k Sorted Lists
    12-Add Digits
    11-String to Integer (atoi)
    10.Power of Two-Leetcode
    9. Delete Node in a Linked List
    使用Openmp并行化
    C++编译过程与内存空间
    C++栈溢出
    程序(进程)内存空间分布深入理解
  • 原文地址:https://www.cnblogs.com/junwangzhe/p/7832774.html
Copyright © 2011-2022 走看看