org.codegist.crest
Class HttpResponse

java.lang.Object
  extended by org.codegist.crest.HttpResponse

public class HttpResponse
extends Object

Http response for the a HttpRequest.

Response charset and mime type are retrieved on the Content-Type header.

If no valid charset and mimetype are found, it defaults respectively with ISO-8859-1 and text/html

If the response is GZipped, the Content-Encoding header must be set to gzip.

Author:
Laurent Gilles (laurent.gilles@codegist.org)

Constructor Summary
HttpResponse(HttpRequest request, int statusCode)
           
HttpResponse(HttpRequest request, int statusCode, Map<String,List<String>> headers)
           
HttpResponse(HttpRequest request, int statusCode, Map<String,List<String>> headers, HttpResource resource)
           
 
Method Summary
 Reader asReader()
          Get the response reader using the response charset (extracted from response header.)
 InputStream asStream()
          Get the response input stream.
 String asString()
          Returns the response as string.
 void close()
          Close the response.
 Charset getCharset()
           
 String getContentEncoding()
           
 List<String> getHeader(String name)
           
 String getMimeType()
           
 HttpRequest getRequest()
           
 int getStatusCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpResponse

public HttpResponse(HttpRequest request,
                    int statusCode)

HttpResponse

public HttpResponse(HttpRequest request,
                    int statusCode,
                    Map<String,List<String>> headers)

HttpResponse

public HttpResponse(HttpRequest request,
                    int statusCode,
                    Map<String,List<String>> headers,
                    HttpResource resource)
Parameters:
request - The original request
statusCode - the response status code
headers - response headers.
resource - underlying http resource
Method Detail

getMimeType

public String getMimeType()

getCharset

public Charset getCharset()

getContentEncoding

public String getContentEncoding()

getRequest

public HttpRequest getRequest()
Returns:
The original request

asReader

public Reader asReader()
                throws IllegalStateException
Get the response reader using the response charset (extracted from response header.)

Returns:
The response reader.
Throws:
IllegalStateException - if asString() has already been called

asStream

public InputStream asStream()
Get the response input stream. Use getCharset() to decode it.

Returns:
The response input stream.
Throws:
IllegalStateException - if asString() has already been called

asString

public String asString()
Returns the response as string. Calling this method will consume the response stream and any call to asReader() or asStream() will throw an IllegalStateException.

Can only be called if the reponse stream hasn't been consumed.

Returns:
the response as a string

getHeader

public List<String> getHeader(String name)

getStatusCode

public int getStatusCode()
Returns:
Http status code

close

public void close()
Close the response.


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.