@Test public void testInvalidSmile() { SmileResponse<User> response = handler.handle(null, createSmileResponse(OK, ImmutableMap.of( "age", "foo" ))); assertFalse(response.hasValue()); assertEquals(response.getException().getMessage(), "Unable to create " + User.class + " from SMILE response"); assertInstanceOf(response.getException().getCause(), InvalidFormatException.class); assertContains(response.getException().getCause().getMessage(), "Cannot deserialize value of type `int` from String \"foo\": not a valid Integer value"); }
@Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } private  FullSmileResponseHandler(JsonCodec<T> jsonCodec); }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } private  FullSmileResponseHandler(JsonCodec<T> jsonCodec); static FullSmileResponseHandler<T> createFullSmileResponseHandler(JsonCodec<T> jsonCodec); @Override SmileResponse<T> handleException(Request request, Exception exception); @Override SmileResponse<T> handle(Request request, Response response); }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } private  FullSmileResponseHandler(JsonCodec<T> jsonCodec); static FullSmileResponseHandler<T> createFullSmileResponseHandler(JsonCodec<T> jsonCodec); @Override SmileResponse<T> handleException(Request request, Exception exception); @Override SmileResponse<T> handle(Request request, Response response);  }