org.webbitserver.stub
Class StubHttpRequest

java.lang.Object
  extended by org.webbitserver.stub.StubDataHolder
      extended by org.webbitserver.stub.StubHttpRequest
All Implemented Interfaces:
DataHolder, HttpRequest

public class StubHttpRequest
extends StubDataHolder
implements HttpRequest

Implementation of HttpRequest that is easy to construct manually and populate. Useful for testing.


Field Summary
 
Fields inherited from interface org.webbitserver.HttpRequest
COOKIE_HEADER
 
Constructor Summary
StubHttpRequest()
           
StubHttpRequest(String uri)
           
 
Method Summary
 List<Map.Entry<String,String>> allHeaders()
          Returns all headers sent from client.
 String body()
          The body
 StubHttpRequest body(String body)
           
 byte[] bodyAsBytes()
          The body's byte array
 HttpCookie cookie(String name)
          Get a cookie with a specific name
 List<HttpCookie> cookies()
           
 String cookieValue(String name)
          Get the value of named cookie
 StubHttpRequest data(String key, Object value)
          Store data value by key.
 boolean hasHeader(String name)
          Whether a specific HTTP header was present in the request.
 String header(String name)
          Retrieve the value single HTTP header.
 StubHttpRequest header(String name, String value)
           
 List<String> headers(String name)
          Retrieve all values for an HTTP header.
 Object id()
          A unique identifier for this request.
 StubHttpRequest id(Object id)
           
 String method()
          HTTP method (e.g.
 StubHttpRequest method(String method)
           
 String postParam(String key)
          Get post parameter value.
 Set<String> postParamKeys()
          List all post parameter keys.
 List<String> postParams(String key)
          Get all post parameter values.
 String queryParam(String key)
          Get query parameter value.
 Set<String> queryParamKeys()
          List all query parameter keys.
 List<String> queryParams(String key)
          Get all query parameter values.
 SocketAddress remoteAddress()
          Remote address of connection (i.e.
 StubHttpRequest remoteAddress(SocketAddress remoteAddress)
           
 long timestamp()
          Timestamp (millis since epoch) of when this request was first received by the server.
 StubHttpRequest timestamp(long timestamp)
           
 String uri()
           
 StubHttpRequest uri(String uri)
          Modify uri
 
Methods inherited from class org.webbitserver.stub.StubDataHolder
data, data, dataKeys
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.webbitserver.DataHolder
data, data, dataKeys
 

Constructor Detail

StubHttpRequest

public StubHttpRequest()

StubHttpRequest

public StubHttpRequest(String uri)
Method Detail

uri

public String uri()
Specified by:
uri in interface HttpRequest

uri

public StubHttpRequest uri(String uri)
Description copied from interface: HttpRequest
Modify uri

Specified by:
uri in interface HttpRequest
Parameters:
uri - new uri

header

public String header(String name)
Description copied from interface: HttpRequest
Retrieve the value single HTTP header.

If the header is not found, null is returned.

If there are multiple headers with the same name, it will return one of them, but it is not defined which one. Instead, use HttpRequest.headers(String).

Specified by:
header in interface HttpRequest

hasHeader

public boolean hasHeader(String name)
Description copied from interface: HttpRequest
Whether a specific HTTP header was present in the request.

Specified by:
hasHeader in interface HttpRequest

cookies

public List<HttpCookie> cookies()
Specified by:
cookies in interface HttpRequest
Returns:
all inbound cookies

cookie

public HttpCookie cookie(String name)
Description copied from interface: HttpRequest
Get a cookie with a specific name

Specified by:
cookie in interface HttpRequest
Parameters:
name - cookie name
Returns:
cookie with that name

queryParam

public String queryParam(String key)
Description copied from interface: HttpRequest
Get query parameter value.

Specified by:
queryParam in interface HttpRequest
Parameters:
key - parameter name
Returns:
the value of the parameter
See Also:
HttpRequest.queryParams(String)

queryParams

public List<String> queryParams(String key)
Description copied from interface: HttpRequest
Get all query parameter values.

Specified by:
queryParams in interface HttpRequest
Parameters:
key - parameter name
Returns:
the values of the parameter
See Also:
HttpRequest.queryParam(String)

queryParamKeys

public Set<String> queryParamKeys()
Description copied from interface: HttpRequest
List all query parameter keys.

Specified by:
queryParamKeys in interface HttpRequest
See Also:
HttpRequest.queryParam(String)

postParam

public String postParam(String key)
Description copied from interface: HttpRequest
Get post parameter value.

Specified by:
postParam in interface HttpRequest
Parameters:
key - parameter name
Returns:
the value of the parameter
See Also:
HttpRequest.postParams(String)

postParams

public List<String> postParams(String key)
Description copied from interface: HttpRequest
Get all post parameter values.

Specified by:
postParams in interface HttpRequest
Parameters:
key - parameter name
Returns:
the values of the parameter
See Also:
HttpRequest.postParam(String)

postParamKeys

public Set<String> postParamKeys()
Description copied from interface: HttpRequest
List all post parameter keys.

Specified by:
postParamKeys in interface HttpRequest
See Also:
HttpRequest.postParam(String)

cookieValue

public String cookieValue(String name)
Description copied from interface: HttpRequest
Get the value of named cookie

Specified by:
cookieValue in interface HttpRequest
Parameters:
name - cookie name
Returns:
cookie value, or null if the cookie does not exist.

headers

public List<String> headers(String name)
Description copied from interface: HttpRequest
Retrieve all values for an HTTP header. If no values are found, an empty List is returned.

Specified by:
headers in interface HttpRequest

allHeaders

public List<Map.Entry<String,String>> allHeaders()
Description copied from interface: HttpRequest
Returns all headers sent from client.

Specified by:
allHeaders in interface HttpRequest

method

public String method()
Description copied from interface: HttpRequest
HTTP method (e.g. "GET" or "POST")

Specified by:
method in interface HttpRequest

body

public String body()
Description copied from interface: HttpRequest
The body

Specified by:
body in interface HttpRequest

bodyAsBytes

public byte[] bodyAsBytes()
Description copied from interface: HttpRequest
The body's byte array

Specified by:
bodyAsBytes in interface HttpRequest

body

public StubHttpRequest body(String body)

method

public StubHttpRequest method(String method)

header

public StubHttpRequest header(String name,
                              String value)

data

public StubHttpRequest data(String key,
                            Object value)
Description copied from interface: DataHolder
Store data value by key.

Specified by:
data in interface DataHolder
Specified by:
data in interface HttpRequest
Overrides:
data in class StubDataHolder
See Also:
DataHolder.data()

remoteAddress

public SocketAddress remoteAddress()
Description copied from interface: HttpRequest
Remote address of connection (i.e. the host of the client).

Specified by:
remoteAddress in interface HttpRequest

id

public Object id()
Description copied from interface: HttpRequest
A unique identifier for this request. This should be treated as an opaque object, that can be used to track the lifecycle of a request.

Specified by:
id in interface HttpRequest

id

public StubHttpRequest id(Object id)

timestamp

public long timestamp()
Description copied from interface: HttpRequest
Timestamp (millis since epoch) of when this request was first received by the server.

Specified by:
timestamp in interface HttpRequest

timestamp

public StubHttpRequest timestamp(long timestamp)

remoteAddress

public StubHttpRequest remoteAddress(SocketAddress remoteAddress)


Copyright © 2012. All Rights Reserved.