@Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { if (responseContext.getMediaType() != null && responseContext.getMediaType().isCompatible(MediaType.TEXT_PLAIN_TYPE)) { String newContentType = "application/json" + responseContext.getMediaType().toString().substring(10); responseContext.getHeaders().putSingle("Content-Type", newContentType); } } }
private String getBodyAsMessage(ClientResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { try (InputStream entityStream = responseContext.getEntityStream()) { Charset charset = null; MediaType mediaType = responseContext.getMediaType(); if (mediaType != null) { String charsetName = mediaType.getParameters().get("charset"); if (charsetName != null) { try { charset = Charset.forName(charsetName); } catch (Exception ignored) { } } } if (charset == null) { charset = Charset.defaultCharset(); } return IOUtils.toString(entityStream, charset); } catch (Exception ignored) { } } return null; } }
private String getPrettyPrintResponseBody(ClientResponseContext responseContext) { String responseBody = getResponseBody(responseContext); if (StringUtils.isNotEmpty(responseBody) && responseContext.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)) { return JsonUtil.toPrettyPrint(responseBody); } return responseBody; }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { if (!logger.isLoggable(level)) { return; } final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); } }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { if (!logger.isLoggable(level)) { return; } final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); } }
@Override public MediaType getMediaType() { return responseContext.getMediaType(); }
@Override public MediaType getMediaType() { return responseContext.getMediaType(); }
@Override public MediaType getMediaType() { return responseContext.getMediaType(); }
@Override public MediaType getMediaType() { return responseContext.getMediaType(); }
@Override public String getContentType() { return context.getMediaType() == null ? null : context.getMediaType().toString(); }
@Override public String getContentType() { return context.getMediaType() == null ? null : context.getMediaType().toString(); }
@Nullable @Override public String getContentType() { return Objects.toString(context.getMediaType(), null); }
@Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { if (responseContext.getMediaType() != null && responseContext.getMediaType().isCompatible(MediaType.TEXT_PLAIN_TYPE)) { String newContentType = "application/json" + responseContext.getMediaType().toString().substring(10); responseContext.getHeaders().putSingle("Content-Type", newContentType); } } }
@Override public void filter(ClientRequestContext reqCtx, ClientResponseContext respCtx) throws IOException { addMultipartFilterIfNeeded(respCtx.getMediaType()); } }
@Override public Charset getCharset() { return HttpMessages.getCharset(context.getMediaType()); }
@Override @SuppressFBWarnings("SLF4J_FORMAT_SHOULD_BE_CONST") public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { if (responseContext.getStatusInfo().getFamily().equals( Response.Status.Family.SUCCESSFUL) && !isContentTypeCompatible(responseContext.getMediaType())) { log.error(ERROR_MSG); String snippet = String.format( "Wrong content type received: [%s]", responseContext.getMediaType()); log.error(snippet); throw new IllegalStateException(snippet); } } }
public ClientResponseContextAssert hasMediaType(final String expectedMediaType) { isNotNull(); final MediaType actualMediaType = actual.getMediaType(); if (expectedMediaType == null && actualMediaType != null) { failWithMessage("Expected content type to be null but was <%s>", actualMediaType.toString()); } if (!MediaType.valueOf(expectedMediaType).isCompatible(actual.getMediaType())) { failWithMessage("Expected content type to be <%s> but was <%s>", expectedMediaType, actualMediaType.toString()); } return myself; } }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (printEntity && responseContext.hasEntity()) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (printEntity && responseContext.hasEntity()) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (printEntity && responseContext.hasEntity()) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); }