com.cometway.httpd
Class HTTPProxyAgent

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

public class HTTPProxyAgent
extends WebServerExtension
implements java.lang.Runnable

This agent handles proxies to other web servers. A file needs to be provided which lists the full URLs or URIs to proxy and where they should be proxied to. The proxy config file consists of name/value pairs separated by newlines. Lines beginning with the # character are ignored as comments. The value of each name/value pair must be a full URL. The following are some valid name/value pairs that can be used in the config file: /directory=http://www.domain.com/directory.agent /dir/page.html=http://www.domain2.com/index.html http://www.domain.com/index.html=http://www.domain2.com/index.html http://domain.com/index.html=http://www.domain2.com/index.html http://www.anotherdomain.com/=http://www.domain2.com:8080/ Both the name and the value of each name/value pair is assumed to be literal, so they will cnly match the exact path/host of the http request. Loose proxies are ones where the entire path is passed to the proxied host. Loose proxies are denoted as "*=": http://www.domain.com/search/*=http://www.google.com/ In this example, http://www.domain.com/search/ will be proxied to http://www.google.com/ and http://www.domain.com/search/search?q=help will be proxied to http://www.google.com/search?q=help Essentially, everything after the name in the name/value pair, will be passed onto what the value is.


Field Summary
protected  java.util.Hashtable socketHash
           
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
HTTPProxyAgent()
           
 
Method Summary
protected  java.net.Socket getProxySocket(java.lang.String hostname, int port, java.lang.String request)
          This method gets or creates a Socket to a proxy host and sends the HTTP request.
 boolean handleRequest(HTTPAgentRequest request)
          Handles a request and routes through appropriate proxy.
 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: http_proxy.agent), "proxy_file" contains a list of the available proxies (default: ./http.proxy), "check_interval" specifies the time to wait before checking a proxy's status (default: 300000), "initial_wait_time" specifies the time to wait initially before checking a proxy (default: 60000).
 boolean isProxied(java.lang.String path, java.lang.String host)
          Checks to see if a path is Proxied.
 void readProxyFile()
          Reads in Proxy File's information into a database of proxies.
 void returnProxySocket(java.lang.String hostname, int port, java.net.Socket s)
          Returns a keep-alive connection to the SocketHash
 void run()
          Runs and synchronizes object, then checks proxies.
 void start()
          Registers service with Object Manager, reads in Proxy File, and starts a new thread for this object.
 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

socketHash

protected java.util.Hashtable socketHash
Constructor Detail

HTTPProxyAgent

public HTTPProxyAgent()
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: http_proxy.agent), "proxy_file" contains a list of the available proxies (default: ./http.proxy), "check_interval" specifies the time to wait before checking a proxy's status (default: 300000), "initial_wait_time" specifies the time to wait initially before checking a proxy (default: 60000). The proxy_socket_cache_timeout property denotes how long cached sockets should be considered alive (in milliseconds, default: 1000).

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

start

public void start()
Registers service with Object Manager, reads in Proxy File, and starts a new thread for this object.

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

readProxyFile

public void readProxyFile()
Reads in Proxy File's information into a database of proxies.


handleRequest

public boolean handleRequest(HTTPAgentRequest request)
Handles a request and routes through appropriate proxy.

Overrides:
handleRequest in class WebServerExtension

getProxySocket

protected java.net.Socket getProxySocket(java.lang.String hostname,
                                         int port,
                                         java.lang.String request)
This method gets or creates a Socket to a proxy host and sends the HTTP request. If a proxy host could not be reached, the socket will be null.


returnProxySocket

public void returnProxySocket(java.lang.String hostname,
                              int port,
                              java.net.Socket s)
Returns a keep-alive connection to the SocketHash


isProxied

public boolean isProxied(java.lang.String path,
                         java.lang.String host)
Checks to see if a path is Proxied.


run

public void run()
Runs and synchronizes object, then checks proxies.

Specified by:
run in interface java.lang.Runnable