rabbit.proxy
Class HttpProxy

java.lang.Object
  extended by rabbit.proxy.HttpProxy

public class HttpProxy
extends Object

A filtering and caching http proxy.

Author:
Robert Olofsson

Field Summary
protected  boolean proxySSL
          Are we allowed to proxy ssl?
protected  List<Integer> sslports
          The List of acceptable ssl-ports.
static String VERSION
          Current version
 
Constructor Summary
HttpProxy()
          Create a new HttpProxy.
 
Method Summary
 void addCurrentConnection(Connection con)
          Add a current connection
 BufferHandler getBufferHandler()
          Get the BufferHandler this proxy is using
 Cache<HttpHeader,HttpHeader> getCache()
          Get the cache that this proxy is currently using.
 rabbit.proxy.ClientTrafficLoggerHandler getClientTrafficLoggerHandler()
          Get the ClientTrafficLoggerHandler
 Config getConfig()
          Get the configuration of the proxy.
 ConnectionHandler getConnectionHandler()
          Get the connection handler.
 Counter getCounter()
          Get the current Counter
 List<Connection> getCurrentConnections()
          Get all the current connections
 InetAddress getHost()
          Get the local host.
 HttpGeneratorFactory getHttpGeneratorFactory()
          Get the current HttpGeneratorFactory.
 NioHandler getNioHandler()
          Get the NioHandler that this proxy is using.
 long getOffset()
          Get the time offset, that is the time between GMT and local time.
 int getPort()
          Get the port this proxy is using.
 ProxyChain getProxyChain()
          Get the ProxyChain this proxy is currently using
 String getServerIdentity()
          Get the current server identity.
 long getStartTime()
          Get the time this proxy was started.
 boolean getStrictHttp()
          Check if strict http is turned on or off.
 TrafficLoggerHandler getTrafficLoggerHandler()
          Get the currently transferred traffic statistics.
 String getVersion()
          Get the version of this proxy.
 void getWebConnection(HttpHeader header, WebConnectionListener wcl)
          Get a WebConnection.
 boolean isSelf(String uhost, int urlport)
          Try hard to check if the given address matches the proxy.
<T> Class<? extends T>
load3rdPartyClass(String name, Class<T> type)
          Load a 3:rd party class.
 void markForPipelining(WebConnection wc)
          Mark a WebConnection for pipelining.
 void releaseWebConnection(WebConnection wc)
          Release a WebConnection so that it may be reused if possible.
 void removeCurrentConnection(Connection con)
          Remove a current connection.
 void setConfig(String conf)
          Set the config file to use for this proxy.
 void setStrictHttp(boolean b)
          Toogle the strict http flag.
 void start()
          Run the proxy in a separate thread.
 void stop()
          Run the proxy in a separate thread.
protected  void updateTrafficLog(TrafficLoggerHandler tlh)
          Update the currently transferred traffic statistics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Current version

See Also:
Constant Field Values

proxySSL

protected boolean proxySSL
Are we allowed to proxy ssl?


sslports

protected List<Integer> sslports
The List of acceptable ssl-ports.

Constructor Detail

HttpProxy

public HttpProxy()
          throws UnknownHostException
Create a new HttpProxy.

Throws:
UnknownHostException - if the local host address can not be determined
Method Detail

setConfig

public void setConfig(String conf)
               throws IOException
Set the config file to use for this proxy.

Parameters:
conf - the name of the file to use for proxy configuration.
Throws:
IOException - if the config file can not be read

setStrictHttp

public void setStrictHttp(boolean b)
Toogle the strict http flag.

Parameters:
b - the new mode for the strict http flag

getStrictHttp

public boolean getStrictHttp()
Check if strict http is turned on or off.

Returns:
the strict http flag

start

public void start()
Run the proxy in a separate thread.


stop

public void stop()
Run the proxy in a separate thread.


getNioHandler

public NioHandler getNioHandler()
Get the NioHandler that this proxy is using.

Returns:
the NioHandler in use

getCache

public Cache<HttpHeader,HttpHeader> getCache()
Get the cache that this proxy is currently using.

Returns:
the Cache in use

getOffset

public long getOffset()
Get the time offset, that is the time between GMT and local time.

Returns:
the current time offset in millis

getStartTime

public long getStartTime()
Get the time this proxy was started.

Returns:
the start time as returned from System.currentTimeMillis()

getCounter

public Counter getCounter()
Get the current Counter

Returns:
the Ćounter in use

getConfig

public Config getConfig()
Get the configuration of the proxy.

Returns:
the current configuration

getVersion

public String getVersion()
Get the version of this proxy.

Returns:
the version of the proxy

getServerIdentity

public String getServerIdentity()
Get the current server identity.

Returns:
the current identity

getHost

public InetAddress getHost()
Get the local host.

Returns:
the InetAddress of the host the proxy is running on.

getPort

public int getPort()
Get the port this proxy is using.

Returns:
the port number the proxy is listening on.

getProxyChain

public ProxyChain getProxyChain()
Get the ProxyChain this proxy is currently using

Returns:
the current ProxyChain

isSelf

public boolean isSelf(String uhost,
                      int urlport)
Try hard to check if the given address matches the proxy. Will use the localhost name and all ip addresses.

Parameters:
uhost - the host name to check
urlport - the port number to check
Returns:
true if the given hostname and port matches this proxy

getWebConnection

public void getWebConnection(HttpHeader header,
                             WebConnectionListener wcl)
Get a WebConnection.

Parameters:
header - the http header to get the host and port from
wcl - the listener that wants to get the connection.

releaseWebConnection

public void releaseWebConnection(WebConnection wc)
Release a WebConnection so that it may be reused if possible.

Parameters:
wc - the WebConnection to release.

markForPipelining

public void markForPipelining(WebConnection wc)
Mark a WebConnection for pipelining.

Parameters:
wc - the WebConnection to mark.

addCurrentConnection

public void addCurrentConnection(Connection con)
Add a current connection

Parameters:
con - the connection

removeCurrentConnection

public void removeCurrentConnection(Connection con)
Remove a current connection.

Parameters:
con - the connection

getConnectionHandler

public ConnectionHandler getConnectionHandler()
Get the connection handler.

Returns:
the current ConnectionHandler

getCurrentConnections

public List<Connection> getCurrentConnections()
Get all the current connections

Returns:
all current connections

updateTrafficLog

protected void updateTrafficLog(TrafficLoggerHandler tlh)
Update the currently transferred traffic statistics.

Parameters:
tlh - the traffic statistics for some operation

getTrafficLoggerHandler

public TrafficLoggerHandler getTrafficLoggerHandler()
Get the currently transferred traffic statistics.

Returns:
the current TrafficLoggerHandler

getClientTrafficLoggerHandler

public rabbit.proxy.ClientTrafficLoggerHandler getClientTrafficLoggerHandler()
Get the ClientTrafficLoggerHandler

Returns:
the current ClientTrafficLoggerHandler.

getBufferHandler

public BufferHandler getBufferHandler()
Get the BufferHandler this proxy is using

Returns:
a BufferHandler

getHttpGeneratorFactory

public HttpGeneratorFactory getHttpGeneratorFactory()
Get the current HttpGeneratorFactory.

Returns:
the HttpGeneratorFactory in use

load3rdPartyClass

public <T> Class<? extends T> load3rdPartyClass(String name,
                                                Class<T> type)
                                     throws ClassNotFoundException
Load a 3:rd party class.

Type Parameters:
T - the type of the clas
Parameters:
name - the fully qualified name of the class to load
type - the super type of the class
Returns:
the loaded class
Throws:
ClassNotFoundException - if the class can not be found