de.unkrig.commons.net.http
Class HttpProxy

java.lang.Object
  extended by de.unkrig.commons.net.http.HttpProxy
All Implemented Interfaces:
RunnableWhichThrows<java.io.IOException>, Stoppable

public final class HttpProxy
extends java.lang.Object
implements RunnableWhichThrows<java.io.IOException>, Stoppable

Implementation of a simple HTTP proxy. Creates a connection to a remote host/port each time an HTTP client connects.


Constructor Summary
HttpProxy(java.net.InetSocketAddress endpoint, java.net.InetSocketAddress remoteAddress)
           
HttpProxy(java.net.InetSocketAddress endpoint, java.net.InetSocketAddress remoteAddress, TransformerWhichThrows<HttpRequest,HttpRequest,java.io.IOException> requestTransformer, TransformerWhichThrows<HttpResponse,HttpResponse,java.io.IOException> responseTransformer)
           
HttpProxy(java.net.InetSocketAddress endpoint, java.lang.String remoteHost, int remotePort)
           
HttpProxy(java.net.InetSocketAddress endpoint, java.lang.String remoteHost, int remotePort, TransformerWhichThrows<HttpRequest,HttpRequest,java.io.IOException> requestTransformer, TransformerWhichThrows<HttpResponse,HttpResponse,java.io.IOException> responseTransformer)
           
 
Method Summary
 java.net.InetSocketAddress getEndpointAddress()
           
 void run()
          "To run" an instance means to call this method and wait until it returns.
 void stop()
          Returns when this Stoppable has completely stopped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpProxy

public HttpProxy(java.net.InetSocketAddress endpoint,
                 java.net.InetSocketAddress remoteAddress)
          throws java.io.IOException
Parameters:
endpoint - The local endpoint (interface) to bind to
remoteAddress - The address of the remote server to connect to
Throws:
java.io.IOException

HttpProxy

public HttpProxy(java.net.InetSocketAddress endpoint,
                 java.lang.String remoteHost,
                 int remotePort)
          throws java.io.IOException
Parameters:
endpoint - The local endpoint (interface) to bind to
remoteHost - The name of the remote server to connect to
remotePort - The port on the remote server
Throws:
java.io.IOException

HttpProxy

public HttpProxy(java.net.InetSocketAddress endpoint,
                 java.net.InetSocketAddress remoteAddress,
                 TransformerWhichThrows<HttpRequest,HttpRequest,java.io.IOException> requestTransformer,
                 TransformerWhichThrows<HttpResponse,HttpResponse,java.io.IOException> responseTransformer)
          throws java.io.IOException
Parameters:
endpoint - The local endpoint (interface) to bind to
remoteAddress - The address of the remote server to connect to
requestTransformer - Could modify requests as they are forwarded from the client to the server
responseTransformer - Could modify responses as they are forwarded from the server to the client
Throws:
java.io.IOException

HttpProxy

public HttpProxy(java.net.InetSocketAddress endpoint,
                 java.lang.String remoteHost,
                 int remotePort,
                 TransformerWhichThrows<HttpRequest,HttpRequest,java.io.IOException> requestTransformer,
                 TransformerWhichThrows<HttpResponse,HttpResponse,java.io.IOException> responseTransformer)
          throws java.io.IOException
Parameters:
endpoint - The local endpoint (interface) to bind to
remoteHost - The name of the remote server to connect to
remotePort - The port on the remote server
requestTransformer - Could modify requests as they are forwarded from the client to the server
responseTransformer - Could modify responses as they are forwarded from the server to the client
Throws:
java.io.IOException
Method Detail

run

public void run()
         throws java.io.IOException
Description copied from interface: RunnableWhichThrows
"To run" an instance means to call this method and wait until it returns.

Specified by:
run in interface RunnableWhichThrows<java.io.IOException>
Throws:
java.io.IOException

stop

public void stop()
Description copied from interface: Stoppable
Returns when this Stoppable has completely stopped.

Specified by:
stop in interface Stoppable

getEndpointAddress

public java.net.InetSocketAddress getEndpointAddress()
Returns:
The endpoint address of the local HTTP server.