You can develop user handlers to customize the behavior of a handler chain and to add unique functionality to the handler. By implementing user handlers on the server-side of Java API for RESTful Web Services (JAX-RS) applications, you can enhance request and response processing.
You can add custom server-side user handlers to the request, response, and error handler chains. If additional processing such as logging every client request is required, then adding user handlers is one way of implementing the logging functionality.
In general, a handler receives a MessageContext instance for accessing and manipulating the current request information and a HandlerChain instance for advancing the chain. To pass control from one handler to another in the handler chain, it is the responsibility of the handler to invoke the doChain() method on the HandlerChain instance. Because a handler can call the doChain() method multiple times, you must consider the possibility that your handler might get invoked more than once for the same request. All handler-related interfaces reside in the org.apache.wink.server.handlers package.
Handlers use the MessageContext interface to access and manipulate the current request information. This interface enables handlers to maintain the state of a message by setting attributes on the message context. You can also use this interface to pass information to other handlers on the chain.
The request handler chain is responsible for processing a request according to the JAX-RS specification by accepting the request, searching for the resource method to invoke, deserializing the request entity, and ultimately invoking the resource method. A request handler is a class that implements the org.apache.wink.server.handlers.RequestHandler interface.
The response handler chain is responsible for handling the object returned from invoking a resource method or a sub-resource method according to the JAX-RS specification. It is responsible for determining the response status code, selecting the response media type, and for serializing the response entity. A Response handler is a class that implements the org.apache.wink.server.handlers.ResponseHandler interface.
A user handler class must implement the org.apache.wink.server.handlers.RequestHandler or org.apache.wink.server.handlers.ResponseHandler interface. You must create a class that extends the org.apache.wink.server.handlers.HandlersFactory interface to return the request or response handler. Finally, you must specify the location of the property file, that has the HandlersFactory class name, as an initialization parameter in the web.xml file to ensure that the properties file is read by the servlet or filter.
You have added a user handler to the handler chain on the server-side of your JAX-RS application so that these custom handlers get invoked on every request or response process.