au.com.lastweekend.cgi
Class CGIProcess

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

public class CGIProcess
extends java.lang.Object
implements CGI

Note. Processes are inherently dangerous and prone to blocking and unrecoverable deadlocks. This class does NOTHING to work around this problem.

The particular scenario is your request sends a lot of content, more than can be buffered by the OS. The CGI script ignores this content and sends a lot of output...

This class will block waiting for the content on stdin to be read by the CGI script, and the CGI script is blocked waiting for something to read stdout = Deadlock.

Version:
$Id: CGIProcess.java 123 2008-12-20 09:57:46Z lwoggardner $
Author:
ggardner

Field Summary
protected static int BUFFER_SIZE
           
 
Constructor Summary
CGIProcess()
           
CGIProcess(java.lang.String cmdPrefix)
           
 
Method Summary
 void exec(java.io.File scriptFile, 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

BUFFER_SIZE

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

CGIProcess

public CGIProcess()

CGIProcess

public CGIProcess(java.lang.String cmdPrefix)
Method Detail

exec

public void exec(java.io.File scriptFile,
                 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:
scriptFile - The script.
env - CGI arguments
Throws:
CGIException

getStandardOutput

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

getExitCode

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

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

terminate

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

Specified by:
terminate in interface CGI


Copyright © 2008. All Rights Reserved.