net.craftforge.essential.client
Class ClientResponse

java.lang.Object
  extended by net.craftforge.essential.client.ClientResponse

public class ClientResponse
extends Object

A client response is used to provide a normalized response output for a client.

Since:
04.07.11
Author:
Christian Bick

Constructor Summary
ClientResponse(int statusCode, Map<String,String[]> headers, InputStream bodyInputStream)
          Creates a client response using the given HTTP status code, response headers and response body.
 
Method Summary
 String getAuthorizationPassword()
          Gets the password from the authorization header.
 String getAuthorizationUser()
          Gets the user from the authorization header.
 String getBodyContent()
          Gets the HTTP response body string.
 InputStream getBodyInputStream()
          Gets the HTTP response body input stream.
 Object getBodyObject(Consumer consumer, Class<?> clazz)
          Gets the HTTP response body as an object of the given class.
 String getContentCharset()
          Gets the response body's charset encoding from the Content-Type header.
 String getContentMediaType()
          Gets the response body's media type from the Content-Type header.
 int getStatusCode()
          Gets the HTTP status code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientResponse

public ClientResponse(int statusCode,
                      Map<String,String[]> headers,
                      InputStream bodyInputStream)
Creates a client response using the given HTTP status code, response headers and response body.

Parameters:
statusCode - The HTTP status code
headers - The HTTP response headers
bodyInputStream - The HTTP response body input stream
Method Detail

getStatusCode

public int getStatusCode()
Gets the HTTP status code.

Returns:
The HTTP status code

getBodyInputStream

public InputStream getBodyInputStream()
Gets the HTTP response body input stream.

Returns:
The HTTP response body input stream

getBodyContent

public String getBodyContent()
Gets the HTTP response body string. Uses the charset from in the Content-Type header for decoding if specified there. Assumes UTF-8 otherwise.

Returns:
The response body string

getBodyObject

public Object getBodyObject(Consumer consumer,
                            Class<?> clazz)
                     throws ControllerException
Gets the HTTP response body as an object of the given class. Uses the media type from the Content-Type header for deligating the deserialization to right consumer method. Uses the charset from the Content-Type header for decoding. Assumes text/xml as media type and UTF-8 as charset if not specified in the Content-Type header.

Parameters:
consumer - The consumer
clazz - The class
Returns:
The response body object
Throws:
ControllerException - if the deserialization fails

getContentMediaType

public String getContentMediaType()
Gets the response body's media type from the Content-Type header. Assumes the media type to be text/xml if it is not specified in the header.

Returns:
The response body's media type

getContentCharset

public String getContentCharset()
Gets the response body's charset encoding from the Content-Type header. Assumes the charset encoding to be UTF-8 if it is not specified in the header.

Returns:
The response body's charset encoding

getAuthorizationUser

public String getAuthorizationUser()
Gets the user from the authorization header.

Returns:
The authorization user

getAuthorizationPassword

public String getAuthorizationPassword()
Gets the password from the authorization header.

Returns:
The authorization password


Copyright © 2011. All Rights Reserved.