com.cometway.httpd
Class HTTPFileServerAgent

java.lang.Object
  extended by com.cometway.props.Props
      extended by com.cometway.ak.Agent
          extended by com.cometway.ak.ServiceAgent
              extended by com.cometway.httpd.WebServerExtension
                  extended by com.cometway.httpd.HTTPFileServerAgent
All Implemented Interfaces:
AgentInterface, HasStateMachineModel
Direct Known Subclasses:
HTTPThrottledFileServer

public class HTTPFileServerAgent
extends WebServerExtension

This agent is used by the WebServer to handle requests for HTML files and other static documents from the file system.


Field Summary
protected  java.lang.String html_directory
           
 
Fields inherited from class com.cometway.ak.Agent
agent_id, agentController, CREATING_STATE, debugReporter, DESTROYED_STATE, DESTROYING_STATE, errorReporter, FAILED_STATE, printlnReporter, props, RUNNING_STATE, STARTING_STATE, STOPPED_STATE, STOPPING_STATE, warningReporter
 
Constructor Summary
HTTPFileServerAgent()
           
 
Method Summary
 java.lang.String generateDirectoryList(java.io.File file, java.lang.String path)
          Generates a directory Listing.
 boolean handleRequest(HTTPAgentRequest request)
          Writes the entire http response header.
 void initProps()
          Initializes this agent's properties by providing default values for each of the following missing properties: "service_name" is used to register this agent with the Service Manager (default: HTTPFileServerAgent), "html_directory" points to the root directory where HTML files are served (default: ./), "default_index" is the default file served when no filename is specified, can be more than one index (default: index.html), "allow_directory_lists" when enabled, allows this agent to display links to files in a directory (default: yes) "domains" used for registering extension, can be more than one domain (default: default)
 boolean isKeepAlive(AgentRequest request)
          Checks if the request given asks for a keep-alive
protected  void printRedirect(HTTPAgentRequest request, java.lang.String path, boolean keepAlive)
          Prints redirect information for a site to HTML output.
protected  void sendFile(java.io.File file, HTTPAgentRequest request)
           
 void start()
          Registers Server and sets up directories, url's, etc.
 
Methods inherited from class com.cometway.ak.ServiceAgent
stop
 
Methods inherited from class com.cometway.ak.Agent
currentStateEquals, debug, destroy, error, error, getAgentController, getDateTimeStr, getProps, getServiceImpl, getStateMachineModel, println, register, registerService, setAgentController, setProps, toString, unregister, unregisterService, warning, warning
 
Methods inherited from class com.cometway.props.Props
addListener, append, copy, copyFrom, copyTo, decrementInteger, dump, enableListeners, enumerateKeys, format, getBoolean, getByteArray, getCharacter, getDate, getDate, getDateString, getDouble, getFloat, getHexString, getInteger, getKeys, getLong, getNextKey, getProperty, getProperty, getPropsContainer, getSize, getString, getString, getTokens, getTokens, getTrimmedString, getVector, hasProperty, incrementInteger, insertProps, loadProps, notifyPropsChanged, notifyPropsChangedIgnore, notifyPropsChangedIgnore, parse, propertyMatchesRegEx, readFromFile, regExPropertyMatches, removeAll, removeListener, removeProperty, resumeNotify, saveProps, set, setBoolean, setCharacter, setDefault, setDouble, setFloat, setInteger, setLong, setProperty, setProperty, setProperty, setPropsContainer, suspendNotify, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

html_directory

protected java.lang.String html_directory
Constructor Detail

HTTPFileServerAgent

public HTTPFileServerAgent()
Method Detail

initProps

public void initProps()
Initializes this agent's properties by providing default values for each of the following missing properties: "service_name" is used to register this agent with the Service Manager (default: HTTPFileServerAgent), "html_directory" points to the root directory where HTML files are served (default: ./), "default_index" is the default file served when no filename is specified, can be more than one index (default: index.html), "allow_directory_lists" when enabled, allows this agent to display links to files in a directory (default: yes) "domains" used for registering extension, can be more than one domain (default: default)

Specified by:
initProps in interface AgentInterface
Overrides:
initProps in class Agent

start

public void start()
Registers Server and sets up directories, url's, etc.

Specified by:
start in interface AgentInterface
Overrides:
start in class WebServerExtension

printRedirect

protected void printRedirect(HTTPAgentRequest request,
                             java.lang.String path,
                             boolean keepAlive)
Prints redirect information for a site to HTML output. Takes AgentRequest and String path as input.


isKeepAlive

public boolean isKeepAlive(AgentRequest request)
Checks if the request given asks for a keep-alive


handleRequest

public boolean handleRequest(HTTPAgentRequest request)
Writes the entire http response header.

Overrides:
handleRequest in class WebServerExtension

sendFile

protected void sendFile(java.io.File file,
                        HTTPAgentRequest request)
                 throws java.io.IOException
Throws:
java.io.IOException

generateDirectoryList

public java.lang.String generateDirectoryList(java.io.File file,
                                              java.lang.String path)
Generates a directory Listing. Takes File and String path as input.