The HTTP commons client 4.12 tutorial section on exception handling clearly shows that one should be able to set a request retry handler by doing the following…
httpclient.setHttpRequestRetryHandler(myRetryHandler);
in eclipse I tried that and it reports HttpClient has no such method. It suggests i cast the client to AbstractHttpClient then call .setHttpRequestRetryHandler like so:
((AbstractHttpClient) httpclient).setHttpRequestRetryHandler(myRetryHandler);
then my code works, but this discrepancy between documentation and API makes me wonder if I’m doing something I shouldn’t.
Is the documentation wrong or is it me?
You’re totally correct. The documentation uses a concrete
DefaultHttpClient(which is a subclass ofAbstractHttpClientand so has thesetHttpRequestRetryHandler()method.As you are doing the right thing and programming to the
HttpClientinterface (which sadly doesn’t expose that method), you have to do that nasty cast.It looks like the Apache team have decided to keep the
HttpClientinterface super-clean, at the expense of client code 🙁