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

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

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

  • 相关阅读:
    spring security使用数据库管理用户权限
    ubuntu安装配置jdk tomcat mysql ...
    64位虚拟机安装64位ubuntu出现问题
    maven pom文件结构详解
    Maven3下的java web项目
    数据库分页和使用jstl标签替换分页的jsp代码
    servlet生命周期
    图片校验码的生成
    HttpSessionListener和HttpSessionBindingListener监听session的销毁
    perl 处理特殊字符
  • 原文地址:https://www.cnblogs.com/junwangzhe/p/7832774.html
Copyright © 2011-2022 走看看