Java Reference
In-Depth Information
throw new
WebApplicationException(Status.UNAUTHORIZED);
List<MediaType> supportedMedia
=crq.getAcceptableMediaTypes();
if("GET".equals(crq.getMethod())
&&!supportedMedia.contains(MediaType.APPLICATION_JSON_TYPE))
throw new
WebApplicationException(Status.UNSUPPORTED_MEDIA_TYPE);
// external users must only access
student methods
String path = crq.getUriInfo().getPath();
if(!path.startsWith("/students"))
throw new
WebApplicationException(Status.FORBIDDEN);
List<String> encoding =
crq.getHeaders().get("accept-encoding");
// If the client does not support the
gzip compression
if(!encoding.toString().contains("gzip"))
throw new
WebApplicationException(Status.EXPECTATION_FAILED);
}
}
Entity interceptors
In addition to the differences noted between filters and entity interceptors, JAX-RS
provides two types of entity interceptors instead of four. There is a reader interceptor
that implements the ReaderInterceptor interface and a writer interceptor, which
implements the WriterInterceptor interface. Due to the elements that they are
supposed to handle (message bodies), interceptors can be used to compress large
content to optimize network utilization; they can also be used for some processing
such as the generation and verification of digital signatures.
Search WWH ::




Custom Search