com.cometway.httpd
Class HTTPRedirectAgent

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.HTTPRedirectAgent
All Implemented Interfaces:
AgentInterface, HasStateMachineModel, java.lang.Runnable

public class HTTPRedirectAgent
extends WebServerExtension
implements java.lang.Runnable

This Request Agent is used by the WebServer. The WebServer uses this agent to determine whether a web request should be redirected and if so, the request is given to this agent for it to handle. This agent requires a file which lists the requests which to redirect. Requests with more than one redirect (listed in the file) will be cycled. The file format is name/value pairs delimited by newlines and lines starting with '#' are ignored. There are 2 kinds of name/value pairs used in the redirect config file. The first is a direct mapping in the format NAME=VALUE. This mapping tells the redirect agent what PATH should be redirected to what PATH. The PATH can consist of a full URL or the full URI path. The following are examples of valid direct mapped name/value pairs: /page.html=/redirected_page.html /directory/=http://www.myotherdomain.com/directory2/ http://www.mydomain.com/mydir/=http://web1.mydomain.com/mydir2/page.html This, however, would not be a valid name/value pair: http://www.domain.com/page.html=/page2.html A direct mapped name which contains a host must have a host in its value. A direct mapping will not recurse subdirectories in a path and each path is regarded as literal. Direct mapped names can by mapped to multiple values if the values are separated by commas. The redirect agent will cycle through the different paths given as the value. The second kind of mapping maps only hosts to hosts, and passes the path along for the mapped host. This is an example of a host mapping: http://myhost.com>http://www.myhost.com No path information is included in the syntax of this mapping, only the host names. Any path intended for myhost.com will be mapped to the host www.myhost.com. This mapping is especially useful when the webserver is multihomed. Multiple hosts can all by mapped to a single host. Cycles in the redirect mappings are not checked, if the redirect mapping has cycles there will be an infinite loop of redirects.


Field Summary
protected  boolean stopRunning
           
protected  java.lang.Object syncObject
           
protected  java.lang.Thread thread
           
 
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
HTTPRedirectAgent()
           
 
Method Summary
 boolean handleRequest(HTTPAgentRequest request)
          This will be called by the WebServer (specifically the ConnectionKMethod) to handle an HTTPAgentRequest.
 void initProps()
          Override this method to initialize this agent's properties before it is started.
 boolean isRedirected(java.lang.String path, java.lang.String host)
           
 void readRedirectFile()
           
 void run()
           
 void start()
          This method inherited from com.cometway.ak.ServiceAgent includes functionality to register itself with the WebServer (temporary).
 void stop()
          Unregisters this instance with the service manager using the service_name property.
 
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

stopRunning

protected boolean stopRunning

thread

protected java.lang.Thread thread

syncObject

protected java.lang.Object syncObject
Constructor Detail

HTTPRedirectAgent

public HTTPRedirectAgent()
Method Detail

initProps

public void initProps()
Description copied from class: Agent
Override this method to initialize this agent's properties before it is started.

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

start

public void start()
Description copied from class: WebServerExtension
This method inherited from com.cometway.ak.ServiceAgent includes functionality to register itself with the WebServer (temporary).

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

stop

public void stop()
Description copied from class: ServiceAgent
Unregisters this instance with the service manager using the service_name property.

Specified by:
stop in interface AgentInterface
Overrides:
stop in class ServiceAgent

readRedirectFile

public void readRedirectFile()

handleRequest

public boolean handleRequest(HTTPAgentRequest request)
Description copied from class: WebServerExtension
This will be called by the WebServer (specifically the ConnectionKMethod) to handle an HTTPAgentRequest. If the request has been handled, true is returned and no other WebServerExtensions will be used.

Overrides:
handleRequest in class WebServerExtension

isRedirected

public boolean isRedirected(java.lang.String path,
                            java.lang.String host)

run

public void run()
Specified by:
run in interface java.lang.Runnable