context.arch.comm.protocol
Class HTTPServerSocket

java.lang.Object
  |
  +--context.arch.comm.protocol.TCPServerSocket
        |
        +--context.arch.comm.protocol.HTTPServerSocket

public class HTTPServerSocket
extends TCPServerSocket
implements CommunicationsServer

This class subclasses TCPServerSocket, listening for and handling HTTP requests. It implements the CommunicationsServer interface

See Also:
TCPServerSocket, CommunicationsServer

Field Summary
static int DEFAULT_PORT
          Default port for HTTP communications is 80
static java.lang.String GET
          HTTP GET request type
static java.lang.String POST
          HTTP POST request type
static java.lang.String PROTOCOL
          The protocol being used is HTTP
 
Fields inherited from class context.arch.comm.protocol.TCPServerSocket
DEFAULT_PORT
 
Constructor Summary
HTTPServerSocket(CommunicationsObject object)
          Basic constructor for HTTPServerSocket that calls TCPServerSocket
HTTPServerSocket(CommunicationsObject object, java.lang.Integer port)
          Constructor for HTTPServerSocket that calls TCPServerSocket with the given port
 
Method Summary
 java.lang.String addReplyProtocol(java.lang.String data)
          Method that takes a reply message and adds the necessary HTTP protocol
 DataObject getErrorMessage()
          This method generates an error message if a request can't be handled properly, to the point where a contextual error message can still be sent as the reply.
 java.lang.String getFatalMessage()
          This method generates an fatal message if a request can't be handled properly, to the point where no contextual error message can be sent as the reply.
 java.lang.String getProtocol()
          Method to get the communications protocol being used
 void handleIncomingRequest(java.net.Socket dataSocket)
          Stub method that handles incoming HTTP requests.
 void quit()
          This method stops the server from receiving more data
 RequestData stripRequestProtocol(java.net.Socket data)
          Method that strips the HTTP protocol from a request message.
 
Methods inherited from class context.arch.comm.protocol.TCPServerSocket
run, start, stopServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
Default port for HTTP communications is 80

PROTOCOL

public static final java.lang.String PROTOCOL
The protocol being used is HTTP

GET

public static final java.lang.String GET
HTTP GET request type

POST

public static final java.lang.String POST
HTTP POST request type
Constructor Detail

HTTPServerSocket

public HTTPServerSocket(CommunicationsObject object)
Basic constructor for HTTPServerSocket that calls TCPServerSocket
Parameters:
object - Handle of the generic instantiating communications object
See Also:
DEFAULT_PORT, TCPServerSocket

HTTPServerSocket

public HTTPServerSocket(CommunicationsObject object,
                        java.lang.Integer port)
Constructor for HTTPServerSocket that calls TCPServerSocket with the given port
Parameters:
object - Handle of the generic instantiating communications object
port - Port to use to receive communications on
See Also:
TCPServerSocket
Method Detail

handleIncomingRequest

public void handleIncomingRequest(java.net.Socket dataSocket)
Stub method that handles incoming HTTP requests. It calls the equivalent method in the CommunicationsObject and then closes the socket.
Specified by:
handleIncomingRequest in interface CommunicationsServer
Overrides:
handleIncomingRequest in class TCPServerSocket
Parameters:
dataSocket - Socket to receive HTTP data from
See Also:
CommunicationsObject.handleIncomingRequest(java.net.Socket)

addReplyProtocol

public java.lang.String addReplyProtocol(java.lang.String data)
                                  throws ProtocolException
Method that takes a reply message and adds the necessary HTTP protocol
Specified by:
addReplyProtocol in interface CommunicationsServer
Parameters:
data - Reply to a received request
Returns:
the reply with the added HTTP protocol
Throws:
ProtocolException - if the protocol can not be added

stripRequestProtocol

public RequestData stripRequestProtocol(java.net.Socket data)
                                 throws ProtocolException
Method that strips the HTTP protocol from a request message. This only deals with GET and POST headers. If any other header is received, it will throw a ProtocolException
Specified by:
stripRequestProtocol in interface CommunicationsServer
Parameters:
data - Socket the request is coming from
Returns:
the request with the HTTP protocol stripped away
Throws:
ProtocolException - if the protocol can not be stripped away

getErrorMessage

public DataObject getErrorMessage()
This method generates an error message if a request can't be handled properly, to the point where a contextual error message can still be sent as the reply. NOT IMPLEMENTED YET, CURRENTLY RETURNS EMPTY DATAOBJECT - AKD
Specified by:
getErrorMessage in interface CommunicationsServer
Returns:
error message in the form of a DataObject
See Also:
getFatalMessage()

getFatalMessage

public java.lang.String getFatalMessage()
This method generates an fatal message if a request can't be handled properly, to the point where no contextual error message can be sent as the reply. NOT IMPLEMENTED YET, CURRENTLY RETURNS EMPTY STRING - AKD
Specified by:
getFatalMessage in interface CommunicationsServer
Returns:
fatal error message
See Also:
getErrorMessage()

quit

public void quit()
This method stops the server from receiving more data
Specified by:
quit in interface CommunicationsServer
See Also:
TCPServerSocket.stopServer()

getProtocol

public java.lang.String getProtocol()
Method to get the communications protocol being used
Specified by:
getProtocol in interface CommunicationsServer
Returns:
communications protocol being used
See Also:
PROTOCOL