Site icon

Working of Filters & Interceptors in RESTFul web service (Jersey /example)

Request response flow in client server (REST Web service)

We have shown the request response mechanism of service and client in Fig 1.

Fig 1: Request response – web services

The execution flow shown in Fig 1, is applicable for client server paradigm. We would like to intercepts or filters the data for following cases.

We have already discussed about the filters in enterprise application.

JAX-RS specification provides the couple of extension points to customize the request/response on client and server sides. There are couple of extension points like filters and interceptors.

The extension points can be used for

How filters works in enterprise applications (JAX-RS Jersey framework – java):

The filters are mostly used to modify the request or response parameters. Generally we will find the authentication filters, which are used to authenticate the user before the request reaches to any resource.

We have already discussed about the request logging filters using jersey wherein we have used the server side (ContainerRequestFilter, ContainerRequestFilterfilters

Fig 2: Client & Server request response filter

Similar to server side, we will have corresponding client side request and response filters.

How Interceptors works in RESTFul web service (JAX-RS) ?

Interceptors are used to modify the entities, mostly the interceptors are used for encoding or decoding of entities.
Let us take a look into the execution order of filters and interceptors is as follows:

Fig 3: Execution flow with filters and interceptors (JAX-RS)

The interceptors are of two types:

Exit mobile version