@Override public boolean isMappable(HttpResponseException exception) { return exception.getResponse() != null; } }
return; } catch (HttpResponseException hre) { HttpResponse hr = hre.getResponse(); if (hr == null) { response.sendError(
@Override public Response toResponse(HttpResponseException exception) { return Response.status(exception.getResponse().getStatusCode()) .build(); }
public static <T> T returnValueOnCodeOrNull(Throwable from, T value, Predicate<Integer> codePredicate) { Iterable<HttpResponseException> throwables = filter(getCausalChain(from), HttpResponseException.class); if (size(throwables) >= 1 && get(throwables, 0).getResponse() != null && codePredicate.apply(get(throwables, 0).getResponse().getStatusCode())) { return value; } return null; }
public static <T> T returnValueOnCodeOrNull(Throwable from, T value, Predicate<Integer> codePredicate) { Iterable<HttpResponseException> throwables = filter(getCausalChain(from), HttpResponseException.class); if (size(throwables) >= 1 && get(throwables, 0).getResponse() != null && codePredicate.apply(get(throwables, 0).getResponse().getStatusCode())) { return value; } return null; }
public static <T> T returnValueOnCodeOrNull(Throwable from, T value, Predicate<Integer> codePredicate) { Iterable<HttpResponseException> throwables = filter(getCausalChain(from), HttpResponseException.class); if (size(throwables) >= 1 && get(throwables, 0).getResponse() != null && codePredicate.apply(get(throwables, 0).getResponse().getStatusCode())) { return value; } return null; }
public static <T> T returnValueOnCodeOrNull(Throwable from, T value, Predicate<Integer> codePredicate) { Iterable<HttpResponseException> throwables = filter(getCausalChain(from), HttpResponseException.class); if (size(throwables) >= 1 && get(throwables, 0).getResponse() != null && codePredicate.apply(get(throwables, 0).getResponse().getStatusCode())) { return value; } return null; }
public static <T> T returnValueOnCodeOrNull(Throwable from, T value, Predicate<Integer> codePredicate) { Iterable<HttpResponseException> throwables = filter(getCausalChain(from), HttpResponseException.class); if (size(throwables) >= 1 && get(throwables, 0).getResponse() != null && codePredicate.apply(get(throwables, 0).getResponse().getStatusCode())) { return value; } return null; }
@Override public Void createOrPropagate(Throwable t) throws Exception { if (checkNotNull(t, "throwable") instanceof HttpResponseException) { HttpResponseException hre = HttpResponseException.class.cast(t); if (hre.getResponse().getStatusCode() == 503 || hre.getResponse().getStatusCode() == 401 || MESSAGE_PATTERN.matcher(hre.getMessage()).matches()) return null; } else if (t instanceof AuthorizationException) { return null; } throw propagate(t); } }
public static <T> T returnValueOnCodeOrNull(Throwable from, T value, Predicate<Integer> codePredicate) { Iterable<HttpResponseException> throwables = filter(getCausalChain(from), HttpResponseException.class); if (size(throwables) >= 1 && get(throwables, 0).getResponse() != null && codePredicate.apply(get(throwables, 0).getResponse().getStatusCode())) { return value; } return null; }
@Override public ListenableFuture<Object> create(Throwable t) { if (!(t instanceof HttpResponseException)) throw propagate(t); HttpResponse response = HttpResponseException.class.cast(t).getResponse(); if (response == null) return immediateFuture(null); // https://tools.ietf.org/html/rfc2616#section-14.37 String retryAfter = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER); if (retryAfter != null) { Optional<RetryAfterException> retryException = tryCreateRetryAfterException(t, retryAfter); if (retryException.isPresent()) throw retryException.get(); } return immediateFuture(null); }
@Override public ListenableFuture<Object> create(Throwable t) { if (!(t instanceof HttpResponseException)) throw propagate(t); HttpResponse response = HttpResponseException.class.cast(t).getResponse(); if (response == null) return immediateFuture(null); // https://tools.ietf.org/html/rfc2616#section-14.37 String retryAfter = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER); if (retryAfter != null) { Optional<RetryAfterException> retryException = tryCreateRetryAfterException(t, retryAfter); if (retryException.isPresent()) throw retryException.get(); } return immediateFuture(null); }
@Override public Object createOrPropagate(Throwable t) throws Exception { if (!(t instanceof HttpResponseException)) throw propagate(t); HttpResponse response = HttpResponseException.class.cast(t).getResponse(); if (response == null) { return null; } // https://tools.ietf.org/html/rfc2616#section-14.37 String retryAfter = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER); if (retryAfter != null) { Optional<RetryAfterException> retryException = tryCreateRetryAfterException(t, retryAfter); if (retryException.isPresent()) throw retryException.get(); } return null; }
public Void apply(Exception from) { HttpResponseException exception = Throwables2.getFirstThrowableOfType(from, HttpResponseException.class); if (exception != null && exception.getCommand().getCurrentRequest().getMethod().equals(HttpMethod.DELETE) && exception.getResponse().getStatusCode() == 302) { return null; } throw Throwables.propagate(from); } }
@Test public void testMaximumRetriesExceeded() throws InterruptedException, ExecutionException { beginToFailOnRequestNumber = 0; endFailuresOnRequestNumber = 6; requestCount = 0; try { submitGetRequest(); fail("Request should not succeed within " + endFailuresOnRequestNumber + " requests"); } catch (HttpResponseException e) { assertEquals(e.getResponse().getStatusCode(), 500); } }
@Test(groups = { "integration", "live" }) public void deleteObjectNoContainer() { try { view.getBlobStore().removeBlob("donb", "test"); } catch (HttpResponseException e) { assertEquals(e.getResponse().getStatusCode(), 404); } catch (ContainerNotFoundException e) { } }
@Test(groups = { "integration", "live" }) public void deleteObjectNoContainer() { try { view.getBlobStore().removeBlob("donb", "test"); } catch (HttpResponseException e) { assertEquals(e.getResponse().getStatusCode(), 404); } catch (ContainerNotFoundException e) { } }
@Test public void testInterleavedSuccessesAndFailures() throws InterruptedException, ExecutionException { beginToFailOnRequestNumber = 3; endFailuresOnRequestNumber = 3 + 5; // Force third request to fail completely requestCount = 0; assertEquals(submitGetRequest().trim(), XML); assertEquals(submitGetRequest().trim(), XML); try { submitGetRequest(); fail("Third request should not succeed by attempt number " + requestCount); } catch (HttpResponseException e) { assertEquals(e.getResponse().getStatusCode(), 500); } assertEquals(submitGetRequest().trim(), XML); }
@Test(groups = { "integration", "live" }) public void testPutIncorrectContentMD5() throws InterruptedException, IOException { byte[] payload = createTestInput(1024).read(); HashCode contentMD5 = md5().hashBytes(new byte[0]); try { putBlobWithMd5(payload, contentMD5); fail(); } catch (HttpResponseException hre) { if (hre.getResponse().getStatusCode() != getIncorrectContentMD5StatusCode()) { throw hre; } } }
@Test(groups = { "integration", "live" }) public void testGetIfNoneMatch() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; String goodETag = addObjectAndValidateContent(container, name); view.getBlobStore().getBlob(container, name, ifETagDoesntMatch("powerfrisbee")); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag)); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 304); } } finally { returnContainer(container); } }