context.arch.comm.protocol
Class HTTPClientSocket

java.lang.Object
  |
  +--context.arch.comm.protocol.TCPClientSocket
        |
        +--context.arch.comm.protocol.HTTPClientSocket

public class HTTPClientSocket
extends TCPClientSocket
implements CommunicationsClient

This class subclasses TCPClientSocket, creating and sending HTTP requests. It implements the CommunicationsClient interface

See Also:
TCPClientSocket, CommunicationsClient

Field Summary
static int DEFAULT_PORT
          Default port to use is 5555
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.TCPClientSocket
DEFAULT_PORT, DEFAULT_SERVER, portNumber, remoteServer
 
Constructor Summary
HTTPClientSocket(CommunicationsObject object)
          Basic constructor for HTTPClientSocket that calls TCPClientSocket
HTTPClientSocket(CommunicationsObject object, java.lang.String server, java.lang.Integer port)
          Constructor for HTTPClientSocket that calls TCPClientSocket with the given port
 
Method Summary
 java.lang.String addRequestProtocol(java.lang.String data, java.lang.String url)
          This method adds the HTTP protocol for a POST request (POST is the default)
 java.lang.String addRequestProtocol(java.lang.String data, java.lang.String url, java.lang.String type)
          Method that adds the HTTP protocol to a request message
 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
 java.net.Socket sendRequest(java.lang.String content)
          This method sends a request to a remote server
 RequestData stripReplyProtocol(java.net.Socket data)
          Method that strips away the HTTP protocol from a reply message
 
Methods inherited from class context.arch.comm.protocol.TCPClientSocket
getPort, getServer, setPort, setServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

DEFAULT_PORT

public static final int DEFAULT_PORT
Default port to use is 5555
Constructor Detail

HTTPClientSocket

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

HTTPClientSocket

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

addRequestProtocol

public java.lang.String addRequestProtocol(java.lang.String data,
                                           java.lang.String url)
                                    throws ProtocolException
This method adds the HTTP protocol for a POST request (POST is the default)
Specified by:
addRequestProtocol in interface CommunicationsClient
Parameters:
content - The request to send
Returns:
socket for the connection

addRequestProtocol

public java.lang.String addRequestProtocol(java.lang.String data,
                                           java.lang.String url,
                                           java.lang.String type)
                                    throws ProtocolException
Method that adds the HTTP protocol to a request message
Specified by:
addRequestProtocol in interface CommunicationsClient
Parameters:
data - Request message to add HTTP protocol to
url - Tag/URL to add to message
Returns:
the request with the HTTP protocol added
Throws:
ProtocolException - if the protocol can not be added

stripReplyProtocol

public RequestData stripReplyProtocol(java.net.Socket data)
                               throws ProtocolException
Method that strips away the HTTP protocol from a reply message
Specified by:
stripReplyProtocol in interface CommunicationsClient
Parameters:
socket - Socket on which reply is coming from
Returns:
the reply 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. CURRENTLY RETURNS EMPTY DATAOBJECT - NEEDS WORK (AKD).
Specified by:
getErrorMessage in interface CommunicationsClient
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. CURRENTLY RETURNS EMPTY STRING - NEEDS WORK (AKD).
Specified by:
getFatalMessage in interface CommunicationsClient
Returns:
fatal error message
See Also:
getErrorMessage()

sendRequest

public java.net.Socket sendRequest(java.lang.String content)
This method sends a request to a remote server
Specified by:
sendRequest in interface CommunicationsClient
Parameters:
content - The request to send
Returns:
socket for the connection

getProtocol

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