au.com.lastweekend.cgi
Class FastCGI

java.lang.Object
  extended by au.com.lastweekend.cgi.FastCGI
All Implemented Interfaces:
CGI

public class FastCGI
extends java.lang.Object
implements CGI

Brute force implementation of Fast CGI in that it creates a new client socket for every request. Other possibilities.

  • Use one socket per thread.
  • Would save the socket creation/destruction overhead but with more complicated socket recovery.
  • Use one socket globally with a request id per thread
  • Would need to read the socket in a global thread and then pass content on to waiting threads. Can't see any reason for wanting to do that as the spec requires the server application to handle this already

    Version:
    $Id: FastCGI.java 100 2008-02-19 10:37:27Z lwoggardner $
    Author:
    Grant Gardner

    Field Summary
    protected static byte FCGI_ABORT_REQUEST
               
    protected static byte FCGI_AUTHORIZER
               
    protected static byte FCGI_BEGIN_REQUEST
               
    protected static byte FCGI_CANT_MPX_CONN
               
    protected static byte FCGI_DATA
               
    protected static byte FCGI_END_REQUEST
               
    protected static byte FCGI_FILTER
               
    protected static byte FCGI_GET_VALUES
               
    protected static byte FCGI_GET_VALUES_RESULT
               
    protected static int FCGI_KEEP_CONN
               
    protected static int FCGI_MAX_CONTENT_LENGTH
               
    protected static int FCGI_MAX_PADDING_LENGTH
               
    protected static byte FCGI_OVERLOADED
               
    protected static byte FCGI_PARAMS
               
    protected static byte FCGI_REQUEST_COMPLETE
               
    protected static byte FCGI_RESPONDER
               
    protected static byte FCGI_STDERR
               
    protected static byte FCGI_STDIN
               
    protected static byte FCGI_STDOUT
               
    protected static byte FCGI_UNKNOWN_ROLE
               
    protected static byte FCGI_UNKNOWN_TYPE
               
    protected static int FCGI_VERSION
               
     
    Constructor Summary
    FastCGI(java.net.Socket socket, int requestId)
               
     
    Method Summary
     void exec(java.io.File script, java.util.Map<java.lang.String,java.lang.String> env)
              Execute the CGI script
     int getExitCode()
               
     java.io.InputStream getStandardOutput()
               
     void pipeInput(java.io.InputStream in, int contentLength)
              Send request input to the CGI process
     void terminate()
              Causes any CGI related system resources to be returned.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    FCGI_VERSION

    protected static final int FCGI_VERSION
    See Also:
    Constant Field Values

    FCGI_BEGIN_REQUEST

    protected static final byte FCGI_BEGIN_REQUEST
    See Also:
    Constant Field Values

    FCGI_ABORT_REQUEST

    protected static final byte FCGI_ABORT_REQUEST
    See Also:
    Constant Field Values

    FCGI_END_REQUEST

    protected static final byte FCGI_END_REQUEST
    See Also:
    Constant Field Values

    FCGI_PARAMS

    protected static final byte FCGI_PARAMS
    See Also:
    Constant Field Values

    FCGI_STDIN

    protected static final byte FCGI_STDIN
    See Also:
    Constant Field Values

    FCGI_STDOUT

    protected static final byte FCGI_STDOUT
    See Also:
    Constant Field Values

    FCGI_STDERR

    protected static final byte FCGI_STDERR
    See Also:
    Constant Field Values

    FCGI_DATA

    protected static final byte FCGI_DATA
    See Also:
    Constant Field Values

    FCGI_GET_VALUES

    protected static final byte FCGI_GET_VALUES
    See Also:
    Constant Field Values

    FCGI_GET_VALUES_RESULT

    protected static final byte FCGI_GET_VALUES_RESULT
    See Also:
    Constant Field Values

    FCGI_UNKNOWN_TYPE

    protected static final byte FCGI_UNKNOWN_TYPE
    See Also:
    Constant Field Values

    FCGI_KEEP_CONN

    protected static final int FCGI_KEEP_CONN
    See Also:
    Constant Field Values

    FCGI_RESPONDER

    protected static final byte FCGI_RESPONDER
    See Also:
    Constant Field Values

    FCGI_AUTHORIZER

    protected static final byte FCGI_AUTHORIZER
    See Also:
    Constant Field Values

    FCGI_FILTER

    protected static final byte FCGI_FILTER
    See Also:
    Constant Field Values

    FCGI_REQUEST_COMPLETE

    protected static final byte FCGI_REQUEST_COMPLETE
    See Also:
    Constant Field Values

    FCGI_CANT_MPX_CONN

    protected static final byte FCGI_CANT_MPX_CONN
    See Also:
    Constant Field Values

    FCGI_OVERLOADED

    protected static final byte FCGI_OVERLOADED
    See Also:
    Constant Field Values

    FCGI_UNKNOWN_ROLE

    protected static final byte FCGI_UNKNOWN_ROLE
    See Also:
    Constant Field Values

    FCGI_MAX_CONTENT_LENGTH

    protected static final int FCGI_MAX_CONTENT_LENGTH
    See Also:
    Constant Field Values

    FCGI_MAX_PADDING_LENGTH

    protected static final int FCGI_MAX_PADDING_LENGTH
    See Also:
    Constant Field Values
    Constructor Detail

    FastCGI

    public FastCGI(java.net.Socket socket,
                   int requestId)
    Method Detail

    exec

    public void exec(java.io.File script,
                     java.util.Map<java.lang.String,java.lang.String> env)
              throws CGIException
    Description copied from interface: CGI
    Execute the CGI script

    Specified by:
    exec in interface CGI
    Parameters:
    script - The script.
    env - CGI arguments
    Throws:
    CGIException

    pipeInput

    public void pipeInput(java.io.InputStream in,
                          int contentLength)
                   throws java.io.IOException
    Description copied from interface: CGI
    Send request input to the CGI process

    Specified by:
    pipeInput in interface CGI
    contentLength - in bytes
    Throws:
    java.io.IOException

    getStandardOutput

    public java.io.InputStream getStandardOutput()
                                          throws java.io.IOException
    Specified by:
    getStandardOutput in interface CGI
    Returns:
    The standard output of the CGI process as an input stream.
    Throws:
    java.io.IOException

    terminate

    public void terminate()
    Description copied from interface: CGI
    Causes any CGI related system resources to be returned.

    Specified by:
    terminate in interface CGI

    getExitCode

    public int getExitCode()
    Specified by:
    getExitCode in interface CGI
    Returns:
    the exit code from the CGI script


    Copyright © 2008. All Rights Reserved.