.getMessageBodyWriterMediaTypes( responseContext.getEntityClass(), responseContext.getEntityType(), responseContext.getEntityAnnotations()); } else if (responseContext.getStatus() == 415) { .getMessageBodyReaderMediaTypes( responseContext.getEntityClass(), responseContext.getEntityType(), responseContext.getEntityAnnotations());
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); } }
@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"); }