Package org.bzdev.net

Interface ServletAdapter


public interface ServletAdapter
Servlet-adapter interface. This interface is used by ServletWebMap to implement it's application-specific behavior, and can readily be used by a servlet for the same purpose. This allows code to be written for an embedded web server (EJWS) and then moved easily to a different web server that supports servlets.

The methods that ServletAdapter provides are modeled after the methods provided by HttpServlet, with HttpServerRequest replacing HttpServletRequest and HttpServerResponse replacing HttpServletResponse. ServletAdapter implements a subset of the methods that HttpServlet provides: the class EmbeddedWebServer automatically handles the HTTP TRACE method, and the FileHandler class handles the HTTP OPTIONS method. The WebMap.Info class, which implements HttpServerResponse, will provide a 'bit bucket' output stream when there is an HTTP HEAD request so that the request can be otherwise treated as an HTTP GET request. An implementation of ServletAdapter should consequently ensure that doGet(HttpServerRequest,HttpServerResponse) is both idempotent and safe.

For servlets, one can either port an implementation of ServletAdapter, or one can use the class EncapsulatingServlet to create a servlet's whose behavior is that provided by a ServletAdapter.

Porting a servlet adapter to create a servlet requires the following changes (this is not an exhaustive list):

Porting a servlet adapter, rather then using EncapsulatingServlet to create a servlet from a servlet adapter, takes more effort and results in two classes to maintain instead of one. On the other hand, porting a servlet can result in a smaller code base when an application is deployed, particularly if the servlet does not require any classes that the BZDev class library provides.
See Also: