net.noderunner.http
Class ThreadedHttpServer

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

public abstract class ThreadedHttpServer
extends java.lang.Object
implements java.lang.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  java.net.ServerSocket ss
           
 
Constructor Summary
ThreadedHttpServer()
           
ThreadedHttpServer(java.net.ServerSocket ss)
          Constructs a new SingleHttpServer, initialized with a server socket.
 
Method Summary
 void close()
          Closes as soon as possible.
protected  void exception(java.lang.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.
 java.lang.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 java.net.ServerSocket ss
Constructor Detail

ThreadedHttpServer

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

Parameters:
ss - server socket to listen with

ThreadedHttpServer

public ThreadedHttpServer()
                   throws java.io.IOException
Throws:
java.io.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 java.io.IOException
Override this method to handle the request. You may optionally process this request asynchronously.

Parameters:
s - server request
address - address of request
Throws:
java.io.IOException

exception

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


run

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

close

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

Throws:
java.io.IOException

toString

public java.lang.String toString()
Returns a debug string.

Overrides:
toString in class java.lang.Object


Copyright © 2009. All Rights Reserved.