Femto Web Server V1.4-F

dfischer.femtowebserver.httpd
Class HttpdFilter

java.lang.Object
  |
  +--dfischer.femtowebserver.httpd.HttpdFilter
Direct Known Subclasses:
ContentCompressionFilter, HttpDebugFilter, HttpSessionCookieHandler, RestrictedInetAddressFilter

public abstract class HttpdFilter
extends java.lang.Object

A HttpdFilter is an object that allows filtering tasks on either the HTTP request to a resource (a Weblet or static content), or on the HTTP response from a resource, or both.

For every HTTP request, a new instance of the HttpdFilter class will be created and the method filterRequest() will be called before the request will be processes by the Femto Web Server itself. After processing the request, the method filterResponse() will be called before the final output will be transferred to the agent (browser).

An optional capability of a HttpdFilter is to abort the request or the response by calling the method abortRequest(). In such a case a reference to a new (blank) HttpResponse will be given back to the HttpdFilter and the filter itself can override the whole HTTP response from the Femto Web Server by its own new response. If abortRequest() is already called during filterRequest(), the Femto Web Server will not process the originally browser request. The method abortRequest() will break/interrupt all chained filters - the filtering will stop immediately.

That a filter becomes active, it must first be added by calling the method Httpd.addFilter() on the Femto Web Server instance. It's also possible to chain filters by adding more than one. Such chained filters are called in the order where they have been added. The method addFilter() can optionally pass filter configuration parameters to the filter, called filter arguments.

A special feature is also, that filters can be added or removed at runtime whitout stopping the Femto Web Server.

Programming Hint 1: declaring local, non static variables and references at class level allows to transfer internal filter data from the filterRequest() to the filterResponse(). These variables and references have only the same value for a single request/response pair.

Programming Hint 2: please have a look on the already implemented filters ContentCompressionFilter, RestrictedInetAddressFilter, HttpDebugFilter and HttpSessionCookieHandler.
The source code and a configuration example is included in the java doc.

See Also:
Httpd.addFilter(String), Httpd.addFilter(String, String[]), Httpd.removeFilter(java.lang.String), Httpd.getFilterClassNames(), Httpd.getFilterArguments(java.lang.String)

Method Summary
 HttpResponse abortRequest()
          Aborts the current HTTP request or response and overrides the ordinary HTTP response.
abstract  void filterRequest(HttpRequest httpRequest, HttpResponse httpResponse)
          Allows filtering tasks on the HTTP request and to preset the HTTP response (at his time blank).
abstract  void filterResponse(HttpRequest httpRequest, HttpResponse httpResponse)
          Allows filtering tasks on the HTTP response and to access the HTTP request.
 java.lang.String[] getFilterArguments()
          Returns the (optionally) filter arguments.
 HttpdProperties getHttpdProperties()
          Returns the Femto Web Server configuration
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFilterArguments

public java.lang.String[] getFilterArguments()
Returns the (optionally) filter arguments.
See Also:
Httpd.addFilter(String, String[])

getHttpdProperties

public HttpdProperties getHttpdProperties()
Returns the Femto Web Server configuration
Returns:
the Femto Web Server configuration.
See Also:
HttpdProperties.getSessionHashtable()

filterRequest

public abstract void filterRequest(HttpRequest httpRequest,
                                   HttpResponse httpResponse)
                            throws java.lang.Exception
Allows filtering tasks on the HTTP request and to preset the HTTP response (at his time blank). Consider that some or all parts of the HTTP response will later be overwritten when the (modified) request is processed by the Femto Web Server.
Parameters:
httpRequest - The HTTP request data (browser request)
HttpResponse - The HTTP response data (server response)
See Also:
HttpRequest.getSession(), HttpRequest.setSession(dfischer.femtowebserver.httpd.HttpdSession), HttpRequest.getRemoteAddress(), HttpRequest.setRemoteAddress(java.lang.String), HttpRequest.getVirtualHost(), HttpRequest.setVirtualHost(java.lang.String), HttpRequest.getVirtualPort(), HttpRequest.setVirtualPort(int), HttpRequest.getUserAgent(), HttpRequest.setUserAgent(java.lang.String), HttpRequest.getHeaderField(java.lang.String), HttpRequest.addHeaderField(java.lang.String, java.lang.String), HttpRequest.updateHeaderField(java.lang.String, java.lang.String), HttpRequest.removeHeaderField(java.lang.String), HttpRequest.getMethod(), HttpRequest.setMethod(java.lang.String), HttpRequest.getRequest(), HttpRequest.setRequest(java.lang.String), HttpRequest.getParameter(String), HttpRequest.addParameter(java.lang.String, java.lang.String), HttpRequest.updateParameter(java.lang.String, java.lang.String), HttpRequest.removeParameter(java.lang.String), HttpRequest.getContent(), HttpRequest.setContent(byte[]), HttpRequest.clearContent(), HttpRequest.getContentType(), HttpRequest.setContentType(java.lang.String), HttpRequest.getContentSubtype(), HttpRequest.setContentSubtype(java.lang.String)

filterResponse

public abstract void filterResponse(HttpRequest httpRequest,
                                    HttpResponse httpResponse)
                             throws java.lang.Exception
Allows filtering tasks on the HTTP response and to access the HTTP request. Consider that modifying the HTTP request will have no impact to the HTTP response result because the request has been already processed by the Femto Web Server.
Parameters:
httpRequest - The HTTP request data (browser request)
HttpResponse - The HTTP response data (server response)
See Also:
HttpResponse.getSession(), HttpResponse.setSession(dfischer.femtowebserver.httpd.HttpdSession), HttpResponse.getStatus(), HttpResponse.setStatus(int, java.lang.String), HttpResponse.getContentType(), HttpResponse.getContentSubtype(), HttpResponse.setContentType(java.lang.String), HttpResponse.getHeaderField(java.lang.String), HttpResponse.getHeaderFieldNames(), HttpResponse.updateHeaderField(java.lang.String, java.lang.String), HttpResponse.addHeaderField(java.lang.String, java.lang.String), HttpResponse.removeHeaderField(java.lang.String), HttpResponse.getContent(), HttpResponse.getContentAsString(), HttpResponse.setContent(byte[]), HttpResponse.clearContent(), HttpResponse.print(String), HttpResponse.println(String)

abortRequest

public HttpResponse abortRequest()
                          throws java.io.IOException
Aborts the current HTTP request or response and overrides the ordinary HTTP response. Aborts also the execution of all furter chained filters. If this method is called already during filterRequest(), the Femto Web Server will not process the originally browser request
Returns:
reference to a new (blank) HttpResponse which must be used to setup the exceptional response.

Femto Web Server V1.4-F

Copyright 2002, 2003, 2006 by Ingenieurbüro David Fischer GmbH, Switzerland. All rights reserved.