com.buglabs.util.simplerestclient
Class HTTPResponse

java.lang.Object
  extended by com.buglabs.util.simplerestclient.HTTPResponse

public class HTTPResponse
extends java.lang.Object

Class for wrapping the response connection. This is returned when calling get/post/put/delete/head on an HttpRequest object Use this object to check status code and get data from request


Field Summary
static int HTTP_CODE_BAD_REQUEST
          400 general error
static int HTTP_CODE_CREATED
          201 resource created
static int HTTP_CODE_INTERNAL_ERROR
          500 internal/application error
static int HTTP_CODE_NOT_AUTHORIZED
          401 not authorized
static int HTTP_CODE_NOT_FOUND
          404 not found
static int HTTP_CODE_OK
          200 general success
static int HTTP_CODE_UNSUPPORTED_TYPE
          415 unsupported media type
 
Constructor Summary
HTTPResponse(java.net.HttpURLConnection connection)
          constructor must take in an HttpURLConnection
 
Method Summary
 void checkStatus()
          Check the response status in http header throw error if an error status is returned
 java.lang.String getErrorMessage()
          Get error message out of connection
 java.lang.String getHeaderField(java.lang.String key)
          Gets a header value from the http response
 int getResponseCode()
          get response code from request
 java.io.InputStream getStream()
          Get an input stream from the connection
 java.lang.String getString()
          Get a string from the connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_CODE_OK

public static final int HTTP_CODE_OK
200 general success

See Also:
Constant Field Values

HTTP_CODE_CREATED

public static final int HTTP_CODE_CREATED
201 resource created

See Also:
Constant Field Values

HTTP_CODE_BAD_REQUEST

public static final int HTTP_CODE_BAD_REQUEST
400 general error

See Also:
Constant Field Values

HTTP_CODE_NOT_AUTHORIZED

public static final int HTTP_CODE_NOT_AUTHORIZED
401 not authorized

See Also:
Constant Field Values

HTTP_CODE_NOT_FOUND

public static final int HTTP_CODE_NOT_FOUND
404 not found

See Also:
Constant Field Values

HTTP_CODE_UNSUPPORTED_TYPE

public static final int HTTP_CODE_UNSUPPORTED_TYPE
415 unsupported media type

See Also:
Constant Field Values

HTTP_CODE_INTERNAL_ERROR

public static final int HTTP_CODE_INTERNAL_ERROR
500 internal/application error

See Also:
Constant Field Values
Constructor Detail

HTTPResponse

public HTTPResponse(java.net.HttpURLConnection connection)
constructor must take in an HttpURLConnection

Method Detail

checkStatus

public void checkStatus()
                 throws java.io.IOException,
                        HTTPException
Check the response status in http header throw error if an error status is returned

Throws:
java.io.IOException
HTTPException

getStream

public java.io.InputStream getStream()
                              throws java.io.IOException,
                                     HTTPException
Get an input stream from the connection

Parameters:
connection -
Returns:
InputStream body of HTTP Response
Throws:
BugnetException
java.io.IOException
HTTPException

getString

public java.lang.String getString()
                           throws java.io.IOException,
                                  HTTPException
Get a string from the connection

Parameters:
connection -
Returns:
String body of HTTP Response
Throws:
java.io.IOException
HTTPException

getResponseCode

public int getResponseCode()
get response code from request

Parameters:
connection -
Returns:

getHeaderField

public java.lang.String getHeaderField(java.lang.String key)
Gets a header value from the http response

Parameters:
key -
Returns:

getErrorMessage

public java.lang.String getErrorMessage()
                                 throws java.io.IOException
Get error message out of connection

Parameters:
connection -
Returns:
Throws:
java.io.IOException