1

In Jaxrs (WebClient for instance) we can set a connect timeout and a read timeout.

    ClientConfiguration c = WebClient.getConfig(client);
    HTTPConduit http = c.getHttpConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(timeout);
    httpClientPolicy.setReceiveTimeout(timeout);
    httpClientPolicy.setAllowChunking(false);
    http.setClient(httpClientPolicy);

I would like to set a timeout that includes both, I don't really care how much time is spent in connecting or in receiving, my requirement is to get a response in X seconds or just discard the search.

cocorossello
  • 1,289
  • 1
  • 17
  • 30

1 Answers1

1

There is no way with CXF to set a maximum timeout for a request that consider both connection and receive durations. The maximum timeout for a request will be:

maximum_timeout = connection_timeout + receive_timeout

See this similar question for Apache HTTP client. The workaround could be to set a timer in a separate Thread to abort the connection when the desired maximum timeout expires

Community
  • 1
  • 1
pedrofb
  • 37,271
  • 5
  • 94
  • 142
  • Maybe via an interceptor?, but I don't know if it's doable – cocorossello Feb 20 '17 at 11:25
  • 1
    I have reviewed `WebClient` javadoc and it is not possible to abort a current request, so it it not possible to use an interceptor because it will be executed in the same thread that the main request (and the main thread it is blocked until response/timout). You would need to create an additional monitoring thread with a timeout and work asynchronously, in both cases: timeout or correct response. Consider whether it's worth... – pedrofb Feb 20 '17 at 12:56