How to set timeout to JAX-RS client with CXF

后端 未结 3 1136
死守一世寂寞
死守一世寂寞 2021-01-08 00:26

I am working on a Rest Client and I am using CXF with JAX-RS.

The problem that I have is that I cannot find any way to override th

相关标签:
3条回答
  • 2021-01-08 00:56

    You can try something like this:

    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(30000);
    http.setClient(httpClientPolicy);
    

    see http://cxf.apache.org/javadoc/latest/org/apache/cxf/transports/http/configuration/HTTPClientPolicy.html

    0 讨论(0)
  • 2021-01-08 01:11

    You can find the correct properties in org.apache.cxf.jaxrs.client.spec.ClientImpl: "http.connection.timeout" and "http.receive.timeout"

    So just use them as property when building the client:

    ClientBuilder.newClient().property("http.receive.timeout", 1000);
    

    With JAX-RS 2.1 (supported from CXF 3.2) you can use these standard methods in ClientBuilder:

    connectTimeout(long timeout, TimeUnit unit);
    readTimeout(long timeout, TimeUnit unit);
    

    See also: https://github.com/eclipse-ee4j/jaxrs-api/issues/467

    0 讨论(0)
  • 2021-01-08 01:16
    HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
    conduit.getClient().setConnectionTimeout(1000 * 3);
    conduit.getClient().setReceiveTimeout(1000 * 3);
    
    0 讨论(0)
提交回复
热议问题