@Override public MediaType getMediaType() { return acr.getMediaType(); }
MediaType contentType = getMediaType(); if (contentType == null) { contentType = getMessageBodyWorkers().getMessageBodyWriterMediaType(
@Override public MediaType getMediaType() { return acr.getMediaType(); }
@Override public MediaType getMediaType() { return acr.getMediaType(); }
/** * fix the Character set for the response see * https://stackoverflow.com/a/20569571/1497139 * as of 2019-02-08 unfortunately does not work! * * @param response * @param resp */ private void fixCharset(ContainerResponse response, ResponseBuilder resp) { MediaType type = response.getMediaType(); if (type != null) { String contentType = type.toString(); if (!contentType.contains("charset")) { contentType = contentType + ";charset=utf-8"; resp.header("Content-Type", contentType); } } } }
import com.sun.jersey.spi.container.ContainerRequest; import com.sun.jersey.spi.container.ContainerResponse; import com.sun.jersey.spi.container.ContainerResponseFilter; import javax.ws.rs.core.MediaType; public class CharsetResponseFilter implements ContainerResponseFilter { public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { MediaType contentType = response.getMediaType(); response.getHttpHeaders().putSingle("Content-Type", contentType.toString() + ";charset=UTF-8"); return response; } }
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { MediaType contentType = response.getMediaType(); // For JSON responses use UTF-8 charset if((contentType != null) && contentType.equals(MediaType.APPLICATION_JSON_TYPE)) { response.getHttpHeaders().putSingle("Content-Type", contentType.toString() + ";charset=UTF-8"); } return response; }
@Override public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { if (MediaType.APPLICATION_JSON_TYPE.isCompatible(response.getMediaType()) || TEXT_JSON.isCompatible(response.getMediaType())) { response.setResponse(Response.fromResponse(response.getResponse()).type(APPLICATION_JSON_UTF8_TYPE).build()); } return response; } }
@Override public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { if (!MediaType.APPLICATION_JSON_TYPE.isCompatible(response.getMediaType())) { return response; } final List<String> fieldsParam = request.getQueryParameters().get("fields"); if (fieldsParam == null) { return response; } final Object entity = response.getEntity(); if (entity == null) { return response; } final JsonNode tree = mapper.convertValue(entity, JsonNode.class); final Set<String> fields = expandFields(fieldsParam); if (tree.isObject()) { filterFields("", (ObjectNode) tree, fields); response.setEntity(tree); } else if (tree.isArray()) { filterFields("", (ArrayNode) tree, fields); response.setEntity(tree); } return response; }
MediaType contentType = response.getMediaType(); if (contentType == null && response.getEntity() != null) { LinkedList<MediaType> l = new LinkedList<MediaType>();
/** * Builds the {@link HttpResponse}. * * @return the {@link HttpResponse} */ private HttpResponse buildHttpResponse() { HttpResponseImpl response = new HttpResponseImpl(); if (containerResponse != null) { response.setContentType(getMediaTypeName(containerResponse.getMediaType())); response.setStatusCode(containerResponse.getStatus()); response.setEntity(containerResponse.getEntity()); response.setHeaders(containerResponse.getHttpHeaders()); } return response; }
MediaType contentType = getMediaType(); if (contentType == null) { contentType = getMessageBodyWorkers().getMessageBodyWriterMediaType(
MediaType contentType = getMediaType(); if (contentType == null) { contentType = getMessageBodyWorkers().getMessageBodyWriterMediaType(