info.sswap.impl.http
Class AbstractHTTPResponse

java.lang.Object
  extended by info.sswap.impl.http.AbstractHTTPResponse
All Implemented Interfaces:
HTTPResponse
Direct Known Subclasses:
HTTPAPIImpl.PDGResponse, HTTPAPIImpl.RDGResponse, HTTPAPIImpl.RIGResponse, HTTPAPIImpl.RQGResponse, HTTPAPIImpl.RRGResponse

public abstract class AbstractHTTPResponse
extends java.lang.Object
implements HTTPResponse

An AbstractHTTPResponse consists of a SSWAPDocument as the return pay load of an invocation, along with the network response object. Methods are supplied to get the SSWAPDocument and the response, for example to query the return code or header information.

If a document is successfully stored, then the underlying connection is closed and the document may be read from getDocument. Otherwise (on error), the connection is left open for reading and should be closed by the caller.

The class is marked abstract to indicate that getDocument should be overridden to return a specific type of document, such as:

  RDG getRDG() {
    return (RDG) getDocument();
  }

See Also:
SSWAPDocument

Field Summary
private  java.lang.Exception exception
           
private  com.clarkparsia.utils.web.Response response
           
private static java.lang.String SSWAP_HTTP_EXCEPTION_HEADER
           
private  SSWAPDocument sswapDocument
           
 
Constructor Summary
AbstractHTTPResponse(SSWAPDocument sswapDocument, com.clarkparsia.utils.web.Response response)
          The constructor sets the SSWAPDocument and response object.
AbstractHTTPResponse(SSWAPDocument sswapDocument, com.clarkparsia.utils.web.Response response, java.lang.Exception exception)
          The constructor sets the SSWAPDocument and response object.
 
Method Summary
 void close()
          Close this response
 java.io.InputStream getContent()
          Return the response content from the server
protected  SSWAPDocument getDocument()
          Concrete class should use this method and cast to return a specific type of SSWAPModel.
 java.io.InputStream getErrorStream()
          Return the error stream from the connection
 java.lang.Exception getException()
          Not currently exposed in the RRGResponse interface.
 java.util.Collection<java.lang.String> getHeaders()
          Return all headers returned by the server
 java.lang.String getHeaderValue(java.lang.String headerName)
          Returns the unparsed value of the HTTP header
 java.util.Collection<java.lang.String> getHeaderValues(java.lang.String headerName)
          Returns the values of the HTTP header parsed on the comma delimiter
 java.lang.String getMessage()
          Return the response message from the server
 int getResponseCode()
          Return the response code
 java.lang.String getSSWAPExceptionHeader()
          Returns the header being used for SSWAP Exceptions.
 java.util.Collection<java.lang.String> getSSWAPExceptionValues()
          Returns values, if any, for the SSWAP Exception Header(s).
 boolean hasErrorCode()
          Return whether or not this has an error result
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SSWAP_HTTP_EXCEPTION_HEADER

private static final java.lang.String SSWAP_HTTP_EXCEPTION_HEADER
See Also:
Constant Field Values

response

private com.clarkparsia.utils.web.Response response

sswapDocument

private SSWAPDocument sswapDocument

exception

private java.lang.Exception exception
Constructor Detail

AbstractHTTPResponse

public AbstractHTTPResponse(SSWAPDocument sswapDocument,
                            com.clarkparsia.utils.web.Response response)
The constructor sets the SSWAPDocument and response object. Connection is automatically closed in the constructor if and only if there is a non-null SSWAPDocument.

Parameters:
sswapDocument - the resultant SSWAPDocument from the invocation (e.g., RDG); may be null to indicate a failure to create a SSWAPDocument. In that case, the response object may be interrogated and should be closed when finished.
response - the network Response object from the invocation; may be null if it was impossible to establish an HTTP connection

AbstractHTTPResponse

public AbstractHTTPResponse(SSWAPDocument sswapDocument,
                            com.clarkparsia.utils.web.Response response,
                            java.lang.Exception exception)
The constructor sets the SSWAPDocument and response object. Connection is automatically closed in the constructor if and only if there is a non-null SSWAPDocument.

Parameters:
sswapDocument - the resultant SSWAPDocument from the invocation (e.g., RDG); may be null to indicate a failure to create a SSWAPDocument. In that case, the response object may be interrogated and should be closed when finished.
response - the network Response object from the invocation; may be null if it was impossible to establish an HTTP connection
exception - the exception that occurred during the invocation (may be null for successful invocations).
Method Detail

getDocument

protected SSWAPDocument getDocument()
Concrete class should use this method and cast to return a specific type of SSWAPModel.

Returns:
the response document, or null on failure.

getErrorStream

public java.io.InputStream getErrorStream()
Description copied from interface: HTTPResponse
Return the error stream from the connection

Specified by:
getErrorStream in interface HTTPResponse
Returns:
the error stream

getMessage

public java.lang.String getMessage()
Description copied from interface: HTTPResponse
Return the response message from the server

Specified by:
getMessage in interface HTTPResponse
Returns:
the message

getHeaders

public java.util.Collection<java.lang.String> getHeaders()
Description copied from interface: HTTPResponse
Return all headers returned by the server

Specified by:
getHeaders in interface HTTPResponse
Returns:
a Map of each header name and a List of its values

getHeaderValue

public java.lang.String getHeaderValue(java.lang.String headerName)
Description copied from interface: HTTPResponse
Returns the unparsed value of the HTTP header

Specified by:
getHeaderValue in interface HTTPResponse
Parameters:
headerName - the header name
Returns:
the header value; null if a header for headerName does not exist

getHeaderValues

public java.util.Collection<java.lang.String> getHeaderValues(java.lang.String headerName)
Description copied from interface: HTTPResponse
Returns the values of the HTTP header parsed on the comma delimiter

Specified by:
getHeaderValues in interface HTTPResponse
Parameters:
headerName - the header name
Returns:
the header values; null if a header for headerName does not exist

getSSWAPExceptionValues

public java.util.Collection<java.lang.String> getSSWAPExceptionValues()
Description copied from interface: HTTPResponse
Returns values, if any, for the SSWAP Exception Header(s). If there are no exceptions the collection will be empty, but not null.

Specified by:
getSSWAPExceptionValues in interface HTTPResponse
Returns:
SSWAP over HTTP Exception messages
See Also:
HTTPResponse.getSSWAPExceptionHeader()

getSSWAPExceptionHeader

public java.lang.String getSSWAPExceptionHeader()
Description copied from interface: HTTPResponse
Returns the header being used for SSWAP Exceptions.

Specified by:
getSSWAPExceptionHeader in interface HTTPResponse
Returns:
SSWAP Exception header
See Also:
HTTPResponse.getSSWAPExceptionValues()

getException

public java.lang.Exception getException()
Not currently exposed in the RRGResponse interface.

Specified by:
getException in interface HTTPResponse
Returns:
exception; may be null

getResponseCode

public int getResponseCode()
Description copied from interface: HTTPResponse
Return the response code

Specified by:
getResponseCode in interface HTTPResponse
Returns:
the response code

getContent

public java.io.InputStream getContent()
Description copied from interface: HTTPResponse
Return the response content from the server

Specified by:
getContent in interface HTTPResponse
Returns:
the response content

hasErrorCode

public boolean hasErrorCode()
Description copied from interface: HTTPResponse
Return whether or not this has an error result

Specified by:
hasErrorCode in interface HTTPResponse
Returns:
true if there is an error result, false otherwise

close

public void close()
           throws java.io.IOException
Description copied from interface: HTTPResponse
Close this response

Specified by:
close in interface HTTPResponse
Throws:
java.io.IOException - if there is an error while closing


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.