public void handleError(HttpCommand command, HttpResponse from) { String content; try { content = from.getPayload() != null ? Strings2.toString(from.getPayload()) : null; command.setException(new HttpResponseException(command, from, content)); } catch (IOException e) { command.setException(new HttpResponseException(command, from)); } finally { releasePayload(from); } } }
public void handleError(HttpCommand command, HttpResponse from) { String content; try { content = from.getPayload() != null ? Strings2.toString(from.getPayload()) : null; command.setException(new HttpResponseException(command, from, content)); } catch (IOException e) { command.setException(new HttpResponseException(command, from)); } finally { releasePayload(from); } } }
public Task apply(HttpResponse from) { String location = from.getFirstHeaderOrNull(HttpHeaders.LOCATION); if (location == null) location = from.getFirstHeaderOrNull("location"); if (location != null) { return new TaskImpl(URI.create(location), null, TaskStatus.QUEUED, new Date(), null, null, null, null); } else { throw new HttpResponseException("no uri in headers or content", null, from); } } }
public void handleError(HttpCommand command, HttpResponse from) { String content; try { content = from.getPayload() != null ? Strings2.toStringAndClose(from.getPayload().openStream()) : null; command.setException(new HttpResponseException(command, from, content)); } catch (IOException e) { command.setException(new HttpResponseException(command, from)); } finally { releasePayload(from); } } }
public void testNullResponse() { Exception from = new HttpResponseException("message", null, null); assertEquals(returnValueOnCodeOrNull(from, true, equalTo(404)), null); } }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testPropagateStandardExceptionUnsupportedOperationExceptionNestedInHttpResponseException() throws Throwable { Exception e = new UnsupportedOperationException(); propagateIfPossible(new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = HttpResponseException.class) public void testPropagateStandardExceptionHttpResponseException() throws Throwable { Exception e = new HttpResponseException("goo", createNiceMock(HttpCommand.class), null); propagateIfPossible(new RuntimeException(e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testPropagateStandardExceptionIllegalArgumentExceptionNestedInHttpResponseException() throws Throwable { Exception e = new IllegalArgumentException(); propagateIfPossible(new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = IllegalStateException.class) public void testPropagateStandardExceptionIllegalStateExceptionNestedInHttpResponseException() throws Throwable { Exception e = new IllegalStateException(); propagateIfPossible(new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = AuthorizationException.class) public void testPropagateStandardExceptionAuthorizationExceptionNestedInHttpResponseException() throws Throwable { Exception e = new AuthorizationException(); propagateIfPossible(new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = ResourceNotFoundException.class) public void testPropagateStandardExceptionResourceNotFoundExceptionNestedInHttpResponseException() throws Throwable { Exception e = new ResourceNotFoundException(); propagateIfPossible(new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
public static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
private static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); // TODO: bogus endpoint return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 700 seconds") public void testHttpResponseExceptionWithRetryAfterOffset(){ fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "700").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 86400 seconds") public void testHttpResponseExceptionWithRetryAfterPastIsZero(){ fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Sun, 2 Jan 2000 00:00:00 GMT").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 700 seconds") public void testHttpResponseExceptionWithRetryAfterOffset() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "700").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry now") public void testHttpResponseExceptionWithRetryAfterDate() { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 GMT").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 86400 seconds") public void testHttpResponseExceptionWithRetryAfterPastIsZero() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Sun, 2 Jan 2000 00:00:00 GMT").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry now") public void testHttpResponseExceptionWithRetryAfterDate() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 GMT").build())); }
public void testHttpResponseExceptionWithMalformedRetryAfterHeaderDoesntConvert(){ fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 ZBW").build())); }