net.noderunner.http
Class ThreadedHttpServer

java.lang.Object
  extended by net.noderunner.http.ThreadedHttpServer
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ServletServer

public abstract class ThreadedHttpServer
extends Object
implements Runnable

This class is for unit testing. It accepts one request at a time in a single thread. Override the handleRequest method to do something interesting.

Version:
1.0
Author:
Elias Ross

Nested Class Summary
 class ThreadedHttpServer.Request
          Inner class for handling a single HTTP server request.
 
Field Summary
protected  ServerSocket ss
           
 
Constructor Summary
ThreadedHttpServer()
           
ThreadedHttpServer(ServerSocket ss)
          Constructs a new SingleHttpServer, initialized with a server socket.
 
Method Summary
 void close()
          Closes as soon as possible.
protected  void exception(Exception e)
          Called when an exception occurs when listening; does nothing now.
 int getPort()
           
protected abstract  void handleRequest(ThreadedHttpServer.Request request)
          Override this method to handle the request.
 void run()
           
 void start()
          Starts listening in a new thread.
 String toString()
          Returns a debug string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ss

protected final ServerSocket ss
Constructor Detail

ThreadedHttpServer

public ThreadedHttpServer(ServerSocket ss)
Constructs a new SingleHttpServer, initialized with a server socket.

Parameters:
ss - server socket to listen with

ThreadedHttpServer

public ThreadedHttpServer()
                   throws IOException
Throws:
IOException
Method Detail

start

public void start()
Starts listening in a new thread.


getPort

public int getPort()

handleRequest

protected abstract void handleRequest(ThreadedHttpServer.Request request)
                               throws IOException
Override this method to handle the request. You may optionally process this request asynchronously.

Parameters:
s - server request
address - address of request
Throws:
IOException

exception

protected void exception(Exception e)
Called when an exception occurs when listening; does nothing now.


run

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

close

public void close()
           throws IOException
Closes as soon as possible.

Throws:
IOException

toString

public String toString()
Returns a debug string.

Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.