private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; }
private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; } }
private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; }
private boolean shouldContinue(HttpCommand command, HttpResponse response) { boolean shouldContinue = false; if (retryHandler.shouldRetryRequest(command, response)) { shouldContinue = true; } else { errorHandler.handleError(command, response); } return shouldContinue; }
@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; }
@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; }
@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; }
boolean shouldContinue(HttpCommand command, IOException response) { // Even though Java does not want to handle it this way, // treat a Protocol Exception on PUT with 100-Continue as a case of Unauthorized (and attempt to retry) if (command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getHeaders().containsEntry("Expect", "100-continue") && response instanceof ProtocolException && response.getMessage().equals("Server rejected operation") ) { logger.debug("Caught a protocol exception on a 100-continue PUT request. Attempting to retry."); return isIdempotent(command) && retryHandler.shouldRetryRequest(command, HttpResponse.builder().statusCode(401).message("Unauthorized").build()); } return isIdempotent(command) && ioRetryHandler.shouldRetryRequest(command, response); }
boolean shouldContinue(HttpCommand command, IOException response) { // Even though Java does not want to handle it this way, // treat a Protocol Exception on PUT with 100-Continue as a case of Unauthorized (and attempt to retry) if (command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getHeaders().containsEntry("Expect", "100-continue") && response instanceof ProtocolException && response.getMessage().equals("Server rejected operation") ) { logger.debug("Caught a protocol exception on a 100-continue PUT request. Attempting to retry."); return isIdempotent(command) && retryHandler.shouldRetryRequest(command, HttpResponse.builder().statusCode(401).message("Unauthorized").build()); } return isIdempotent(command) && ioRetryHandler.shouldRetryRequest(command, response); }
boolean shouldContinue(HttpCommand command, IOException response) { // Even though Java does not want to handle it this way, // treat a Protocol Exception on PUT with 100-Continue as a case of Unauthorized (and attempt to retry) if (command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getHeaders().containsEntry("Expect", "100-continue") && response instanceof ProtocolException && response.getMessage().equals("Server rejected operation") ) { logger.debug("Caught a protocol exception on a 100-continue PUT request. Attempting to retry."); return isIdempotent(command) && retryHandler.shouldRetryRequest(command, HttpResponse.builder().statusCode(401).message("Unauthorized").build()); } return isIdempotent(command) && ioRetryHandler.shouldRetryRequest(command, response); }
public void testStreamIsClosedWhenRetrying() 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); expect(retryHandler.shouldRetryRequest(command, response)).andReturn(true); 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); assertTrue(service.shouldContinue(command, response)); verify(retryHandler, errorHandler); // Verify that the response stream is closed and consumed assertFalse(in.isOpen); assertTrue(response.getPayload().openStream() == in); // The service shouldn't have changed it assertEquals(response.getPayload().openStream().available(), 0); assertEquals(response.getPayload().openStream().read(), -1); }
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); }
expect(retryHandler.shouldRetryRequest(command, response)).andReturn(false); replay(retryHandler, errorHandler);
expect(retryHandler.shouldRetryRequest(command, response)).andReturn(false); replay(retryHandler, errorHandler);