Another solution to make this work:
client.getContext().getParameters().add(HttpMethodParams.RETRY_HANDLER,
"CustomHttpClientConverter");
with CustomHttpClientConverter being:
class CustomHttpClientConverter extends HttpClientConverter {
public CustomHttpClientConverter(Context context) {
super(context);
}
@Override public HttpClientCall toSpecific(HttpClientHelper client, Request
request) {
HttpClientCall clientCall = super.toSpecific(client, request);
if (clientCall instanceof HttpMethodCall) {
HttpMethodCall httpMethodCall = (HttpMethodCall) clientCall;
httpMethodCall.getHttpMethod().getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new CustomRetryHandler());
}
return clientCall;
}
}
I could use either of the two implementations. However, from a compatibility
perspective moving forward with versions of the Rest Framework, I am leaning
toward the above solution. Any suggestions with a different solution or
preferred direction would be highly appreciated.
Thanks,
Sanjay
----------------------------------------
> From: [EMAIL PROTECTED]
> To: [email protected]
> Date: Tue, 24 Jun 2008 18:17:50 +0000
> Subject: RE: Setting HttpClient IOException Retry
>
>
> I have a solution that sort of works but I am not sure that is the best way
> of accomplishing this. Hoping this to be a simple work around until the issue
> 356 is resolved. Not very clean and would like any other suggestions if
> possible:
>
> A Custom Engine:
> public class CustomEngine extends com.noelios.restlet.Engine {
>
> public CustomEngine() {
> super();
> }
>
> /**
> * If the Helper is an instance of HttpClientHelper, then override
> * to provide our custom helper. Otherwise, return the constructed helper.
> *
> * @return a Helper
> */
> @Override public Helper createHelper(Client client) {
>
> Helper helper = super.createHelper(client);
> if (helper instanceof HttpClientHelper) {
>
> // override to provide Custom Helper
> return new ExtendedHttpClientHelper(client);
> }
>
> return helper;
> }
> }
>
> // A Custom Helper
> public class ExtendedHttpClientHelper extends HttpClientHelper {
>
> public ExtendedHttpClientHelper(Client client) {
> super(client);
> }
>
> /**
> * Populate Created Request with CustomRetryHandler
> */
> @Override public HttpClientCall create(Request request) {
> HttpMethodCall httpMethodCall = (HttpMethodCall) super.create(request);
>
>
> httpMethodCall.getHttpMethod().getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
> new CustomRetryHandler());
>
> return httpMethodCall;
> }
> }
>
> public class CustomRetryHandler implements HttpMethodRetryHandler {
> private int retryCount;
>
> private static int MAX_TRIES = 2;
>
> public boolean retryMethod(HttpMethod arg0, IOException arg1, int arg2) {
>
> if (retryCount < MAX_TRIES) {
> retryCount++;
> return true;
> }
>
> return false;
> }
> }
>
> An then in my code, I setup the custom engine using:
>
> org.restlet.util.Engine.setInstance(new CustomEngine());
>
> Any suggestions for Betterment would be greately appreciated.
> ----------------------------------------
>> From: [EMAIL PROTECTED]
>> To: [email protected]
>> Date: Tue, 24 Jun 2008 16:47:27 +0000
>> Subject: RE: Setting HttpClient IOException Retry
>>
>>
>> Additionally, I believe there is an open issue related to this
>> configuration, http://restlet.tigris.org/issues/show_bug.cgi?id=356
>>
>> Any suggestions to how this parameter might be easily configured while the
>> issue is addressed would be welcomed.
>>
>> Thanks again,
>> Sanjay
>> ----------------------------------------
>>> From: [EMAIL PROTECTED]
>>> To: [email protected]
>>> Date: Tue, 24 Jun 2008 16:18:20 +0000
>>> Subject: Setting HttpClient IOException Retry
>>>
>>>
>>> Hi,
>>>
>>> I am hoping to be able to configure the org.apache.commons.HttpClient's
>>> method retry handler to change the max number of times the HttpClient will
>>> attempt to retry connecting when there is an IOException.The Restlet
>>> HttpClientHelper, I believe does not support this configuration to the
>>> underlying HttpClient. Any suggestions on the best way to set the Retry
>>> Handler without explicit casting of Helper and getting the HttpClient there
>>> in?
>>>
>>> Additionally, any suggestions on how to simulate an IOException from a
>>> Restlet so that the retry can be validated would be appreciated. Is there a
>>> Status that I can set that will result in an IOException in the HttpClient?
>>>
>>> component.getDefaultHost().attach(new Restlet(component.getContext()){
>>> @Override public void handle(Request request, Response response){
>>>
>>> response.setEntity(new StringRepresentation("Hello World"));
>>>
>>> }
>>> });
>>>
>>> Thanks much.
>>> Sanjay
>>> _________________________________________________________________
>>> Need to know now? Get instant answers with Windows Live Messenger.
>>> http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008
>>
>> _________________________________________________________________
>> The i’m Talkathon starts 6/24/08. For now, give amongst yourselves.
>> http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst
>
> _________________________________________________________________
> Introducing Live Search cashback . It's search that pays you back!
> http://search.live.com/cashback/?&pkw=form=MIJAAF/publ=HMTGL/crea=introsrchcashback
_________________________________________________________________
Need to know now? Get instant answers with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008