使用CXF将超时设置为JAX-RS客户端

时间:2018-03-23 11:54:24

标签: timeout jax-rs cxf

我需要为以下客户端或配置设置自定义超时:

import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.client.ClientConfiguration;

Client client = WebClient.client(api);
ClientConfiguration config = WebClient.getConfig(client);

我阅读了this,尤其是this,但我无法在我的对象中找到这些建议的属性或方法。我宁愿不改变对象类型。

2 个答案:

答案 0 :(得分:0)

import org.apache.cxf.transport.http.HTTPConduit;

import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

客户端客户端= WebClient.client(api);

HTTPConduit http =(HTTPConduit)client.getConduit();

HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(0);

httpClientPolicy.setReceiveTimeout(0);

http.setClient(httpClientPolicy);

答案 1 :(得分:0)

我需要将其添加到我之前发布的代码中:

HTTPConduit conduit = config.getHttpConduit();
conduit.getClient().setReceiveTimeout(150000);
//conduit.getClient().setConnectionTimeout(120000);

它有效。我只需要设置接收超时,但连接超时设置也可以。