net.craftforge.essential.client
Class ClientRequest

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

public class ClientRequest
extends Object

A client request is used to provide a normalized request input for a client.

Since:
04.07.11
Author:
Christian Bick

Constructor Summary
ClientRequest(String httpMethod, String urlInfoPart)
          Creates a client request.
 
Method Summary
 Map<String,String[]> getHeaders()
          Gets the HTTP request headers.
 String getHttpMethod()
          Gets the HTTP request method.
 Map<String,String[]> getParameters()
          Gets the HTTP request parameters.
 InputStream getRequestBody()
          Gets the HTTP request body.
 String getUrlInfoPart()
          Gets the request URL info part.
 void setAuthorization(String username, String password)
          Sets the HTTP request authorization header.
 void setBody(InputStream bodyInputStream, String mediaType)
          Sets the request body input stream for this request and specifies the media type used in the Content-Type header.
 void setBody(InputStream bodyInputStream, String mediaType, String charset)
          Sets the request body input stream for this request and specifies the media type and charset used in the Content-Type header.
 void setBody(Object object, Producer producer, String mediaType)
          Sets the request body for this request and specifies the media type and charset used in the Content-Type header.
 void setBody(Object object, Producer producer, String mediaType, String charset)
          Sets the request body for this request and specifies the media type and charset used in the Content-Type header.
 void setBody(String bodyContent, String mediaType)
          Sets the request body for this request and specifies the media type used in the Content-Type header.
 void setBody(String bodyContent, String mediaType, String charset)
          Sets the request body for this request and specifies the media type and charset used in the Content-Type header.
 void setHeader(String headerName, String headerValue)
          Sets the header with the given header name to the specified header value.
 void setHeader(String headerName, String[] headerValues)
          Sets the header with the given header name to the specified header values.
 void setHeaders(Map<String,String[]> headers)
          Sets the headers.
 void setParameter(String parameterName, String parameterValue)
          Sets the parameter with the given parameter name to the specified parameter value.
 void setParameter(String parameterName, String[] parameterValues)
          Sets the parameter with the given parameter name to the specified parameter values.
 void setParameters(Map<String,String[]> parameters)
          Sets the parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientRequest

public ClientRequest(String httpMethod,
                     String urlInfoPart)
Creates a client request. Uses the specified HTTP method and allocates the resource using the URL info part. Will use default headers and no query parameters.

Parameters:
httpMethod - The HTTP request method
urlInfoPart - The request URL info part
Method Detail

getHttpMethod

public String getHttpMethod()
Gets the HTTP request method.

Returns:
The HTTP request method

getUrlInfoPart

public String getUrlInfoPart()
Gets the request URL info part.

Returns:
The URL info part

getHeaders

public Map<String,String[]> getHeaders()
Gets the HTTP request headers.

Returns:
The HTTP request headers

getParameters

public Map<String,String[]> getParameters()
Gets the HTTP request parameters.

Returns:
The HTTP request parameters

getRequestBody

public InputStream getRequestBody()
Gets the HTTP request body.

Returns:
The HTTP request body

setAuthorization

public void setAuthorization(String username,
                             String password)
Sets the HTTP request authorization header.

Parameters:
username - The authorization username
password - The authorization password

setBody

public void setBody(String bodyContent,
                    String mediaType)
Sets the request body for this request and specifies the media type used in the Content-Type header. Uses UTF-8 as charset.

Parameters:
bodyContent - The body content as a string
mediaType - The media type

setBody

public void setBody(String bodyContent,
                    String mediaType,
                    String charset)
Sets the request body for this request and specifies the media type and charset used in the Content-Type header.

Parameters:
bodyContent - The body content as a string
mediaType - The media type
charset - The charset

setBody

public void setBody(InputStream bodyInputStream,
                    String mediaType)
Sets the request body input stream for this request and specifies the media type used in the Content-Type header. Uses UTF-8 as charset.

Parameters:
bodyInputStream - The body as an input stream
mediaType - The media type

setBody

public void setBody(InputStream bodyInputStream,
                    String mediaType,
                    String charset)
Sets the request body input stream for this request and specifies the media type and charset used in the Content-Type header.

Parameters:
bodyInputStream - The body as an input stream
mediaType - The media type
charset - The charset

setBody

public void setBody(Object object,
                    Producer producer,
                    String mediaType)
             throws ControllerException
Sets the request body for this request and specifies the media type and charset used in the Content-Type header. Uses UTF-8 as charset.

Parameters:
object - The request body as an object
producer - The producer to serialize the object
mediaType - The media type
Throws:
ControllerException - if the object serialization process fails

setBody

public void setBody(Object object,
                    Producer producer,
                    String mediaType,
                    String charset)
             throws ControllerException
Sets the request body for this request and specifies the media type and charset used in the Content-Type header.

Parameters:
object - The request body as an object
producer - The producer to serialize the object
mediaType - The media type
charset - The charset
Throws:
ControllerException - if the object serialization process fails

setHeader

public void setHeader(String headerName,
                      String headerValue)
Sets the header with the given header name to the specified header value. Will overwrite any existing header data with the same header name.

Parameters:
headerName - The header name
headerValue - The header value

setHeader

public void setHeader(String headerName,
                      String[] headerValues)
Sets the header with the given header name to the specified header values. Will overwrite any existing header data with the same header name.

Parameters:
headerName - The header name
headerValues - The header values

setHeaders

public void setHeaders(Map<String,String[]> headers)
Sets the headers.

Parameters:
headers - The headers

setParameter

public void setParameter(String parameterName,
                         String parameterValue)
Sets the parameter with the given parameter name to the specified parameter value. Will overwrite any existing parameter data with the same parameter name.

Parameters:
parameterName - The parameter name
parameterValue - The parameter value

setParameter

public void setParameter(String parameterName,
                         String[] parameterValues)
Sets the parameter with the given parameter name to the specified parameter values. Will overwrite any existing parameter data with the same parameter name.

Parameters:
parameterName - The parameter name
parameterValues - The parameter values

setParameters

public void setParameters(Map<String,String[]> parameters)
Sets the parameters.

Parameters:
parameters - The parameters


Copyright © 2011. All Rights Reserved.