Jetty/Feature/Servlets Bundled with Jetty

From Eclipsepedia

Jump to: navigation, search



Contents

Introduction

Jetty ships with a bundle of servlets that interact with the key classes. Most are in the org.eclipse.jetty.servlets package. These servlets are among the principle elements of Jetty as a component-based infrastructure that holds and runs J2EE applications. As described below, they play a major role in running and maintaining the Jetty server. For more information, see Servlets javadoc for the package.

Feature

GzipFilter

The Jetty GzipFilter is a compression filter that you can apply to almost any dynamic resource (servlet). It fixes many of the bugs in commonly available compression filters–for example, it handles all ways to set content length. We have tested it with Jetty continuations and suspending requests. Some user-agents might be excluded from compression to avoid common browser bugs (yes, this means IE!). See GzipFilter javadoc.

MultiPartFilter

The MultiPartFilter class implements the Filter interface that the web container calls. It acts as a decoder of the mulitpart/form-data stream that an HTML form sends using a file input item. It stores any files an HTML form sends to a temporary location. It also adds a file object to the request, which acts as an attribute. Other values are available through the usual getParameter API, and the setCharacterEncoding mechanism is respected when converting bytes to strings. See MultiPartFilter javadoc.

NoJspServlet

This NoJsp servlet extends the abstract class HttpServlet; it displays the code 500 error message "JSP support not configured." See NojspServlet javadoc.

ProxyServlet

ProxyServlet is an experimental effort that implements the Servlet interface. It acts as an authorized servlet on behalf on another running servlet. It is not a substitute for the running servlet, but provides a mirror for the service. See ProxyServlet javadoc.

QoSFilter

The Quality of Service Filter limits the number of active requests to the number set by the "maxRequests" init parameter (default 10). If more requests than the set value are received, they are suspended and placed in priority queues. The getPriority(ServletRequest) method determines priorities, which are a value between zero and the value in the "maxPriority" init parameter (default 10), with higher values having higher priority.

This filter prevents wasting threads waiting for slow/limited resources such as a JDBC connection pool. It avoids consuming all of a container's thread pool. It also uses a priority system when resuming waiting requests. For example, consider a filter with a maxRequest limit slightly smaller than the container's thread pool, and a high priority allocated to admin users. Regardless of load, admin users are always able to access the web application. A semaphore polices the maxRequest limit, and the filter waits briefly while attempting to acquire the semaphore. Th "waitMS" init parameter controls waiting, avoiding the expense of a suspend if the semaphore is quickly available. If the system cannot obtain the semaphore, the request is suspended for the default suspend period of the container or the value set in the "suspendMs" init parameter. See QoSFilter javadoc.

DoSFilter

This has been replaced by the QoSFilter.

WelcomeFilter

The WelcomeFilter is another servlet that also implements the Filter interface. It forwards any servlets to the necessary welcome display of an application when serviced. See WelcomeFilter javadoc.

DefaultServlet

The DefaultServlet implements the ResourceFactory interface and extends the HttpServlet abstract class. It is usually mapped to / and provides handling for static content, OPTION and TRACE methods for the context. The MOVE method is allowed if PUT and DELETE are allowed. See DefaultServlet javadoc.

Jetty supports the following initParameters:

acceptRanges–If true, range requests and responses are supported.
dirAllowed–If true, directory listings are returned if no welcome file is found. 
  Otherwise 403 Forbidden displays.
redirectWelcome–If true, welcome files are redirected rather that forwarded.
gzip–If set to true, then static content is served as gzip content encoded if a matching 
  resource is found ending with ".gz".
resourceBase–Set to replace the context resource base.
aliases–If true, aliases of resources are allowed (that is, symbolic links and caps variations) 
  and may bypass security constraints.
maxCacheSize–Maximum total size of the cache or 0 for no cache.
maxCachedFileSize–Maximum size of a file to cache.
maxCachedFiles–Maximum number of files to cache.
useFileMappedBuffer–If set to true, mapped file buffer serves static content when using 
  NIO connector. Setting this value to false means that a direct buffer is used instead of a mapped file buffer. 
  By default, this is set to true.

CGI

The CGI servlet class extends the abstract HttpServlet class. When the init parameter is called, the cgi bin directory is set with the cgibinResourceBase. Otherwise, it defaults to the resource base of the context. See CGI javadoc.

The cgi bin uses three parameters:

commandPrefix–The init parameter obtained when there is a prefix set to all commands directed to the method exec.
Path–An init parameter passed to the exec environment as a PATH. This must be run unpacked 
  somewhere in the filesystem.
ENV_ –An init parameter that points to an environment variable with the name stripped of the
  leading ENV_ and using the init parameter value.