com.google.api.client.http
Class HttpResponse

java.lang.Object
  extended by com.google.api.client.http.HttpResponse

public final class HttpResponse
extends Object

HTTP response.

Implementation is not thread-safe.

Since:
1.0
Author:
Yaniv Inbar

Field Summary
 String contentEncoding
          Deprecated. (scheduled to be made private in 1.6) Use getContentEncoding()
 String contentType
          Deprecated. (scheduled to be made private in 1.6) Use getContentType()
 boolean disableContentLogging
          Deprecated. (scheduled to be made private in 1.6) Use getDisableContentLogging() or setDisableContentLogging(boolean)
 HttpHeaders headers
          Deprecated. (scheduled to be made private in 1.6) Use getHeaders()
 boolean isSuccessStatusCode
          Deprecated. (scheduled to be made private in 1.6) Use isSuccessStatusCode()
 HttpRequest request
          Deprecated. (scheduled to be made private in 1.6) Use getRequest()
 int statusCode
          Deprecated. (scheduled to be made private in 1.6) Use getStatusCode()
 String statusMessage
          Deprecated. (scheduled to be made private in 1.6) Use getStatusMessage()
 HttpTransport transport
          Deprecated. (scheduled to be made private in 1.6) Use getTransport()
 
Method Summary
 void disconnect()
          Disconnect using LowLevelHttpResponse.disconnect().
 InputStream getContent()
          Returns the content of the HTTP response.
 String getContentEncoding()
          Returns the content encoding or null for none.
 String getContentType()
          Returns the content type or null for none.
 boolean getDisableContentLogging()
          Sets whether to disable response content logging during getContent() (unless Level.ALL is loggable which forces all logging).
 HttpHeaders getHeaders()
          Returns the HTTP response headers.
 HttpParser getParser()
          Returns the HTTP response content parser to use for the content type of this HTTP response or null for none.
 HttpRequest getRequest()
          Returns the HTTP request.
 int getStatusCode()
          Returns the HTTP status code.
 String getStatusMessage()
          Returns the HTTP status message or null for none.
 HttpTransport getTransport()
          Returns the HTTP transport.
 void ignore()
          Closes the the content of the HTTP response from getContent(), ignoring any content.
 boolean isSuccessStatusCode()
          Returns whether received a successful HTTP status code >= 200 && < 300 (see getStatusCode()).
static boolean isSuccessStatusCode(int statusCode)
          Returns whether the given HTTP response status code is a success code >= 200 and < 300.
<T> T
parseAs(Class<T> dataClass)
          Parses the content of the HTTP response from getContent() and reads it into a data class of key/value pairs using the parser returned by getParser() .
 String parseAsString()
          Parses the content of the HTTP response from getContent() and reads it into a string.
 HttpResponse setDisableContentLogging(boolean disableContentLogging)
          Sets whether to disable response content logging during getContent() (unless Level.ALL is loggable which forces all logging).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contentEncoding

@Deprecated
public final String contentEncoding
Deprecated. (scheduled to be made private in 1.6) Use getContentEncoding()
Content encoding or null.


contentType

@Deprecated
public final String contentType
Deprecated. (scheduled to be made private in 1.6) Use getContentType()
Content type or null for none.


headers

@Deprecated
public final HttpHeaders headers
Deprecated. (scheduled to be made private in 1.6) Use getHeaders()
HTTP headers.

If a header name is used for multiple headers, only the last one is retained. The value is initialized to HttpRequest.responseHeaders before being parsed from the actual HTTP response headers.


isSuccessStatusCode

@Deprecated
public final boolean isSuccessStatusCode
Deprecated. (scheduled to be made private in 1.6) Use isSuccessStatusCode()
Whether received a successful status code >= 200 && < 300.


statusCode

@Deprecated
public final int statusCode
Deprecated. (scheduled to be made private in 1.6) Use getStatusCode()
Status code.


statusMessage

@Deprecated
public final String statusMessage
Deprecated. (scheduled to be made private in 1.6) Use getStatusMessage()
Status message or null.


transport

@Deprecated
public final HttpTransport transport
Deprecated. (scheduled to be made private in 1.6) Use getTransport()
HTTP transport.


request

@Deprecated
public final HttpRequest request
Deprecated. (scheduled to be made private in 1.6) Use getRequest()
HTTP request.

Since:
1.4

disableContentLogging

@Deprecated
public boolean disableContentLogging
Deprecated. (scheduled to be made private in 1.6) Use getDisableContentLogging() or setDisableContentLogging(boolean)
Whether to disable response content logging during getContent() (unless Level.ALL is loggable which forces all logging).

Useful for example if content has sensitive data such as an authentication token. Defaults to false.

Method Detail

getDisableContentLogging

public boolean getDisableContentLogging()
Sets whether to disable response content logging during getContent() (unless Level.ALL is loggable which forces all logging).

Since:
1.5

setDisableContentLogging

public HttpResponse setDisableContentLogging(boolean disableContentLogging)
Sets whether to disable response content logging during getContent() (unless Level.ALL is loggable which forces all logging).

Useful for example if content has sensitive data such as an authentication token. Defaults to false.

Since:
1.5

getContentEncoding

public String getContentEncoding()
Returns the content encoding or null for none.

Since:
1.5

getContentType

public String getContentType()
Returns the content type or null for none.

Since:
1.5

getHeaders

public HttpHeaders getHeaders()
Returns the HTTP response headers.

Since:
1.5

isSuccessStatusCode

public boolean isSuccessStatusCode()
Returns whether received a successful HTTP status code >= 200 && < 300 (see getStatusCode()).

Since:
1.5

getStatusCode

public int getStatusCode()
Returns the HTTP status code.

Since:
1.5

getStatusMessage

public String getStatusMessage()
Returns the HTTP status message or null for none.

Since:
1.5

getTransport

public HttpTransport getTransport()
Returns the HTTP transport.

Since:
1.5

getRequest

public HttpRequest getRequest()
Returns the HTTP request.

Since:
1.5

getContent

public InputStream getContent()
                       throws IOException
Returns the content of the HTTP response.

The result is cached, so subsequent calls will be fast.

Returns:
input stream content of the HTTP response or null for none
Throws:
IOException - I/O exception

ignore

public void ignore()
            throws IOException
Closes the the content of the HTTP response from getContent(), ignoring any content.

Throws:
IOException

disconnect

public void disconnect()
                throws IOException
Disconnect using LowLevelHttpResponse.disconnect().

Throws:
IOException
Since:
1.4

getParser

public HttpParser getParser()
Returns the HTTP response content parser to use for the content type of this HTTP response or null for none.


parseAs

public <T> T parseAs(Class<T> dataClass)
          throws IOException
Parses the content of the HTTP response from getContent() and reads it into a data class of key/value pairs using the parser returned by getParser() .

Returns:
parsed data class or null for no content
Throws:
IOException - I/O exception
IllegalArgumentException - if no parser is defined for the given content type or if there is no content type defined in the HTTP response

parseAsString

public String parseAsString()
                     throws IOException
Parses the content of the HTTP response from getContent() and reads it into a string.

Since this method returns "" for no content, a simpler check for no content is to check if getContent() is null.

Returns:
parsed string or "" for no content
Throws:
IOException - I/O exception

isSuccessStatusCode

public static boolean isSuccessStatusCode(int statusCode)
Returns whether the given HTTP response status code is a success code >= 200 and < 300.



Copyright © 2011 Google. All Rights Reserved.