`

WebService CXF 如何设置 timeout

阅读更多

由于用CXF构建的webservice使用的是spring配置方式很简单 
但是由于客户端使用jaxws:client方式请求的,这个请求方式不能直接配置timeout的
用spring配置jaxws客户端请求的的配置:

 

<jaxws:client id="" serviceClass="" address="" />

 

如果使用这种方式配置直接有timeout属性 

 

<http-conf:conduit>
         <http-conf:client ConnectionTimeout="30000"/>
</http-conf:conduit>

 

那我们继续使用jaxws:client配置方式如何设置timeout呢? 
只需在我们调用web service的代码之处加上: 

 

        long timeout = 10000L;
	Client client = ClientProxy.getClient(对应spring配置文件里你配置的clientid);
        if (client != null) {
            HTTPConduit conduit = (HTTPConduit) client.getConduit();
            HTTPClientPolicy policy = new HTTPClientPolicy();
            policy.setConnectionTimeout(timeout);
            policy.setReceiveTimeout(timeout);
            conduit.setClient(policy);
        }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics