本文整理匯總了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");
}
}