Jersey 2.7 - setting retry handler

我与影子孤独终老i 提交于 2019-12-21 05:02:31

问题


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?

来源:https://stackoverflow.com/questions/23291666/jersey-2-7-setting-retry-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!