Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

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 comorg.hpapache.symphonywink.server.handlers package.

...

There are two types of handlers:

  • System Handler
  • User Handler

...

  • - 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

...

  • Handler - 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.
Info
titleReference

Refer to chapter 2, section ‎2.3.1 for more details on User Handlers Customization.In order to customize a handler chain refer to section 2 "Apache Wink Building Blocks", Customization of the Handlers Chain

Message Context

The MessageContext allows the following:
Allows The MessageContext 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

...

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 comorg.hpapache.wink.server.handlers.RequestHandler interface.

...

User request handlers are inserted before the InvokeMethodHandler handler.

Info
titleReference

In order to customize a handler chain refer to section 2 "Apache Wink Building Blocks", Customization of the Handlers Chain

Response Handler Chain

The Response Handler Chain is responsible for handling the object returned from invoking a resource method or 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.

System Response Handlers

The following is a list of system handlers comprising the response handler chain in the order that they appear in the chain.

Handler

Description

PopulateResponseStatusHandler

Determines the response status code, according to the JAX-RS spec

PopulateResponseMediaTypeHandler

Determines the response media type, according to the JAX-RS spec

FlushResultHandler

Serializes the response entity using the appropriate MessageBodyWriter

HeadMethodHandler

Performs cleanup operations in case that there was no resource method that was associated with HEAD.

User Response Handlers

User response handlers are inserted before the FlushResultHandler handler. Apache Wink initializes the user response handler chain with the CheckLocationHeaderHandler handler that verifies that the "Location" response header is present on a response when there is a status code that requires it, for example, status code: 201.

Info
titleReference

In order to customize a handler chain refer to section 2 "Apache Wink Building Blocks", Customization of the Handlers Chain

Error Handler Chain

The Error Handler Chain is responsible for handling all of the exceptions that are thrown during the invocation of the Request and Response handler chains, according to the JAX-RS specification for handling exceptions. It is responsible for determining the response status code, selecting the response media type and for serializing the response entity.

An Error handler is a class that implements the org.apache.wink.server.handlers.ResponseHandler interface.

System Error Handlers

The following is a list of system handlers comprising the error handler chain in the order that they appear in the chain.

Error Handlers

Handler

Description

PopulateErrorResponseHandler

Prepares the response entity from a thrown exception according to the JAX-RS specification

PopulateResponseStatusHandler

Determines the response status code according to the JAX-RS spec

PopulateResponseMediaTypeHandler

Determines the response media type, according to the JAX-RS spec

FlushResultHandler

Serializes the response entity using the appropriate MessageBodyWriter

User Error Handlers

User error handlers are inserted before the FlushResultHandler handler.

Info
titleReference

In order to customize a handler chain refer to section 2 "Apache Wink Building Blocks", Customization of the Handlers Chain

Request Processing

The following details how the Apache Wink runtime performs request processing:

  1. Create new instances of the three handler chains. The handlers themselves are singletons.
  2. Create a new instance of a MessageContext to pass between the handlers.
  3. Invoke the first handler on the Request chain.
  4. Once the request chain is complete, invoke the Response chain and pass it the MessageContext that was used in the Request chain.
  5. Make both chains and the MessageContext available for garbage collection.

If at any time during the execution of a Request or Response chain an exception is thrown, catch the exception, wrap it in a new MessageContext instance and invoke the Error chain to produce an appropriate response.