public void handleError(HttpCommand command, HttpResponse response) { int statusCode = response.getStatusCode(); if (statusCode >= 300 && statusCode < 400) { getRedirectionHandler().handleError(command, response); } else if (statusCode >= 400 && statusCode < 500) { getClientErrorHandler().handleError(command, response); } else if (statusCode >= 500) { getServerErrorHandler().handleError(command, response); } }
private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; }
public void handleError(HttpCommand command, HttpResponse response) { int statusCode = response.getStatusCode(); if (statusCode >= 300 && statusCode < 400) { getRedirectionHandler().handleError(command, response); } else if (statusCode >= 400 && statusCode < 500) { getClientErrorHandler().handleError(command, response); } else if (statusCode >= 500) { getServerErrorHandler().handleError(command, response); } }
private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; }
public void handleError(HttpCommand command, HttpResponse response) { int statusCode = response.getStatusCode(); if (statusCode >= 300 && statusCode < 400) { getRedirectionHandler().handleError(command, response); } else if (statusCode >= 400 && statusCode < 500) { getClientErrorHandler().handleError(command, response); } else if (statusCode >= 500) { getServerErrorHandler().handleError(command, response); } }
private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; } }
public void handleError(HttpCommand command, HttpResponse response) { int statusCode = response.getStatusCode(); if (statusCode >= 300 && statusCode < 400) { getRedirectionHandler().handleError(command, response); } else if (statusCode >= 400 && statusCode < 500) { getClientErrorHandler().handleError(command, response); } else if (statusCode >= 500) { getServerErrorHandler().handleError(command, response); } }
private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; }
public void handleError(HttpCommand command, HttpResponse response) { int statusCode = response.getStatusCode(); if (statusCode >= 300 && statusCode < 400) { getRedirectionHandler().handleError(command, response); } else if (statusCode >= 400 && statusCode < 500) { getClientErrorHandler().handleError(command, response); } else if (statusCode >= 500) { getServerErrorHandler().handleError(command, response); } }
@VisibleForTesting boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } // At this point we are going to send a new request or we have just handled the error, so // we should make sure that any open stream is closed. releasePayload(response); return shouldContinue; }
public void handleError(HttpCommand command, HttpResponse response) { int statusCode = response.getStatusCode(); if (statusCode >= 300 && statusCode < 400) { getRedirectionHandler().handleError(command, response); } else if (statusCode >= 400 && statusCode < 500) { getClientErrorHandler().handleError(command, response); } else if (statusCode >= 500) { getServerErrorHandler().handleError(command, response); } }
@VisibleForTesting boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } // At this point we are going to send a new request or we have just handled the error, so // we should make sure that any open stream is closed. releasePayload(response); return shouldContinue; }
public void testDefaultInjection() { DelegatingErrorHandler handler = Guice.createInjector().getInstance( DelegatingErrorHandler.class); assertEquals(handler.getClientErrorHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); assertEquals(handler.getServerErrorHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); assertEquals(handler.getRedirectionHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); }
@VisibleForTesting boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } // At this point we are going to send a new request or we have just handled the error, so // we should make sure that any open stream is closed. releasePayload(response); return shouldContinue; }
public void testClientHandlerInjection() { DelegatingErrorHandler handler = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to( DelegatingErrorHandler.class); } }).getInstance(DelegatingErrorHandler.class); assertEquals(handler.getClientErrorHandler().getClass(), DelegatingErrorHandler.class); assertEquals(handler.getServerErrorHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); assertEquals(handler.getRedirectionHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); }
public void testStreamIsClosedWhenNotRetrying() throws IOException { MockInputStream in = new MockInputStream(2); // Input stream that produces 2 bytes HttpResponse response = HttpResponse.builder().payload(newInputStreamPayload(in)).build(); response.getPayload().getContentMetadata().setContentLength(1L); HttpCommand command = mockHttpCommand(); DelegatingRetryHandler retryHandler = EasyMock.createMock(DelegatingRetryHandler.class); DelegatingErrorHandler errorHandler = EasyMock.createMock(DelegatingErrorHandler.class); errorHandler.handleError(command, response); expectLastCall(); expect(retryHandler.shouldRetryRequest(command, response)).andReturn(false); replay(retryHandler, errorHandler); // Verify the stream is open. This consumes one byte. assertEquals(response.getPayload().openStream().available(), 2); assertEquals(response.getPayload().openStream().read(), 1); BaseHttpCommandExecutorService<?> service = mockHttpCommandExecutorService(retryHandler, errorHandler); assertFalse(service.shouldContinue(command, response)); verify(retryHandler, errorHandler); // Verify that the response stream is closed assertFalse(in.isOpen); assertTrue(response.getPayload().openStream() == in); assertEquals(response.getPayload().openStream().available(), 0); assertEquals(response.getPayload().openStream().read(), -1); }
public void testDefaultInjection() { DelegatingErrorHandler handler = Guice.createInjector().getInstance( DelegatingErrorHandler.class); assertEquals(handler.getClientErrorHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); assertEquals(handler.getServerErrorHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); assertEquals(handler.getRedirectionHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); }
DelegatingErrorHandler errorHandler = EasyMock.createMock(DelegatingErrorHandler.class); errorHandler.handleError(command, response); expectLastCall().andAnswer(new IAnswer<Void>() { @Override
public void testClientHandlerInjection() { DelegatingErrorHandler handler = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to( DelegatingErrorHandler.class); } }).getInstance(DelegatingErrorHandler.class); assertEquals(handler.getClientErrorHandler().getClass(), DelegatingErrorHandler.class); assertEquals(handler.getServerErrorHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); assertEquals(handler.getRedirectionHandler().getClass(), CloseContentAndSetExceptionErrorHandler.class); }
DelegatingErrorHandler errorHandler = EasyMock.createMock(DelegatingErrorHandler.class); errorHandler.handleError(command, response); expectLastCall().andAnswer(new IAnswer<Void>() { @Override