How to set timeout to JAX-RS client with CXF

NikosDim picture NikosDim · Feb 4, 2015 · Viewed 26.5k times · Source

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 the default timeout values of the client.

A simple client:

Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/MyApp");
target = target.path("jsp/Test.jsp");
Response response = target.request().get();

I have read that there are two timeout properties in CXF called ReceiveTimeout and ConnectionTimeout but I have not managed to find a way to set them in my client.

I have tried client.property("ReceiveTimeout", 5000); but it doesn't work.

I have seen examples of using an xml configuration file to configure the client but I prefer not to take that path if it is possible.

Any ideas?

Answer

laughing buddha picture laughing buddha · May 6, 2017
HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
conduit.getClient().setConnectionTimeout(1000 * 3);
conduit.getClient().setReceiveTimeout(1000 * 3);