com.monoserv.modules.data
Class HttpDataModule

java.lang.Object
  extended by com.monoserv.modules.data.HttpDataModule

public class HttpDataModule
extends java.lang.Object

This implements the IModuleData for passing a HttpResponse and a HttpRequest object around for modules to work on. Its rudimentary at the moment, but will enhance in features as needed in the near future.

See Also:
com.monoserv.http.HttpResponse, com.monoserv.http.HttpRequest

Constructor Summary
HttpDataModule()
          Constructor - creates a default HttpResponse object and nulls the HttpRequest.
 
Method Summary
 byte[] getDataBinary()
          Only here because its required.
 int getDataFormat()
          As of right now, we are assuming text data is being sent back.
 java.lang.String getDataString()
          Returns the HTTP message as it is currently in memory.
 HttpRequest getHttpRequest()
          Accessor method - returns the current HttpRequest object
 HttpResponse getHttpResponse()
          Accessor method - returns the current HttpResponse object
 boolean hasData()
          Determines if the data for this module actually exists.
 void readData(java.io.InputStream socketStream)
          Method to retreive the HTTP data from the supplied input stream (most likely from a socket).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpDataModule

public HttpDataModule()
Constructor - creates a default HttpResponse object and nulls the HttpRequest. The HttpRequest is created in readData() after the inputstream is specified.

See Also:
HttpResponse#makeResponse(), readData(InputStream)
Method Detail

getDataFormat

public int getDataFormat()
As of right now, we are assuming text data is being sent back. This will have to be changed in the near future to allow for other encodings. Binary data such as data for images, will be inside the HttpResponse object so we will not need to worry ourselves with that here.

Returns:
int IModuleData.FORMAT_STRING_UTF8 (integer value 2)
See Also:
IModuleData#FORMAT_STRING_UTF8

readData

public void readData(java.io.InputStream socketStream)
              throws java.lang.RuntimeException
Method to retreive the HTTP data from the supplied input stream (most likely from a socket). Checks the Socket's available() method and constructs a string buffer to receive the data. Once it has all been read, it creates a HttpRequest object using the makeRequest(String) method.

Parameters:
socketStream - The InputStream returned from getInputStream() from the connected socket.
Throws:
java.lang.RuntimeException - If something goes wrong (reading error, I/O error, etc).

getDataBinary

public byte[] getDataBinary()
Only here because its required. Simply throws the exception and thats it.

Returns:
byte[] What would be data... nothing is ever return in this instance though.
Throws:
java.lang.UnsupportedOperationException - Thrown always, no matter what.

getDataString

public java.lang.String getDataString()
Returns the HTTP message as it is currently in memory. Basically returns the getHttpMessage() of the internal HttpResponse object.

Returns:
String A HTTP-compliant message used for responding back to the client.
See Also:
HttpResponse#getHttpMessage()

hasData

public boolean hasData()
Determines if the data for this module actually exists. Simply checks the HttpResponse object for null status

Returns:
boolean True if the HttpResponse object is not null, false otherwise.

getHttpResponse

public HttpResponse getHttpResponse()
Accessor method - returns the current HttpResponse object

Returns:
HttpResponse The object representing the HTTP response

getHttpRequest

public HttpRequest getHttpRequest()
Accessor method - returns the current HttpRequest object

Returns:
HttpRequest The object representing the HTTP request.