Handler Chain - Runtime Extension
The Apache Wink runtime utilizes three Handler Chains for the complete processing of a request: Request chain, Response chain and Error chain. A handler receives a MessageContext instance for accessing and manipulating the current request information and a HandlerChain instance for advancing the chain. It is the responsibility of the handler to pass control to the next handler on the chain by invoking the doChain() method on the HandlerChain instance.
A handler may call the doChain() method several times if needed, so handlers are required to consider the possibility they will be invoked more than once for the same request.
All handler related interfaces reside in the com.hp.symphony.server.handlers package.
The implementation of separate chains provides the ability to move up and down one chain before moving on to the next chain. This is particularly useful for the implementation of the JAX-RS resource-method search algorithm that includes invoking sub-resource locators, and implementing the Continued Search mode.
Handlers
There are two types of handlers:
- System Handler
- User Handler
System Handlers are the handlers that implement the core engine of the Apache Wink runtime. The Apache Wink runtime will not function correctly if any of the system handlers are removed from the chain.
User Handlers are the handlers that are provided by an application to customize a chains behavior and to add unique functionality to it. User handlers are not part of the core functionality of Apache Wink.
Reference
Refer to chapter 2, section 2.3.1 for more details on User Handlers Customization.
Message Context
The MessageContext allows the following:
Allows handlers to access and manipulate the current request informationAllows handlers to maintain a state by setting attributes on the message context, as the handlers themselves are singletons and therefore statelessAllows handlers to pass information to other handlers on the chain
Request Handler 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, de-serializing the request entity and finally for invoking the resource method. It is responsible for invoking sub-resource locators by moving up and down the chain as needed. A Request handler is a class that implements the com.hp.wink.server.handlers.RequestHandler interface.
System Request Handlers
The following is a list of system handlers comprising the request handler chain in the order that they appear in the chain.
Handler |
Description |
---|---|
SearchResultHandler |
Responsible for throwing the search result error if there was one during the search for the resource method |
OptionsMethodHandler |
Generates a response for an OPTIONS request in case that there is no resource method that is associated with OPTIONS, according to the JAX-RS spec |
HeadMethodHandler |
Handles a response for a HEAD request in case that there is no resource method that is associated with HEAD, according to the JAX-RS spec |
FindRootResourceHandler |
Locates the root resource that best matches the request |
FindResourceMethodHandler |
Locates the actual method to invoke that matches the request, invoking sub-resource locators as needed |
CreateInvocationParametersHandler |
Creates the parameters of the resource method to invoke and de-serializes the request entity using the appropriate MessageBodyReader |
InvokeMethodHandler |
Invokes the resource method |
User Request Handlers
User request handlers are inserted before the InvokeMethodHandler handler.