example
Class HttpServer

java.lang.Object
  |
  +--example.HttpServer
All Implemented Interfaces:
java.lang.Runnable

public class HttpServer
extends java.lang.Object
implements java.lang.Runnable

Implementation of a basic HTTP server for Firewall tunneling. The server supports both Client->Server and Server->Client communication.


Constructor Summary
HttpServer(int port, int poolSize)
          Creates a new HttpServer instance
 
Method Summary
(package private)  void addClient(java.net.Socket s)
          Adds a new client
 void addHttpServerListener(HttpServerListener l)
          Adds a new HttpServerListener.
 int getClientCount()
           
(package private)  void notifyListener(java.io.InputStream data, java.io.OutputStream out)
          Notifies the listener when a message arrives
 void removeHttpServerListener(HttpServerListener l)
          Removes a new HttpServerListener.
 void run()
          Thread to accept connections
 void send(byte[] data)
          Simple implementation that sends data to all clients
(package private)  void writeResponse(java.io.DataOutputStream out)
          Convience method to write the HTTP Response header
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServer

public HttpServer(int port,
                  int poolSize)
           throws java.io.IOException
Creates a new HttpServer instance

Parameters:
port - Port to listen on
poolSize - Number of handler threads
Throws:
java.io.IOException - Thrown if the accept socket cannot be opended
Method Detail

addClient

void addClient(java.net.Socket s)
Adds a new client

Parameters:
s - Socket
Returns:
void

getClientCount

public int getClientCount()

addHttpServerListener

public void addHttpServerListener(HttpServerListener l)
                           throws java.util.TooManyListenersException
Adds a new HttpServerListener. Only one listener can be added

Parameters:
l - HttpServerListener
Returns:
void
Throws:
java.util.TooManyListenersException - Thrown if more then one listener is added

removeHttpServerListener

public void removeHttpServerListener(HttpServerListener l)
Removes a new HttpServerListener. be added

Parameters:
l - HttpServerListener
Returns:
void

notifyListener

void notifyListener(java.io.InputStream data,
                    java.io.OutputStream out)
Notifies the listener when a message arrives

Parameters:
data - Message data
out - Stream to write results too
Returns:
void

send

public void send(byte[] data)
Simple implementation that sends data to all clients

Parameters:
data - Array of bytes containing data to send
Returns:
void

run

public void run()
Thread to accept connections

Specified by:
run in interface java.lang.Runnable
Returns:
void

writeResponse

void writeResponse(java.io.DataOutputStream out)
             throws java.io.IOException
Convience method to write the HTTP Response header

Parameters:
out - Stream to write the response too
Returns:
void
Throws:
java.io.IOException - Thrown if response can't be written