com.equilibrium.util.api
Class MGResponse

java.lang.Object
  extended by com.equilibrium.util.api.MGResponse
Direct Known Subclasses:
MGBatchesExecutingResponse, MGBatchStatusResponse, MGFileResponse

public class MGResponse
extends java.lang.Object

Represents the response from the MediaGenerator.


Method Summary
 void discard()
          Forget the rest of the response.
 java.lang.String getContentKey()
          Return the message key for the content or null if there is no content.
 int getContentLength()
          Return the content length for the content or 0.
 java.lang.String getContentMimeType()
          Return the content mime type for the response.
 double getDoubleParam(java.lang.String key)
          Return the parameter associated with key coerced to a double.
 java.lang.String getHttpHeader(java.lang.String key)
          Return the named http header.
 java.util.Map getHttpHeaders()
          Return the http header dictionary.
 int[] getIntArrayParam(java.lang.String key)
          Return int array parameter from comma separated list response.
 int getIntParam(java.lang.String key)
          Return the parameter associated key coerced to an integer.
 long getLongParam(java.lang.String key)
          Return the parameter associated key coerced to a long integer.
 java.lang.String getParam(java.lang.String key)
          Get a message response parameter.
 java.util.Set getParameters()
          Return the keys collected from the message so far.
 java.lang.String getResponsePath()
          Return the path to the generated file if there is one.
 int getStatusCode()
          Return the status code for the reponse.
 java.lang.String getTextResponse()
          Convenience method for getting a text-only response as a string.
 boolean hasContent()
          Return true if the if there is file content available, false otherwise.
 int readContent(byte[] buf)
          Fill the buffer with response data.
 boolean streamResponse(java.io.OutputStream outStream)
          Stream the response to the designated stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasContent

public boolean hasContent()
Return true if the if there is file content available, false otherwise. If this property is true, the content can be retrieved with MGResponse.readContent(byte[])

Returns:
true if the response contains file content.

getStatusCode

public int getStatusCode()
Return the status code for the reponse. These status codes correspond to the http status codes. A value of 0 indicates that no status code was returned.

Returns:
the status code ala http.

getContentKey

public java.lang.String getContentKey()
Return the message key for the content or null if there is no content.

Returns:
the key for the content.

readContent

public int readContent(byte[] buf)
                throws java.io.IOException
Fill the buffer with response data.

Parameters:
buf - the buffer.
Returns:
the number of bytes placed into buf.
Throws:
java.io.IOException

streamResponse

public boolean streamResponse(java.io.OutputStream outStream)
                       throws java.io.IOException
Stream the response to the designated stream. This method allows sending a response from the media generator directly into an output stream.

Parameters:
outStream - the output stream to send the response to.
Returns:
true if there was a response.
Throws:
java.io.IOException

discard

public void discard()
             throws java.io.IOException
Forget the rest of the response.

Throws:
java.io.IOException

getContentLength

public int getContentLength()
Return the content length for the content or 0.

Returns:
the length of the content parameter.

getHttpHeaders

public java.util.Map getHttpHeaders()
Return the http header dictionary. Note that Content-Length is never in this list. Use ContentLength accessor instead. The keys into the map are always lower-case.

Returns:
map containing http headers.

getHttpHeader

public java.lang.String getHttpHeader(java.lang.String key)
Return the named http header. Note that Content-Length is never in this list. Use ContentLength accessor instead. This method takes upper, lower, and mixed-case keys.

Parameters:
key - header key.
Returns:
the header value.

getContentMimeType

public java.lang.String getContentMimeType()
Return the content mime type for the response.

Returns:
the mime type for any content or null.

getResponsePath

public java.lang.String getResponsePath()
Return the path to the generated file if there is one. A response path is generated if the script did not stream back the response content. A response path will never be generated unless the nc parameter is explicitly set to false.

Returns:
the path.

getTextResponse

public java.lang.String getTextResponse()
                                 throws java.io.IOException
Convenience method for getting a text-only response as a string. Returns a text response as a string if there is one or null if not.

Returns:
the text response or null.
Throws:
java.io.IOException

getIntParam

public int getIntParam(java.lang.String key)
                throws MGException
Return the parameter associated key coerced to an integer.

Parameters:
key - the key.
Returns:
the integer value associated.
Throws:
MGException

getLongParam

public long getLongParam(java.lang.String key)
                  throws MGException
Return the parameter associated key coerced to a long integer.

Parameters:
key - the key.
Returns:
the long integer value associated.
Throws:
MGException

getDoubleParam

public double getDoubleParam(java.lang.String key)
                      throws MGException
Return the parameter associated with key coerced to a double.

Parameters:
key - the key.
Returns:
the long integer value associated.
Throws:
MGException

getIntArrayParam

public int[] getIntArrayParam(java.lang.String key)
                       throws MGException
Return int array parameter from comma separated list response. This is used primarily to get a list of currently executing batches.

Parameters:
key - the key.
Returns:
and array of integers, parsed from the response.
Throws:
MGException

getParam

public java.lang.String getParam(java.lang.String key)
Get a message response parameter. The keys are defined in MessageCommands

Parameters:
key - the response parameter key.
Returns:
the value associated.

getParameters

public java.util.Set getParameters()
Return the keys collected from the message so far. In general, these will includes header tags and content length for the next file param.

Returns:
current parameter keys.