5

I would like to set a retry handler for Jersey client utilizing ApacheConnector. I wish to do it, because I want it to retry on timeout (my HAProxy will switch it to another server). I have no clue how to do this in Jersey 2.7.

Example code:

public static void Example() {

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.connectorProvider(new ApacheConnectorProvider());
    clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager());

    RequestConfig reqConfig = RequestConfig.custom().build(); 
    clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, reqConfig);

    Client client = ClientBuilder.newClient(clientConfig);
    WebTarget apiTarget = client.target("http://127.0.0.1/rest");
    System.out.println(apiTarget.path(ApiConstant.PING)
            .path(ApiConstant.PING1)
            .request(MediaType.TEXT_PLAIN)
            .get(String.class));
}

How, using this code, I can set a retry handler to send request again if server responds with an error? Is it possible?

Michał Kowalczyk
  • 358
  • 1
  • 5
  • 21
  • 1
    I guess you haven't had any luck with this? It's something I need to look at myself at some point. I can only think of 2 ways: implement a ClientInterceptor to do the work, or somehow hook into the HttpClient and set a retryHandler, but I don't think Jersey expose the HttpClientBuilder. Will come back once I've worked something out. – Will Apr 30 '14 at 09:17
  • It's really old question but any news here? @Will – Klapsa2503 Nov 30 '22 at 10:54

0 Answers0