rabbit.proxy
Class Proxy

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--rabbit.proxy.Proxy
All Implemented Interfaces:
java.lang.Runnable

public class Proxy
extends java.lang.Thread

This is the central dispatcher for RabbIT. Basically it sits in a loop accepting connection and for each connection creating a handler for it. Also handles logging so it goes out nicely formatted (and synchronized).


Field Summary
protected static java.util.Vector accessfilters
          the filters, a vector of classes (in given order)
static int ALL
          Show all normal messages and higher.
protected static java.util.Hashtable cachehandlers
          the hash tables with type=>Class mapping for cache handling.
static Config config
          The current configuration
protected static java.lang.String CONFIG
          The standard configuration file
static int DEBUG
          Show all messages in the log.
static int ERROR
          Show error messages and higer.
static int FATAL
          Show only fatal messages.
protected static java.util.Hashtable handlers
          the hash tables with type=>Class mapping
protected static java.util.Vector httpinfilters
          the filters, a vector of classes (in given order)
protected static java.util.Vector httpoutfilters
          the filters, a vector of classes (in given order)
static int INFO
          Show information messages and higher.
static int MSG
          Show important messages and above.
protected static boolean proxySSL
          Are we allowed to proxy ssl?
protected static java.util.Vector sslports
          The Vector of acceptable ssl-ports.
static java.lang.String VERSION
          Current version
static int WARN
          Show warnings and higer.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
protected static void closeSocket()
          Closes the serversocket and makes the proxy stop listening for connections.
static NCache getCache()
          Get the cache the proxy are using.
static ConnectionHandler getConnectionHandler()
          Get the connection handler.
static int getConnectPort(int port)
          Get the port to connect to.
static Counter getCounter()
          Get the Log-handle
static java.util.Vector getCurrentConections()
          returns the current connections.
static int getErrorLevel(java.lang.String errorlevel)
          Get the actual error level from the given String.
static java.lang.String getErrorLevelString(int errorlevel)
          Get the String description of the given error level
static java.net.InetAddress getHost()
          Get the local host.
static java.net.InetAddress getInetAddress(java.net.URL url)
          Get the InetAddress to connect to.
static long getOffset()
          Get the offset in milis from GMT NOTE! the offset is only calculated at startup.
static int getPort()
          Get the port this proxy is using.
static java.lang.String getProxyAuthString()
          Get the authenticationstring to use for proxy.
static java.lang.String getServerIdentity()
           
static java.util.Date getStartDate()
          return the time when the proxy was started.
 java.util.TimeZone getTimeZone()
          Get the time zone the proxy is running in.
static WebConnection getWebConnection(HTTPHeader header)
          Get a WebConnection.
static boolean isProxyConnected()
          are we connected to another proxy?
static void kill()
          shutdown
protected  void loadClasses()
          Make sure all filters and handlers are available
protected  java.util.Hashtable loadHandlers(java.lang.String section)
          load a set of handlers.
static void logConnection(Connection con)
          log a connection handled.
static void logError(int type, java.lang.String error)
          log errors and other important stuff.
static void logError(java.lang.String error)
          log errors and other important stuff.
static void main(java.lang.String[] args)
          Start a proxy.
protected static void openSocket()
          Open a socket on the specified port also make the proxy continue accepting connections.
static void printHelp()
          print out the helptext to the user.
static void reConfigure(Config config)
          Reconfigure the proxy during runtime.
static void releaseWebConnection(WebConnection wc)
          Release a WebConnection so that it may be reused if possible.
static void removeConnection(Connection con)
          Remove a connection (it has received full treatment)
 void run()
          while we can, accept new sockets, creating a handler for each and also save connections for statistics.
static void saveConfig()
          save the config back to file
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
Current version

See Also:
Constant Field Values

CONFIG

protected static java.lang.String CONFIG
The standard configuration file


DEBUG

public static final int DEBUG
Show all messages in the log.

See Also:
Constant Field Values

ALL

public static final int ALL
Show all normal messages and higher.

See Also:
Constant Field Values

INFO

public static final int INFO
Show information messages and higher.

See Also:
Constant Field Values

WARN

public static final int WARN
Show warnings and higer.

See Also:
Constant Field Values

MSG

public static final int MSG
Show important messages and above.

See Also:
Constant Field Values

ERROR

public static final int ERROR
Show error messages and higer.

See Also:
Constant Field Values

FATAL

public static final int FATAL
Show only fatal messages.

See Also:
Constant Field Values

config

public static Config config
The current configuration


handlers

protected static java.util.Hashtable handlers
the hash tables with type=>Class mapping


cachehandlers

protected static java.util.Hashtable cachehandlers
the hash tables with type=>Class mapping for cache handling.


accessfilters

protected static java.util.Vector accessfilters
the filters, a vector of classes (in given order)


httpinfilters

protected static java.util.Vector httpinfilters
the filters, a vector of classes (in given order)


httpoutfilters

protected static java.util.Vector httpoutfilters
the filters, a vector of classes (in given order)


proxySSL

protected static boolean proxySSL
Are we allowed to proxy ssl?


sslports

protected static java.util.Vector sslports
The Vector of acceptable ssl-ports.

Method Detail

main

public static void main(java.lang.String[] args)
Start a proxy. Parse flags and read the config, then starts the proxy.

Parameters:
args - the command-line flags given.

getTimeZone

public java.util.TimeZone getTimeZone()
Get the time zone the proxy is running in. This is neccessary to give dates in GMT.


getOffset

public static long getOffset()
Get the offset in milis from GMT NOTE! the offset is only calculated at startup. This means that during DST changes this may be invalid for a day or two. Restart RabbIT dayly during that time to get it right _IF_ you feel it is a problem.


getConnectionHandler

public static ConnectionHandler getConnectionHandler()
Get the connection handler.


getWebConnection

public static WebConnection getWebConnection(HTTPHeader header)
                                      throws java.io.IOException
Get a WebConnection.

java.io.IOException

releaseWebConnection

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

Parameters:
wc - the WebConnection to release.

run

public void run()
while we can, accept new sockets, creating a handler for each and also save connections for statistics.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

openSocket

protected static void openSocket()
Open a socket on the specified port also make the proxy continue accepting connections.


closeSocket

protected static void closeSocket()
Closes the serversocket and makes the proxy stop listening for connections.


printHelp

public static void printHelp()
print out the helptext to the user.


reConfigure

public static void reConfigure(Config config)
Reconfigure the proxy during runtime.

Parameters:
config - the new config.

saveConfig

public static void saveConfig()
save the config back to file


getErrorLevel

public static int getErrorLevel(java.lang.String errorlevel)
Get the actual error level from the given String.

Parameters:
errorlevel - the String to translate.
Returns:
the errorlevel suitable for the given String.

getErrorLevelString

public static java.lang.String getErrorLevelString(int errorlevel)
Get the String description of the given error level

Parameters:
errorlevel - the int to translate to a String.
Returns:
the String describing the errorlevel.

logError

public static void logError(java.lang.String error)
log errors and other important stuff.

Parameters:
error - the thing that happend.

logError

public static void logError(int type,
                            java.lang.String error)
log errors and other important stuff.

Parameters:
type - the type of the error.
error - the thing that happend.

getCache

public static NCache getCache()
Get the cache the proxy are using.

Returns:
the NCache the proxy currently are using.

getCounter

public static Counter getCounter()
Get the Log-handle

Returns:
the Counter we use.

getPort

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

Returns:
the port number the proxy is listening on.

getHost

public static java.net.InetAddress getHost()
Get the local host.

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

isProxyConnected

public static boolean isProxyConnected()
are we connected to another proxy?

Returns:
true if the proxy is connected to another proxy.

getInetAddress

public static java.net.InetAddress getInetAddress(java.net.URL url)
                                           throws java.net.UnknownHostException
Get the InetAddress to connect to.

Returns:
the InetAddress to give the request
java.net.UnknownHostException

getConnectPort

public static int getConnectPort(int port)
Get the port to connect to.

Parameters:
port - the port we want to connect to.
Returns:
the port to connect to.

getProxyAuthString

public static java.lang.String getProxyAuthString()
Get the authenticationstring to use for proxy.

Returns:
an authentication string.

getCurrentConections

public static java.util.Vector getCurrentConections()
returns the current connections.

Returns:
a Vector with the current connections.

removeConnection

public static void removeConnection(Connection con)
Remove a connection (it has received full treatment)

Parameters:
con - the connection that is closing down.

getStartDate

public static java.util.Date getStartDate()
return the time when the proxy was started.

Returns:
a Date with the time the proxy was started.

getServerIdentity

public static java.lang.String getServerIdentity()

loadHandlers

protected java.util.Hashtable loadHandlers(java.lang.String section)
load a set of handlers.

Parameters:
section - the section in the config file.
Returns:
a Hashtable with mimetypes as keys and Handlers as values.

loadClasses

protected void loadClasses()
Make sure all filters and handlers are available


logConnection

public static void logConnection(Connection con)
log a connection handled.

Parameters:
con - the Connection that handled a request

kill

public static void kill()
shutdown