|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface HttpUnsuccessfulResponseHandler
Interface which handles abnormal HTTP responses (in other words not 2XX).
For example, this might be used to refresh an OAuth 2 token:
public static class RefreshTokenHandler implements HttpUnsuccessfulResponseHandler { public boolean handleResponse( HttpRequest request, HttpResponse response, boolean retrySupported) throws IOException { if (response.statusCode == 401) { refreshToken(); } return false; } }
Sample usage with a request factory:
public static HttpRequestFactory createRequestFactory(HttpTransport transport) { final RefreshTokenHandler handler = new RefreshTokenHandler(); return transport.createRequestFactory(new HttpRequestInitializer() { public void initialize(HttpRequest request) { request.unsuccessfulResponseHandler = handler; } }); }
If you have a custom unsuccessful response handler, use this more complex example:
public static HttpRequestFactory createRequestFactory(HttpTransport transport) { final RefreshTokenHandler handler = new RefreshTokenHandler(); return transport.createRequestFactory(new HttpRequestInitializer() { public void initialize(HttpRequest request) { request.unsuccessfulResponseHandler = new HttpUnsuccessfulResponseHandler() { public boolean handleResponse( HttpRequest request, HttpResponse response, boolean retrySupported) throws IOException { return handler.handleResponse(request, response, retrySupported); } }; } }); }
Implementations should normally be thread-safe.
Method Summary | |
---|---|
boolean |
handleResponse(HttpRequest request,
HttpResponse response,
boolean retrySupported)
Handler that will be invoked when an abnormal response is received. |
Method Detail |
---|
boolean handleResponse(HttpRequest request, HttpResponse response, boolean retrySupported) throws IOException
request
- Request object that can be read from for context or modified before retryresponse
- Response to processretrySupported
- Whether there will actually be a retry if this handler return true
. Some handlers may want to have an effect only when there will actually be a retry
after they handle their event (e.g. a handler that implements exponential backoff).
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |