本文整理汇总了Java中javax.ws.rs.container.ContainerResponseContext.getMediaType方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerResponseContext.getMediaType方法的具体用法?Java ContainerResponseContext.getMediaType怎么用?Java ContainerResponseContext.getMediaType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.container.ContainerResponseContext
的用法示例。
在下文中一共展示了ContainerResponseContext.getMediaType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processResponse
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void processResponse(ContainerRequestContext requestContext, ContainerResponseContext responseContext,
ResourceInfo resourceInfo) {
MediaType mediaType = responseContext.getMediaType();
if (mediaType != null && MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
Object responseData = responseContext.getEntity();
WrapperResponseEntity jsonResponse;
if (responseData instanceof WrapperResponseEntity) {
jsonResponse = (WrapperResponseEntity) responseData;
} else {
jsonResponse = new WrapperResponseEntity(ResponseCode.OK);
jsonResponse.setData(responseData);
}
responseContext.setStatus(ResponseCode.OK.getCode());
responseContext.setEntity(jsonResponse);
}
}
示例2: processResponse
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void processResponse(ContainerRequestContext requestContext,
ContainerResponseContext responseContext,
ResourceInfo resourceInfo) {
MediaType mediaType = responseContext.getMediaType();
if (mediaType != null && MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
Object responseData = responseContext.getEntity();
WrapperResponseEntity jsonResponse;
if (responseData instanceof WrapperResponseEntity) {
jsonResponse = (WrapperResponseEntity) responseData;
} else {
jsonResponse = new WrapperResponseEntity(ResponseCode.OK);
jsonResponse.setData(responseData);
}
responseContext.setStatus(ResponseCode.OK.getCode());
responseContext.setEntity(jsonResponse);
}
}
示例3: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
String version = Version.get(requestContext);
if (version != null) {
MediaType mediaType = responseContext.getMediaType();
if (mediaType != null) {
Map<String, String> parameters = new HashMap<String, String>(mediaType.getParameters());
parameters.put(parameterName, version);
mediaType = new MediaType(mediaType.getType(), mediaType.getSubtype(), parameters);
responseContext.getHeaders().putSingle("Content-Type", mediaType.toString());
}
}
}
示例4: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
MediaType mediaType = responseContext.getMediaType();
responseContext.getHeaders().putSingle("Content-Type", mediaType.withCharset("utf-8").toString());
}
示例5: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
/**
* Filter method called after a response has been provided for a request
* (either by a {@link ContainerRequestFilter request filter} or by a
* matched resource method.
* <p>
* Filters in the filter chain are ordered according to their {@code javax.annotation.Priority}
* class-level annotation value.
* </p>
*
* @param requestContext request context.
* @param responseContext response context.
* @throws IOException if an I/O exception occurs.
*/
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
MediaType contentType = responseContext.getMediaType();
if (contentType != null) {
responseContext.getHeaders().putSingle("Content-Type", contentType.toString() + ";charset=UTF-8");
}
}