我需要为以下客户端或配置设置自定义超时:
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);
我读了这个,尤其是这个,但我在我的对象中找不到那些建议的属性或方法。我宁愿不更改对象类型。
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(;
我需要将其添加到我之前发布的代码中:
HTTPConduit conduit = config.getHttpConduit();
conduit.getClient().setReceiveTimeout(150000);
//conduit.getClient().setConnectionTimeout(120000);
它奏效了。我只需要设置接收超时,但连接超时设置也有效。