context.arch.comm.protocol
Class HTTPClientSocket

java.lang.Object
  extended bycontext.arch.comm.protocol.TCPClientSocket
      extended bycontext.arch.comm.protocol.HTTPClientSocket
All Implemented Interfaces:
CommunicationsClient

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 boolean DEBUG
          Debug flag.
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_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
 java.lang.String toString()
           
 
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, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Debug flag. Set to true to see debug messages.


PROTOCOL

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

See Also:
Constant Field Values

GET

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

See Also:
Constant Field Values

POST

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

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
Default port to use is 5555

See Also:
Constant Field Values
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:
data - The request to add the protocol to
url - The recipient of the request (eg, an URL in HTTP). May be null.
Returns:
socket for the connection
Throws:
ProtocolException - thrown if protocol can't be added
See Also:
CommunicationsClient.stripReplyProtocol(Socket), CommunicationsServer.stripRequestProtocol(Socket), CommunicationsServer.addReplyProtocol(String)

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
type - The type of the request: GET or POST.
Returns:
the request with the HTTP protocol added
Throws:
ProtocolException - if the protocol can not be added
See Also:
CommunicationsClient.stripReplyProtocol(Socket), CommunicationsServer.stripRequestProtocol(Socket), CommunicationsServer.addReplyProtocol(String)

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:
data - The socket the reply is being received on
Returns:
the reply with the HTTP protocol stripped away
Throws:
ProtocolException - if the protocol can not be stripped away
See Also:
CommunicationsClient.addRequestProtocol(String,String), CommunicationsServer.stripRequestProtocol(Socket), CommunicationsServer.addReplyProtocol(String)

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)
                            throws java.io.IOException
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
Throws:
java.io.IOException

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

toString

public java.lang.String toString()