Request delegation with Habari Web Components

The TdjHandlerWrapper class was introduced in version 2.0 of Habari Web Components. It allows to execute code before and after the code of a wrapped handler.

From the documentation:

 A HandlerWrapper acts as a IHandler but delegates the handle method  and life cycle events to a delegate.  This is primarily used to implement the Decorator pattern.

Example use cases

Example use cases for request delegation include user authentication, filtering, logging, statistics, and compression.

Nesting wrappers is allowed

By nesting of handler wrappers, the server can provide combinations of the wrappers (logging and statistics).

Example: introducing the TdjStatisticsHandler

A common use case are request statistics. The TdjStatistisHandler class gives access to information such as

  • how many requests have been processed since the server startup?
  • what was the minimum, maximum and average processing time for requests?
  • how many errors occoured?

Instead of adding the statistics code in the web component, the server use an instance of this class which collects statistics data before and after calling wrapped web components.

A wrapper implementation must override the Handle method. In the method body, code can be executed before and after the call to the wrapped handler. Example:

procedure TdjStatisticsHandler.Handle(Target: string; Context: TdjServerContext;
  Request: TIdHTTPRequestInfo; Response: TIdHTTPResponseInfo);





Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s