## org.apache.catalina.util
Class CGIProcessEnvironment

    java.lang.Object
      org.apache.catalina.util.ProcessEnvironment
          org.apache.catalina.util.CGIProcessEnvironment

public class CGIProcessEnvironment
extends ProcessEnvironment

Encapsulates the CGI Process' environment and rules to derive that environment from the servlet container and request information.

Since:
  Tomcat 4.0
Version:
  $Revision: 1.4 $, $Date: 2004/05/26 16:20:54 $
Author:
  Martin Dengler [root@martindengler.com]

Field Summary

Fields inherited from class org.apache.catalina.util.ProcessEnvironment
`command, debug, env, pathInfo, valid, workingDirectory`

Constructor Summary
`CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req, javax.servlet.ServletContext context)` Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.
`CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req, javax.servlet.ServletContext context, int debug)` Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.
`CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req, javax.servlet.ServletContext context, java.lang.String cgiPathPrefix)` Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.
`CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req, javax.servlet.ServletContext context, java.lang.String cgiPathPrefix, int debug)` Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.

Method Summary
`protected boolean` `deriveProcessEnvironment(javax.servlet.http.HttpServletRequest req)` Constructs the CGI environment to be supplied to the invoked CGI script; relies heavliy on Servlet API methods and findCGI
`protected java.lang.String[]` `findCGI(java.lang.String pathInfo, java.lang.String webAppRootDir, java.lang.String contextPath, java.lang.String servletPath, java.lang.String cgiPathPrefix)` Resolves core information about the cgi script.
`java.util.Hashtable` `getParameters()` Gets process' derived query parameters
`java.lang.String` `toString()` Print important CGI environment information in an easy-to-read HTML table

Methods inherited from class org.apache.catalina.util.ProcessEnvironment
`blanksToString, getCommand, getContext, getContextPath, getEnvironment, getServletPath, getWebAppRootDir, getWorkingDirectory, isValid, log, nullsToBlanks, nullsToString, setCommand, setEnvironment, setupFromContext, setupFromRequest`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### CGIProcessEnvironment

    public CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req,
                                 javax.servlet.ServletContext context)

  Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc. The cgi path prefix is initialized to "" (the empty string).

Parameters:
  `req` - HttpServletRequest for information provided by the Servlet API
  `context` - ServletContext for information provided by the Servlet API

### CGIProcessEnvironment

    public CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req,
                                 javax.servlet.ServletContext context,
                                 java.lang.String cgiPathPrefix)

  Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.

Parameters:
  `req` - HttpServletRequest for information provided by the Servlet API
  `context` - ServletContext for information provided by the Servlet API
  `cgiPathPrefix` - subdirectory of webAppRootDir below which the web app's CGIs may be stored; can be null or "".

### CGIProcessEnvironment

    public CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req,
                                 javax.servlet.ServletContext context,
                                 int debug)

  Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.

Parameters:
  `req` - HttpServletRequest for information provided by the Servlet API
  `context` - ServletContext for information provided by the Servlet API
  `debug` - int debug level (0 == none, 6 == lots)

### CGIProcessEnvironment

    public CGIProcessEnvironment(javax.servlet.http.HttpServletRequest req,
                                 javax.servlet.ServletContext context,
                                 java.lang.String cgiPathPrefix,
                                 int debug)

  Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.

Parameters:
  `req` - HttpServletRequest for information provided by the Servlet API
  `context` - ServletContext for information provided by the Servlet API
  `cgiPathPrefix` - subdirectory of webAppRootDir below which the web app's CGIs may be stored; can be null or "".
  `debug` - int debug level (0 == none, 6 == lots)

Method Detail

### deriveProcessEnvironment

    protected boolean deriveProcessEnvironment(javax.servlet.http.HttpServletRequest req)

  Constructs the CGI environment to be supplied to the invoked CGI script; relies heavliy on Servlet API methods and findCGI

  Overrides:
    `deriveProcessEnvironment` in class `ProcessEnvironment`
  Parameters:
    `req` - request associated with the CGI invokation
  Returns:
    true if environment was set OK, false if there was a problem and no environment was set

### findCGI

    protected java.lang.String[] findCGI(java.lang.String pathInfo,
                                         java.lang.String webAppRootDir,
                                         java.lang.String contextPath,
                                         java.lang.String servletPath,
                                         java.lang.String cgiPathPrefix)

  Resolves core information about the cgi script.

  Example URI:

       /servlet/cgigateway/dir1/realCGIscript/pathinfo1

  - path = $CATALINA_HOME/mywebapp/dir1/realCGIscript
  - scriptName = /servlet/cgigateway/dir1/realCGIscript
  - cgiName = /dir1/realCGIscript
  - name = realCGIscript

  CGI search algorithm: search the real path below <my-webapp-root> and find the first non-directory in the getPathTranslated("/"), reading/searching from left-to-right.

  The CGI search path will start at webAppRootDir + File.separator + cgiPathPrefix (or webAppRootDir alone if cgiPathPrefix is null).

  cgiPathPrefix is usually set by the calling servlet to the servlet's cgiPathPrefix init parameter

  Parameters:
    `pathInfo` - String from HttpServletRequest.getPathInfo()
    `webAppRootDir` - String from context.getRealPath("/")
    `contextPath` - String as from HttpServletRequest.getContextPath()
    `servletPath` - String as from HttpServletRequest.getServletPath()
    `cgiPathPrefix` - subdirectory of webAppRootDir below which the web app's CGIs may be stored; can be null.
  Returns:
    - `path` - full file-system path to valid cgi script, or null if no cgi was found
    - `scriptName` - CGI variable SCRIPT_NAME; the full URL path to valid cgi script or null if no cgi was found
    - `cgiName` - servlet pathInfo fragment corresponding to the cgi script itself, or null if not found
    - `name` - simple name (no directories) of the cgi script, or null if no cgi was found
  Since:
    Tomcat 4.0

### toString

    public java.lang.String toString()

  Print important CGI environment information in an easy-to-read HTML table

  Overrides:
    `toString` in class `ProcessEnvironment`
  Returns:
    HTML string containing CGI environment info

### getParameters

    public java.util.Hashtable getParameters()

  Gets process' derived query parameters

  Returns:
    process' query parameters

Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.