Let me start with Filters:
FILTERS:
Filters can modify incoming and outgoing requests and responses, including modifying headers, objects, and other request / response parameters.
Additional filters are classified as Container / Server Filters and Client Filters .
Consider server filters. There are two more obvious types:
- query filter
- response filter
There are two main differences between the two types (depending on what they refer to):
- Response filters implement the ContainerResponseFilter interface and have two arguments:
container request (ContainerRequestContext requestContext) and
container response (ContainerResponseContext responseContext) .
Now, what do these two arguments relate to:
public interface ContainerRequestContext
Container request filter context. A mutable class that provides information for a particular query for a filter, such as a query URI, message headers, a message object, or query scope properties. Open setters allow modification of the open information requested for a request.
public interface ContainerResponseContext
Context filter. A mutable class that provides response-specific information for a filter, such as message headers, a message object, or request scope properties. Open setters allow you to change the information specific to a specific user.
Note that requestContext can access one more thing: requestURI
- Request filters are implemented by ContainerRequestFilter and have only one argument:
container request (ContainerRequestContext requestContext)
Getting to your question:
What stream is specified in the setEntityStream (arg0) and getEntityStream () method?
This can be broken down into:
- getEntityStream (): A server-side entity stream request is where the object is read from the client request and a client-side response object stream where the object is read from the server response.
- setEntityStream (arg0): On the server, when writing the response object and on the write request side, the request object for sending the request to the server for the write object. **
EDIT:
- Filters can be used to check certain criteria for any query. If the criteria are not met, filters can also cancel the response.
Consider the following example from the jersey documentation :
public class AuthorizationRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { final SecurityContext securityContext = requestContext.getSecurityContext(); if (securityContext == null || !securityContext.isUserInRole("privileged")) { requestContext.abortWith(Response .status(Response.Status.UNAUTHORIZED) .entity("User cannot access the resource.") .build()); } } }
The AuthorizationRequestFilter in this example checks to see if the authenticated user is in a privileged role. When the filter method is completed, the response passed as a parameter to the abortWith method is used to respond to the request. Response filters, if registered, will be executed and will be able to process a canceled response.
Filters can influence which method is consistent. Pre-match filters are query filters that run before query matching begins.
@PreMatching public class PreMatchingFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException {
PreMatchingFilter is a simple pre-approval filter that changes all HTTP PUT methods to POST. This can be useful when you want to always process these PUT and POST HTTP methods with the same Java code.
Interceptors:
Write-Interceptors wraps the object in the GZIPOutput stream, and Reader-Interceptors wraps the object in the GZIPInput stream, which decompresses the data from the received compressed object.
In addition, Interceptors can also be used to provide digital signatures . For digital signatures, it is necessary to calculate the hash of the body and add it to the header of the request for signature (client-side) or response (server-side).