com.github.kristofa.test.http
Class HttpRequestImpl

java.lang.Object
  extended by com.github.kristofa.test.http.HttpRequestImpl
All Implemented Interfaces:
HttpRequest

public class HttpRequestImpl
extends Object
implements HttpRequest


Constructor Summary
HttpRequestImpl()
          Creates a new unintialized instance.
HttpRequestImpl(HttpRequest request)
          Copy constructor.
 
Method Summary
 HttpRequestImpl content(byte[] content)
          Sets content of message body for request.
 HttpRequestImpl contentMatcher(ContentMatcher matcher)
          Sets ContentMatcher.
 boolean equals(Object obj)
          
 byte[] getContent()
          Get content for request.
 Set<HttpMessageHeader> getHttpMessageHeaders()
          Get http message headers.
 Set<HttpMessageHeader> getHttpMessageHeaders(String name)
          Get http message headers with given name/key.
 Method getMethod()
          Gets method for request.
 String getPath()
          Gets path for request without query parameters.
 Set<QueryParameter> getQueryParameters()
          Gets query parameters for request.
 Set<QueryParameter> getQueryParameters(String key)
          Gets query parameters with given key.
 int hashCode()
          
 HttpRequestImpl httpMessageHeader(String name, String value)
          Adds a Http message header.
 HttpRequestImpl method(Method method)
          Sets method for request.
 HttpRequestImpl path(String path)
          Sets path for request.
 HttpRequestImpl queryParameter(String key, String value)
          Adds a query parameter for request.
 HttpRequestImpl removeHttpMessageHeader(String name, String value)
          Removes Http message header with given name and value.
 HttpRequestImpl removeHttpMessageHeaders(String name)
          Removes all Http message headers with given name.
 HttpRequestImpl removeQueryParameter(String key, String value)
          Removes Query Parameter with given key and value.
 HttpRequestImpl removeQueryParameters(String key)
          Removes all Query Parameters that have given key.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpRequestImpl

public HttpRequestImpl()
Creates a new unintialized instance.


HttpRequestImpl

public HttpRequestImpl(HttpRequest request)
Copy constructor. Will initialize http request with content of given request.

Parameters:
request - Request to copy.
Method Detail

method

public HttpRequestImpl method(Method method)
Sets method for request.

Parameters:
method - Method for request.
Returns:
This http request.

content

public HttpRequestImpl content(byte[] content)
Sets content of message body for request.

Parameters:
content - Message body for request.
Returns:
This http request.

contentMatcher

public HttpRequestImpl contentMatcher(ContentMatcher matcher)
                               throws UnexpectedContentException
Sets ContentMatcher. It will be initialized with any existing data.

If not set a default ContentMatcher will be used which simply does an equals on byte array.

Parameters:
matcher - New Content matcher. Should not be null.
Returns:
This http request.
Throws:
UnexpectedContentException - In case the current content is incompatible with the new ContentMatcher. In this case the new matcher will not be set. The previous ContentMatcher will remain active.

path

public HttpRequestImpl path(String path)
Sets path for request.

Parameters:
path - Sets path for request.
Returns:
This http request.

queryParameter

public HttpRequestImpl queryParameter(String key,
                                      String value)
Adds a query parameter for request.

Parameters:
key - Parameter key. Should not be empty or null or blank.
value - Parameter value. Should not be empty or null or blank.
Returns:
This http request.

removeQueryParameter

public HttpRequestImpl removeQueryParameter(String key,
                                            String value)
Removes Query Parameter with given key and value.

Parameters:
key - Query parameter key.
value - Query parameter value.
Returns:
This http request.

removeQueryParameters

public HttpRequestImpl removeQueryParameters(String key)
Removes all Query Parameters that have given key.

Parameters:
key - Query parameter key.
Returns:
This http request.

httpMessageHeader

public HttpRequestImpl httpMessageHeader(String name,
                                         String value)
Adds a Http message header.

Parameters:
name - header name. Should not be null or blank.
value - header value. Should not be null or blank.
Returns:
This http request.

removeHttpMessageHeader

public HttpRequestImpl removeHttpMessageHeader(String name,
                                               String value)
Removes Http message header with given name and value.

Parameters:
name - Http message header name.
value - Http message header value.
Returns:
This http request.

removeHttpMessageHeaders

public HttpRequestImpl removeHttpMessageHeaders(String name)
Removes all Http message headers with given name.

Parameters:
name - Http message header name.
Returns:
This http request.

getMethod

public Method getMethod()
Gets method for request.

Specified by:
getMethod in interface HttpRequest
Returns:
Method for request.

getContent

public byte[] getContent()
Get content for request.

Specified by:
getContent in interface HttpRequest
Returns:
Content for request.

getPath

public String getPath()
Gets path for request without query parameters.

Specified by:
getPath in interface HttpRequest
Returns:
Path for request.

getQueryParameters

public Set<QueryParameter> getQueryParameters()
Gets query parameters for request.

Specified by:
getQueryParameters in interface HttpRequest
Returns:
Query parameters for request.

getHttpMessageHeaders

public Set<HttpMessageHeader> getHttpMessageHeaders()
Get http message headers.

Specified by:
getHttpMessageHeaders in interface HttpRequest
Returns:
Http message headers.

getQueryParameters

public Set<QueryParameter> getQueryParameters(String key)
Gets query parameters with given key.

Specified by:
getQueryParameters in interface HttpRequest
Parameters:
key - Query parameter key. Should not be null or blank.
Returns:
Query parameters with given key.

getHttpMessageHeaders

public Set<HttpMessageHeader> getHttpMessageHeaders(String name)
Get http message headers with given name/key.

Specified by:
getHttpMessageHeaders in interface HttpRequest
Parameters:
name - Name/key. Should not be null or blank.
Returns:
Http message headers with given name/key.

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014. All Rights Reserved.