org.apache.axis2.transport.http.server
Class SimpleHttpServer

java.lang.Object
  extended byorg.apache.axis2.transport.http.server.SimpleHttpServer
All Implemented Interfaces:
Runnable

public class SimpleHttpServer
extends Object
implements Runnable

A simple, but extensible HTTP server, mostly for testing purposes.


Constructor Summary
SimpleHttpServer()
          Creates a new HTTP server instance, using an arbitrary free TCP port
SimpleHttpServer(int port)
          Creates a new HTTP server instance, using the specified TCP port
SimpleHttpServer(int port, ThreadFactory threadPool)
          Creates a new HTTP server instance, using the specified TCP port
SimpleHttpServer(SimpleSocketFactory socketfactory, int port)
          Creates a new HTTP server instance, using the specified socket factory and the TCP port
SimpleHttpServer(SimpleSocketFactory socketfactory, int port, ThreadFactory threadPool)
          Creates a new HTTP server instance, using the specified socket factory and the TCP port that uses the given ThreadPool.
 
Method Summary
 void destroy()
          Stops this HTTP server instance.
 String getLocalAddress()
          Returns the IP address that this HTTP server instance is bound to.
 int getLocalPort()
          Returns the TCP port that this HTTP server instance is bound to.
 HttpRequestHandler getRequestHandler()
          Returns the currently used HttpRequestHandler by this SimpleHttpServer
 String getTestname()
           
 boolean isRunning()
          Checks if this HTTP server instance is running.
 void run()
           
 void setHttpService(HttpService service)
           
 void setRequestHandler(HttpRequestHandler rh)
          Sets the HttpRequestHandler to be used for this SimpleHttpServer.
 void setTestname(String testname)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleHttpServer

public SimpleHttpServer()
                 throws IOException
Creates a new HTTP server instance, using an arbitrary free TCP port

Throws:
IOException - if anything goes wrong during initialization

SimpleHttpServer

public SimpleHttpServer(int port)
                 throws IOException
Creates a new HTTP server instance, using the specified TCP port

Parameters:
port - Desired TCP port
Throws:
IOException - if anything goes wrong during initialization

SimpleHttpServer

public SimpleHttpServer(int port,
                        ThreadFactory threadPool)
                 throws IOException
Creates a new HTTP server instance, using the specified TCP port

Parameters:
port - Desired TCP port
threadPool - ThreadPool to be used.
Throws:
IOException - if anything goes wrong during initialization

SimpleHttpServer

public SimpleHttpServer(SimpleSocketFactory socketfactory,
                        int port)
                 throws IOException
Creates a new HTTP server instance, using the specified socket factory and the TCP port

Parameters:
port - Desired TCP port
Throws:
IOException - if anything goes wrong during initialization

SimpleHttpServer

public SimpleHttpServer(SimpleSocketFactory socketfactory,
                        int port,
                        ThreadFactory threadPool)
                 throws IOException
Creates a new HTTP server instance, using the specified socket factory and the TCP port that uses the given ThreadPool. If a ThreadPool is not given then a new default axis2 ThreadPool will be used.

Parameters:
port - Desired TCP port
threadPool - ThreadPool to be used inside the SimpleHttpServer. The threadPool object that is provided needs to implement tp.execute(Runnable r)
Throws:
IOException - if anything goes wrong during initialization
Method Detail

destroy

public void destroy()
Stops this HTTP server instance.


run

public void run()
Specified by:
run in interface Runnable

getLocalAddress

public String getLocalAddress()
Returns the IP address that this HTTP server instance is bound to.

Returns:
String representation of the IP address or null if not running

getLocalPort

public int getLocalPort()
Returns the TCP port that this HTTP server instance is bound to.

Returns:
TCP port, or -1 if not running

getRequestHandler

public HttpRequestHandler getRequestHandler()
Returns the currently used HttpRequestHandler by this SimpleHttpServer

Returns:
The used HttpRequestHandler, or null.

getTestname

public String getTestname()

isRunning

public boolean isRunning()
Checks if this HTTP server instance is running.

Returns:
true/false

setHttpService

public void setHttpService(HttpService service)

setRequestHandler

public void setRequestHandler(HttpRequestHandler rh)
Sets the HttpRequestHandler to be used for this SimpleHttpServer.

Parameters:
rh - Request handler to be used, or null to disable.

setTestname

public void setTestname(String testname)