Class CGI

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.eclipse.jetty.servlets.CGI
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class CGI extends javax.servlet.http.HttpServlet
CGI Servlet.

The following init parameters are used to configure this servlet:

cgibinResourceBase
Path to the cgi bin directory if set or it will default to the resource base of the context.
resourceBase
An alias for cgibinResourceBase.
cgibinResourceBaseIsRelative
If true then cgibinResourceBase is relative to the webapp (eg "WEB-INF/cgi")
commandPrefix
may be used to set a prefix to all commands passed to exec. This can be used on systems that need assistance to execute a particular file type. For example on windows this can be set to "perl" so that perl scripts are executed.
Path
passed to the exec environment as PATH.
ENV_*
used to set an arbitrary environment variable with the name stripped of the leading ENV_ and using the init parameter value
useFullPath
If true, the full URI path within the context is used for the exec command, otherwise a search is done for a partial URL that matches an exec Command
ignoreExitState
If true then do not act on a non-zero exec exit status")
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    private utility class that manages the Environment passed to exec.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
     
    private String
     
    private File
     
    private CGI.EnvList
     
    private boolean
     
    private boolean
     
    private String
     
    private boolean
     
    private boolean
     
    private static final Logger
     
    private static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CGI()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    exec(File command, String pathInfo, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
    executes the CGI process
    private static String
    Utility method to get a line of text from the input stream.
    void
     
    void
    service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
     
    private static void
    writeProcessInput(Process p, InputStream input, int len)
     
    private static void
     

    Methods inherited from class javax.servlet.http.HttpServlet

    doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service

    Methods inherited from class javax.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • LOG

      private static final Logger LOG
    • _ok

      private boolean _ok
    • _docRoot

      private File _docRoot
    • _cgiBinProvided

      private boolean _cgiBinProvided
    • _path

      private String _path
    • _cmdPrefix

      private String _cmdPrefix
    • _useFullPath

      private boolean _useFullPath
    • _env

      private CGI.EnvList _env
    • _ignoreExitState

      private boolean _ignoreExitState
    • _relative

      private boolean _relative
  • Constructor Details

    • CGI

      public CGI()
  • Method Details

    • init

      public void init() throws javax.servlet.ServletException
      Overrides:
      init in class javax.servlet.GenericServlet
      Throws:
      javax.servlet.ServletException
    • service

      public void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, IOException
      Overrides:
      service in class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
      IOException
    • exec

      private void exec(File command, String pathInfo, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException
      executes the CGI process
      Parameters:
      command - the command to execute, this command is prefixed by the context parameter "commandPrefix".
      pathInfo - The PATH_INFO to process, see http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getPathInfo%28%29. Cannot be null
      req - the HTTP request
      res - the HTTP response
      Throws:
      IOException - if the execution of the CGI process throws
    • writeProcessInput

      private static void writeProcessInput(Process p, String input)
    • writeProcessInput

      private static void writeProcessInput(Process p, InputStream input, int len)
    • getTextLineFromStream

      private static String getTextLineFromStream(InputStream is) throws IOException
      Utility method to get a line of text from the input stream.
      Parameters:
      is - the input stream
      Returns:
      the line of text
      Throws:
      IOException - if reading from the input stream throws