⼀次项⽬组中需要控制超时时间,前期习惯⽤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(\"\ }
conduit.setClient(policy);}
需要⽤到的jar包为:
如果单独运⾏超时机制和接⼝查询都是没有问题的,但放⼊项⽬组中就不⾏,后来才知是和spring的⼀些jar包冲突了。
CXF不⾏我就换了axis框架:通过下图中的jar包程序⽣成了AXIS客户端代码,在⽹上下载的axis2的框架⽣成的代码少⽂件,不知是否有⽤。单我是⽤下图中做的。⽣成如下客户端代码⽂件:
设置超时的代码处理,超时机制就能实现了。:
因篇幅问题不能全部显示,请点此查看更多更全内容