@Test public void testMissingContentType() { JsonResponse<User> response = handler.handle(null, mockResponse().body("hello").build()); assertFalse(response.hasValue()); assertNull(response.getException()); assertNull(response.getJson()); assertNull(response.getJsonBytes()); assertEquals(response.getResponseBytes(), "hello".getBytes(StandardCharsets.UTF_8)); assertEquals(response.getResponseBody(), "hello"); assertTrue(response.getHeaders().isEmpty()); }
@Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } private  FullJsonResponseHandler(JsonCodec<T> jsonCodec); }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } private  FullJsonResponseHandler(JsonCodec<T> jsonCodec); static FullJsonResponseHandler<T> createFullJsonResponseHandler(JsonCodec<T> jsonCodec); @Override JsonResponse<T> handleException(Request request, Exception exception); @Override JsonResponse<T> handle(Request request, Response response); }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } private  FullJsonResponseHandler(JsonCodec<T> jsonCodec); static FullJsonResponseHandler<T> createFullJsonResponseHandler(JsonCodec<T> jsonCodec); @Override JsonResponse<T> handleException(Request request, Exception exception); @Override JsonResponse<T> handle(Request request, Response response);  }