com.javageeks.gjas.connection
Class HttpConnection

java.lang.Object
  |
  +--com.javageeks.gjas.connection.HttpConnection
All Implemented Interfaces:
Connection, com.javageeks.gjas.connection.HttpConnectionConstants

public class HttpConnection
extends java.lang.Object
implements Connection, com.javageeks.gjas.connection.HttpConnectionConstants

This class provides a simplistic HTTP/1.0 service; it uses only a single root (as opposed to other Web servers, which allow for multiple "virtual roots" in their setup), and offers only the most rudimentary of HTTP protocol services. Because HttpConnection is a transient type (that is, multiple HttpConnection instances will come and go without warning or guarantee), we use static instances to carry expensive resources (like the properties we use) from instance to instance without having to reload them each time. Much of this code is cribbed from the WebServer.java example from the JavaSoft site; however, if you're familiar with that code, you'll notice that this version is much smaller, owing to the fact that GJAS factors out much of the complexity unrelated to HTTP (like thread pools).

TODO:


Field Summary
static int HTTP_ACCEPTED
           
static int HTTP_BAD_GATEWAY
           
static int HTTP_BAD_METHOD
           
static int HTTP_BAD_REQUEST
           
static int HTTP_CLIENT_TIMEOUT
           
static int HTTP_CONFLICT
           
static int HTTP_CREATED
           
static int HTTP_ENTITY_TOO_LARGE
           
static int HTTP_FORBIDDEN
           
static int HTTP_GATEWAY_TIMEOUT
           
static int HTTP_GONE
           
static int HTTP_INTERNAL_ERROR
           
static int HTTP_LENGTH_REQUIRED
           
static int HTTP_MOVED_PERM
           
static int HTTP_MOVED_TEMP
           
static int HTTP_MULT_CHOICE
           
static int HTTP_NO_CONTENT
           
static int HTTP_NOT_ACCEPTABLE
           
static int HTTP_NOT_AUTHORITATIVE
           
static int HTTP_NOT_FOUND
           
static int HTTP_NOT_MODIFIED
           
static int HTTP_OK
           
static int HTTP_PARTIAL
           
static int HTTP_PAYMENT_REQUIRED
           
static int HTTP_PRECON_FAILED
           
static int HTTP_PROXY_AUTH
           
static int HTTP_REQ_TOO_LONG
           
static int HTTP_RESET
           
static int HTTP_SEE_OTHER
           
static int HTTP_SERVER_ERROR
           
static int HTTP_UNAUTHORIZED
           
static int HTTP_UNAVAILABLE
           
static int HTTP_UNSUPPORTED_TYPE
           
static int HTTP_USE_PROXY
           
static int HTTP_VERSION
           
 
Constructor Summary
HttpConnection()
           
 
Method Summary
 void parseRequest(java.io.InputStream in, java.util.Properties headers)
           
 void sendResponse(java.io.OutputStream os, java.util.Properties headers)
           
 void serve(java.net.Socket socket, ConfigProperties props)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_OK

public static final int HTTP_OK

HTTP_CREATED

public static final int HTTP_CREATED

HTTP_ACCEPTED

public static final int HTTP_ACCEPTED

HTTP_NOT_AUTHORITATIVE

public static final int HTTP_NOT_AUTHORITATIVE

HTTP_NO_CONTENT

public static final int HTTP_NO_CONTENT

HTTP_RESET

public static final int HTTP_RESET

HTTP_PARTIAL

public static final int HTTP_PARTIAL

HTTP_MULT_CHOICE

public static final int HTTP_MULT_CHOICE

HTTP_MOVED_PERM

public static final int HTTP_MOVED_PERM

HTTP_MOVED_TEMP

public static final int HTTP_MOVED_TEMP

HTTP_SEE_OTHER

public static final int HTTP_SEE_OTHER

HTTP_NOT_MODIFIED

public static final int HTTP_NOT_MODIFIED

HTTP_USE_PROXY

public static final int HTTP_USE_PROXY

HTTP_BAD_REQUEST

public static final int HTTP_BAD_REQUEST

HTTP_UNAUTHORIZED

public static final int HTTP_UNAUTHORIZED

HTTP_PAYMENT_REQUIRED

public static final int HTTP_PAYMENT_REQUIRED

HTTP_FORBIDDEN

public static final int HTTP_FORBIDDEN

HTTP_NOT_FOUND

public static final int HTTP_NOT_FOUND

HTTP_BAD_METHOD

public static final int HTTP_BAD_METHOD

HTTP_NOT_ACCEPTABLE

public static final int HTTP_NOT_ACCEPTABLE

HTTP_PROXY_AUTH

public static final int HTTP_PROXY_AUTH

HTTP_CLIENT_TIMEOUT

public static final int HTTP_CLIENT_TIMEOUT

HTTP_CONFLICT

public static final int HTTP_CONFLICT

HTTP_GONE

public static final int HTTP_GONE

HTTP_LENGTH_REQUIRED

public static final int HTTP_LENGTH_REQUIRED

HTTP_PRECON_FAILED

public static final int HTTP_PRECON_FAILED

HTTP_ENTITY_TOO_LARGE

public static final int HTTP_ENTITY_TOO_LARGE

HTTP_REQ_TOO_LONG

public static final int HTTP_REQ_TOO_LONG

HTTP_UNSUPPORTED_TYPE

public static final int HTTP_UNSUPPORTED_TYPE

HTTP_SERVER_ERROR

public static final int HTTP_SERVER_ERROR

HTTP_INTERNAL_ERROR

public static final int HTTP_INTERNAL_ERROR

HTTP_BAD_GATEWAY

public static final int HTTP_BAD_GATEWAY

HTTP_UNAVAILABLE

public static final int HTTP_UNAVAILABLE

HTTP_GATEWAY_TIMEOUT

public static final int HTTP_GATEWAY_TIMEOUT

HTTP_VERSION

public static final int HTTP_VERSION
Constructor Detail

HttpConnection

public HttpConnection()
Method Detail

serve

public void serve(java.net.Socket socket,
                  ConfigProperties props)
           throws java.lang.Exception
Specified by:
serve in interface Connection

parseRequest

public void parseRequest(java.io.InputStream in,
                         java.util.Properties headers)
                  throws java.io.IOException

sendResponse

public void sendResponse(java.io.OutputStream os,
                         java.util.Properties headers)
                  throws java.io.IOException