本文整理了Java中javax.ws.rs.container.ContainerResponseContext.getEntityType()
方法的一些代码示例,展示了ContainerResponseContext.getEntityType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ContainerResponseContext.getEntityType()
方法的具体详情如下:
包路径:javax.ws.rs.container.ContainerResponseContext
类名称:ContainerResponseContext
方法名:getEntityType
[英]Get the generic entity type information.
[中]获取泛型实体类型信息。
代码示例来源:origin: icode/ameba
.getMessageBodyWriterMediaTypes(
responseContext.getEntityClass(),
responseContext.getEntityType(),
responseContext.getEntityAnnotations());
} else if (responseContext.getStatus() == 415) {
.getMessageBodyReaderMediaTypes(
responseContext.getEntityClass(),
responseContext.getEntityType(),
responseContext.getEntityAnnotations());
代码示例来源:origin: stackoverflow.com
public class MyContainerResponseFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
// You can get the body of the response from the ContainerResponseContext
Object entity = containerResponseContext.getEntity();
// You'll need to know what kind of Object the entity is in order to do something useful though
// You can get some data using these functions
Class<?> entityClass = containerResponseContext.getEntityClass();
Type entityType = containerResponseContext.getEntityType();
// And/or by looking at the ContainerRequestContext and knowing what the response entity will be
String method = containerRequestContext.getMethod();
UriInfo uriInfo = containerRequestContext.getUriInfo();
// Then you can modify your Authorization header in some way
String authorizationHeaderValue = containerResponseContext.getHeaderString(HttpHeaders.AUTHORIZATION);
authorizationHeaderValue = authorizationHeaderValue + " a signature you calculated";
containerResponseContext.getHeaders().putSingle(HttpHeaders.AUTHORIZATION, authorizationHeaderValue);
}
}
代码示例来源:origin: apache/cxf
@Override
public void filter(ContainerRequestContext requestContext,
ContainerResponseContext responseContext) throws IOException {
String ct = responseContext.getMediaType().toString();
if (requestContext.getProperty("filterexception") != null) {
if (!"text/plain".equals(ct)) {
throw new RuntimeException();
}
responseContext.getHeaders().putSingle("FilterException",
requestContext.getProperty("filterexception"));
}
Object entity = responseContext.getEntity();
Type entityType = responseContext.getEntityType();
if (entity instanceof GenericHandler && InjectionUtils.getActualType(entityType) == Book.class) {
ct += ";charset=ISO-8859-1";
if ("getGenericBook2".equals(rInfo.getResourceMethod().getName())) {
Annotation[] anns = responseContext.getEntityAnnotations();
if (anns.length == 4 && anns[3].annotationType() == Context.class) {
responseContext.getHeaders().addFirst("Annotations", "OK");
}
} else {
responseContext.setEntity(new Book("book", 124L));
}
} else {
ct += ";charset=";
}
responseContext.getHeaders().putSingle("Content-Type", ct);
responseContext.getHeaders().add("Response", "OK");
}
内容来源于网络,如有侵权,请联系作者删除!