Thanks Paul!
It worked like a charm. Here is my test, in case if you are interested.
public void testRetryHandler() {
HttpMethodRetryHandler retryhandler = new HttpMethodRetryHandler() {
public boolean retryMethod(
final HttpMethod method,
final IOException exception,
int executionCount) {
if (executionCount >= 5) {
// Do not retry if over max retry count
return false;
}
if (exception instanceof NoHttpResponseException) {
// Retry if the server dropped connection on us
return true;
}
if (!method.isRequestSent()) {
// Retry if the request has not been sent fully or
// if it's OK to retry methods that have been sent
return true;
}
// otherwise do not retry
return false;
}
};
ApacheHttpClient client = ApacheHttpClient.create();
client.addFilter(new com.sun.jersey.api.client.filter.LoggingFilter());
HttpClient hc = client.getClientHandler().getHttpClient();
hc.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
retryhandler);
/**
* HttpClient will automatically retry up to 5 times those methods that
* fail with a transport exception while the HTTP request is still being
* transmitted to the target server (i.e. the request has not been
fully transmitted to the server).
*/
WebResource r = client.resource("
http://localhost/resource");
try {
ClientResponse cr = r.get(ClientResponse.class);
} catch (ClientHandlerException e) {
assertTrue(e.getCause() instanceof ConnectException);
}
}
Best regards,
Arul
Paul Sandoz wrote:
>
> On Mar 16, 2009, at 4:42 PM, Arul Dhesiaseelan wrote:
>
>> Hi Paul,
>>
>> I meant I did not try testing that code. But, I will be testing this
>> shortly and will let you know.
>>
>
> OK.
>
>
>> Thanks for adding the getter to the client.
>>
>> Btw, do you know when we can expect the 1.0.3 release?
>>
>
> http://wikis.sun.com/display/Jersey/Schedule
>
> End of March/Start of April.
>
> Paul.
>
>> Best regards,
>> Arul
>>
>> Paul Sandoz wrote:
>>>
>>> On Mar 13, 2009, at 7:17 PM, Arul Dhesiaseelan wrote:
>>>
>>>> Redirects are set on the HttpMethodParams on the HttpClient. But,
>>>> HttpMethodRetryHandler interface uses Apache Client HttpMethod. So,
>>>> I don't this this would work:
>>>>
>>>
>>> Do you mean that the following will or will not work for you?
>>>
>>>
>>>> HttpClient client = new HttpClient(new
>>>> MultiThreadedHttpConnectionManager());
>>>> // set retry
>>>> client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>>>> retryhandler);
>>>> ApacheHttpClient client = new ApacheHttpClient(new
>>>> ApacheHttpClientHandler(client));
>>>>
>>>
>>> I have just added a method so you can do the following, which i
>>> think is a little cleaner:
>>>
>>> ApacheHttpClient client = ApacheHttpClient.create();
>>> HttpClient hc = client.getClientHandler().getHttpClient();
>>> hc.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>>> retryhandler);
>>>
>>> Paul.
>>>
>>>> Thanks!
>>>> Arul
>>>>
>>>> Paul Sandoz wrote:
>>>>>
>>>>> On Mar 13, 2009, at 5:57 PM, Arul Dhesiaseelan wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Is it possible to control the retry mechanism for the Client API
>>>>>> based on HttpClient? I think it defaults to 5.
>>>>>>
>>>>>
>>>>> No.
>>>>>
>>>>> I do not know where that property can be set, but if you can set
>>>>> it on HttpClient then you can do:
>>>>>
>>>>> HttpClient client = new HttpClient(new
>>>>> MultiThreadedHttpConnectionManager());
>>>>> // set retry
>>>>> ApacheHttpClient client = new ApacheHttpClient(new
>>>>> ApacheHttpClientHandler(client));
>>>>>
>>>>> Paul.
>>>>>
>>>>>> I do not see any config option available in ApacheHttpClientConfig.
>>>>>
>>>>>> -Arul
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>