There are two sides to the REST interaction, client and server. Jersey / JAX -RS-2 has both a client API and a βcoreβ server API. When working with the client API, we could use ClientRequestFilter , and when using the server-side API, we would use ContainerRequestFilter . There is no way to mix and match them, they should be strictly used from the corresponding side of the interaction.
A ContainerRequestFilter (Server Side) example was supposed to do some authorization / authentication, which is a pretty common use case for a filter on the server side. The filter will be called before reaching any of your resources.
Client ---> Internet ---> Server ---> Filter ---> Resource
A ClientRequestFilter (client side) example will implement some cache client (like a mock browser cache). Or the case (which has already been implemented) is a filter for encoding the username and password for BASIC authentication. Before the request is actually sent to the server, a client filter will be called.
Client ---> Filter ---> Internet ---> Server ---> Resource
There are also XxxResponseFilters that follow the next thread
Resource ---> ContainerResponseFilter ---> Server ---> Internet ---> Client Server ---> Internet ---> ClientResponseFilter ---> Client
Paul samsotha
source share