com.objectwave.simpleSockets
Class ServeHTTPClient

java.lang.Object
  |
  +--com.objectwave.simpleSockets.ServeClient
        |
        +--com.objectwave.simpleSockets.ServeHTTPClient
All Implemented Interfaces:
java.lang.Runnable

public class ServeHTTPClient
extends ServeClient

Serve up data to one particular client. Two threads are used from a thread pool ro process requests. One thread reads data from the client, the other publishes data.

Version:
2.0
Author:
Dave Hoag

Field Summary
 
Fields inherited from class com.objectwave.simpleSockets.ServeClient
alive, debug, id, server, socket, thread
 
Method Summary
 void bind(java.net.Socket s)
          Simply associate the socket that represents this client connection with this instance.
protected  java.lang.String extractRequest(java.lang.String str)
          Skip some of the HTTP request header information.
static com.objectwave.simpleSockets.ServeHTTPClient.HeaderAndData formatHTMLHeader(java.io.InputStream actualHtml)
          Override this method to process your request.
 SimpleHTTP getGateway()
           
 com.objectwave.simpleSockets.ServeHTTPClient.MyWriter getMyWriter()
          The Writer represents the client.
 ReplyHandler getReplyHandler()
           
protected  void loop()
          This departs from the traditional simple server implementations.
protected  com.objectwave.simpleSockets.ServeHTTPClient.HeaderAndData processRequestData(java.lang.String requestString)
          Override this method to process your request.
static void setDefaultReplyHandler(ReplyHandler han)
          Set the default ReplyHandler if none is specified for the particular instance.
 void setReplyHandler(ReplyHandler han)
          Through use of a reply handler, the SimpleHTTP server can be used as is without requiring a subclass of special implementation.
 
Methods inherited from class com.objectwave.simpleSockets.ServeClient
emitReply, emitReplyStream, getName, handleSocketException, isBound, kill, loopForBinding, pause, processRequest, processRequestStream, run, runConnection, terminateConnection, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setDefaultReplyHandler

public static void setDefaultReplyHandler(ReplyHandler han)
Set the default ReplyHandler if none is specified for the particular instance.

Parameters:
han - ReplyHandler How to repsond to http requests

setReplyHandler

public void setReplyHandler(ReplyHandler han)
Through use of a reply handler, the SimpleHTTP server can be used as is without requiring a subclass of special implementation. The ReplyHander will return a String as a result of requests, preferably an HTTP document.

Parameters:
han - com.objectwave.simpleSockets.ReplyHandler A custom implementation

getReplyHandler

public ReplyHandler getReplyHandler()
Returns:
ReplyHandle The reply handler assigned to this instance, or the default one

getMyWriter

public com.objectwave.simpleSockets.ServeHTTPClient.MyWriter getMyWriter()
The Writer represents the client. Anything that is to be sent to client should be sent here.


bind

public void bind(java.net.Socket s)
          throws java.io.IOException
Simply associate the socket that represents this client connection with this instance. A required step by the server.

Overrides:
bind in class ServeClient
Parameters:
s - The socket this client should now handle.
java.io.IOException

getGateway

public SimpleHTTP getGateway()

extractRequest

protected java.lang.String extractRequest(java.lang.String str)
Skip some of the HTTP request header information.

Parameters:
str - The string sent in over the socket
Returns:
The remainder of the string after the beginning of the header information

loop

protected void loop()
             throws java.io.IOException,
                    java.io.EOFException
This departs from the traditional simple server implementations.

Overrides:
loop in class ServeClient
java.io.IOException
java.io.EOFException

processRequestData

protected com.objectwave.simpleSockets.ServeHTTPClient.HeaderAndData processRequestData(java.lang.String requestString)
                                                                                 throws java.io.IOException
Override this method to process your request. Returning a string from this method will imply to this to call emitReply();

Parameters:
requestString - The information on the HTTP request after the host and port
Returns:
String The reply to send to the browser. This is the actual formatted HTML reply that goes over the socket.
java.io.IOException

formatHTMLHeader

public static com.objectwave.simpleSockets.ServeHTTPClient.HeaderAndData formatHTMLHeader(java.io.InputStream actualHtml)
                                                                                   throws java.io.IOException
Override this method to process your request. Returning a string from this method will imply to this to call emitReply();

Parameters:
actualHtml - String Expected to be valid HTML.
Returns:
String The reply to send to the browser. This is the actual formatted HTML reply that goes over the socket. protected String processRequest(String requestString) { if(getReplyHandler() != null) { String req = extractRequest(requestString); //System.out.println("Extracted Requst " + req); return formatHTMLHeader(getReplyHandler().processRequest(req)); } int idx = requestString.indexOf(' '); String actual = requestString; if(idx > 0) { requestString.substring(0, idx); } return formatHTMLHeader(getTestString(actual)); } /** Put a standard HTML header on the actual html.
java.io.IOException