ikrs.httpd.filehandler
Class PHPHandler
java.lang.Object
ikrs.httpd.AbstractFileHandler
ikrs.httpd.filehandler.CGIHandler
ikrs.httpd.filehandler.PHPHandler
- All Implemented Interfaces:
- FileHandler
public class PHPHandler
- extends CGIHandler
This is a PHP file handler. It passes the requested file to the PHP (php-cgi) interpreter
and stores the generated data inside a buffered resource.
Future implementations might send the generated data in runtime (without a buffer), but
that would require a HTTP handler that does not expect the given data length when the
network output starts.
Fields inherited from class ikrs.httpd.filehandler.CGIHandler |
CGI_ENV_AUTH_TYPE, CGI_ENV_CONTENT_LENGTH, CGI_ENV_CONTENT_TYPE, CGI_ENV_DOCUMENT_ROOT, CGI_ENV_GATEWAY_INTERFACE, CGI_ENV_HTTP_, CGI_ENV_PATH_INFO, CGI_ENV_PATH_TRANSLATED, CGI_ENV_QUERY_STRING, CGI_ENV_REMOTE_ADDR, CGI_ENV_REMOTE_HOST, CGI_ENV_REMOTE_IDENT, CGI_ENV_REMOTE_USER, CGI_ENV_REQUEST_METHOD, CGI_ENV_REQUEST_URI, CGI_ENV_SCRIPT_FILENAME, CGI_ENV_SCRIPT_NAME, CGI_ENV_SERVER_NAME, CGI_ENV_SERVER_PORT, CGI_ENV_SERVER_PROTOCOL, CGI_ENV_SERVER_SOFTWARE |
Method Summary |
void |
buildAdditionalCGIEnvironmentVars(HTTPHeaders headers,
java.io.File file,
java.net.URI requestURI,
java.util.Map<java.lang.String,java.lang.String> environment)
Subclasses implementing the method may define additional/optional CGI environment settings. |
java.util.List<java.lang.String> |
buildCGISystemCommand(HTTPHeaders headers,
PostDataWrapper postData,
java.io.File file,
java.net.URI requestURI)
Subclasses implementing this method must return a valid system command that can be executed
directly using Java's ProcessBuilder. |
Resource |
handleCGIOutput(HTTPHeaders headers,
java.io.File file,
java.net.URI requestURI,
PostDataWrapper postData,
ProcessableResource cgiOutput)
After the CGI handler performed the system command the resulting resource must be handled. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PHPHandler
public PHPHandler()
throws java.lang.NullPointerException
- Throws:
java.lang.NullPointerException
buildCGISystemCommand
public java.util.List<java.lang.String> buildCGISystemCommand(HTTPHeaders headers,
PostDataWrapper postData,
java.io.File file,
java.net.URI requestURI)
- Subclasses implementing this method must return a valid system command that can be executed
directly using Java's ProcessBuilder.
The first list element must be the command name itself, all following elements are the command
line arguments.
- Specified by:
buildCGISystemCommand
in class CGIHandler
- Parameters:
headers
- The current request's HTTP headers.postData
- The current request's post data (a data wrapper holding the input stream).file
- The requested file (in the local file system).requestURI
- The request's URI (from headers.getRequestURI()).
- Returns:
- A list representing the system command.
buildAdditionalCGIEnvironmentVars
public void buildAdditionalCGIEnvironmentVars(HTTPHeaders headers,
java.io.File file,
java.net.URI requestURI,
java.util.Map<java.lang.String,java.lang.String> environment)
- Subclasses implementing the method may define additional/optional CGI environment settings.
Note: there is no need to define the standard CGI environment as it is already contained
in the handler's default mapping.
The default vars are:
- AUTH_TYPE
- CONTENT_LENGTH
- CONTENT_TYPE
- GATEWAY_INTERFACE
- HTTP_*
- PATH_INFO
- PATH_TRANSLATED
- QUERY_STRING
- REMOTE_ADDR
- REMOTE_HOST
- REMOTE_IDENT
- REMOTE_USER
- REQUEST_METHOD
- SCRIPT_NAME
- SERVER_NAME
- SERVER_PORT
- SERVER_PROTOCOL
- SERVER_SOFTWARE
See CGI specs or http://graphcomp.com/info/specs/cgi11.html for details.
If the handler requires to overwrite pre-defined environment vars the method may change/remove
the value in the given mapping. Handle with care.
If the implementing handler has no additional environment vars the method may just do nothing.
- Specified by:
buildAdditionalCGIEnvironmentVars
in class CGIHandler
- Parameters:
headers
- The current request's HTTP headers.file
- The requested file (in the local file system).requestURI
- The request's URI (from headers.getRequestURI()).environment
- The current environment settings and the target map.
handleCGIOutput
public Resource handleCGIOutput(HTTPHeaders headers,
java.io.File file,
java.net.URI requestURI,
PostDataWrapper postData,
ProcessableResource cgiOutput)
throws java.io.IOException
- After the CGI handler performed the system command the resulting resource must be handled.
The way the CGI output is handled differs from handler to handler as the underlying ran
command produces different types of output.
So it's up the the handler to process the generated data.
- Specified by:
handleCGIOutput
in class CGIHandler
- Parameters:
headers
- The current request's HTTP headers.file
- The requested file (in the local file system).requestURI
- The request's URI (from headers.getRequestURI()).cgiOutput
- The actual CGI output; use cgiOutput.getEcitValue() to determine the
return code of the CGI program.postDataWrapper
- The sent post data (a wrapper object containing the input stream).
- Returns:
- After the output was processed the returned resource should contain (optional)
header replacements and returned script data.
- Throws:
java.io.IOException