Package sunlabs.brazil.handler
Class CgiHandler
- java.lang.Object
-
- sunlabs.brazil.handler.CgiHandler
-
- All Implemented Interfaces:
Handler
public class CgiHandler extends java.lang.Object implements Handler
Handler for implementing cgi/1.1 interface. This implementation allows either suffix matching (e.g. .cgi) to identify cgi scripts, or prefix matching (e.g. /bgi-bin). Defaults to "/". All output from the cgi script is buffered (e.g. chunked encoding is not supported).
NOTE: in versions of Java prior to release 1.3, the ability to set a working directory when running an external process is missing. This handler automatically checks for this ability and sets the proper working directory, but only if the underlying VM supports it.The following request properties are used:
- root
- The document root for cgi files
- suffix
- The suffix for cgi files (defaults to .cgi)
- prefix
- The prefix for all cgi files (e.g. /cgi-bin)
- url
- "o(riginal)" or "c(urrent)". If an upstream handler has changed the URL, this specifes which url to look for the cgi script relative to. The default is to use the original url.
- custom
- set to "true" to enable custom environment variables.
If set, all server properties starting with this handler's
prefix are placed into the environment with the name:
CONFIG_name
, where name is the property key, in upper case, with the prefix removed. This allows cgi scripts to be customized in the server's configuration file. - runwith
- The command to use to run scripts. The absolute file path is added as the last parameter. If not specified, the file name is run as the command.
- noheaders
- According to the CGI spec, cgi documents are to begin with properly formed http headers to specifie the type, return status and optionally other meta information about the request. if "noheaders" is specified, then the content is expected to *not* have any http headers, and the content type is as implied by the url suffix.
- Version:
- 2.4, 06/06/14
- Author:
- Stephen Uhler
-
-
Constructor Summary
Constructors Constructor Description CgiHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
init(Server server, java.lang.String prefix)
One time initialization.boolean
respond(Request request)
Dispatch and handle the CGI request.
-
-
-
Method Detail
-
init
public boolean init(Server server, java.lang.String prefix)
One time initialization. The handler configuration properties are extracted and set inrespond(Request)
to allow upstream handlers to modify the parameters.- Specified by:
init
in interfaceHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
should not be used.
-
respond
public boolean respond(Request request)
Dispatch and handle the CGI request. Gets called on ALL requests. Set up the environment, exec the process, and deal appropriately with the input and output. In this implementation, all cgi script files must end with a standard suffix, although the suffix may omitted from the url. The url /main/do/me/too?a=b will look, starting in DocRoot, for main.cgi, main/do.cgi, etc until a matching file is found.Input parameters examined in the request properties:
- Suffix
- The suffix for all cgi scripts (defaults to .cgi)
- DocRoot
- The document root, for locating the script.
-
-