Package com.consol.citrus.http.message
Class HttpMessage
- java.lang.Object
-
- com.consol.citrus.message.DefaultMessage
-
- com.consol.citrus.http.message.HttpMessage
-
- All Implemented Interfaces:
Message
,Serializable
public class HttpMessage extends DefaultMessage
- Since:
- 2.0
- Author:
- Christoph Deppisch
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description HttpMessage()
Empty constructor initializing with empty message payload.HttpMessage(Message message)
Constructs copy of given message.HttpMessage(Object payload)
Default message using message payload.HttpMessage(Object payload, Map<String,Object> headers)
Default message using message payload and headers.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpMessage
accept(String accept)
Sets the Http accepted content type header for response.HttpMessage
addHeaderData(String headerData)
HttpMessage
contentType(String contentType)
Sets the Http request content type header.HttpMessage
contextPath(String contextPath)
Sets the Http request context path header.HttpMessage
cookie(javax.servlet.http.Cookie cookie)
Adds new cookie to this http message.static HttpMessage
fromRequestData(String requestData)
Reads request from complete request dump.static HttpMessage
fromResponseData(String responseData)
Reads response from complete response dump.String
getAccept()
Gets the accept header.String
getContentType()
Gets the Http content type header.String
getContextPath()
Gets the Http request context path.List<javax.servlet.http.Cookie>
getCookies()
Gets the cookies.String
getPath()
Gets the request path after the context path.Map<String,Collection<String>>
getQueryParams()
Gets the Http request query params.String
getQueryParamString()
Gets the Http request query param string.String
getReasonPhrase()
Gets the Http response reason phrase.org.springframework.http.HttpMethod
getRequestMethod()
Gets the Http request method.org.springframework.http.HttpStatus
getStatusCode()
Gets the Http response status code.String
getUri()
Gets the Http request request uri.String
getVersion()
Gets the Http version.HttpMessage
header(String headerName, Object headerValue)
Sets new header name value pair.HttpMessage
method(org.springframework.http.HttpMethod method)
Sets the Http request method header.HttpMessage
path(String path)
Sets request path that is dynamically added to base uri.HttpMessage
queryParam(String name)
Sets a new Http request query param.HttpMessage
queryParam(String name, String value)
Sets a new Http request query param.HttpMessage
queryParams(String queryParamString)
Sets the Http request query params query String.HttpMessage
reasonPhrase(String reasonPhrase)
Sets the Http response reason phrase header.void
setCookies(javax.servlet.http.Cookie[] cookies)
Sets the cookies.HttpMessage
setHeader(String headerName, Object headerValue)
HttpMessage
status(org.springframework.http.HttpStatus statusCode)
Sets the Http response status code.HttpMessage
statusCode(Integer statusCode)
Sets the Http response status code header.HttpMessage
uri(String requestUri)
Sets the Http request request uri header.HttpMessage
version(String version)
Sets the Http version header.-
Methods inherited from class com.consol.citrus.message.DefaultMessage
getHeader, getHeaderData, getHeaders, getId, getName, getPayload, getPayload, getTimestamp, getType, removeHeader, setName, setPayload, setType, setType, toString
-
-
-
-
Constructor Detail
-
HttpMessage
public HttpMessage()
Empty constructor initializing with empty message payload.
-
HttpMessage
public HttpMessage(Message message)
Constructs copy of given message.- Parameters:
message
- The base message for the copy operation
-
HttpMessage
public HttpMessage(Object payload)
Default message using message payload.- Parameters:
payload
- The payload for the message to set
-
-
Method Detail
-
method
public HttpMessage method(org.springframework.http.HttpMethod method)
Sets the Http request method header.- Parameters:
method
- The Http method header to use- Returns:
- The altered HttpMessage
-
version
public HttpMessage version(String version)
Sets the Http version header.- Parameters:
version
- The http version header value to use- Returns:
- The altered HttpMessage
-
status
public HttpMessage status(org.springframework.http.HttpStatus statusCode)
Sets the Http response status code.- Parameters:
statusCode
- The status code header to respond with- Returns:
- The altered HttpMessage
-
statusCode
public HttpMessage statusCode(Integer statusCode)
Sets the Http response status code header.- Parameters:
statusCode
- The status code header value to respond with- Returns:
- The altered HttpMessage
-
reasonPhrase
public HttpMessage reasonPhrase(String reasonPhrase)
Sets the Http response reason phrase header.- Parameters:
reasonPhrase
- The reason phrase header value to use- Returns:
- The altered HttpMessage
-
uri
public HttpMessage uri(String requestUri)
Sets the Http request request uri header.- Parameters:
requestUri
- The request uri header value to use- Returns:
- The altered HttpMessage
-
contentType
public HttpMessage contentType(String contentType)
Sets the Http request content type header.- Parameters:
contentType
- The content type header value to use- Returns:
- The altered HttpMessage
-
accept
public HttpMessage accept(String accept)
Sets the Http accepted content type header for response.- Parameters:
accept
- The accept header value to set- Returns:
- The altered HttpMessage
-
contextPath
public HttpMessage contextPath(String contextPath)
Sets the Http request context path header.- Parameters:
contextPath
- The context path header value to use- Returns:
- The altered HttpMessage
-
queryParams
public HttpMessage queryParams(String queryParamString)
Sets the Http request query params query String. Query String is a compilation of key-value pairs separated by comma character e.g. key1=value1[","key2=value2]. Query String can be empty.- Parameters:
queryParamString
- The query parameter string to evaluate- Returns:
- The altered HttpMessage
-
queryParam
public HttpMessage queryParam(String name)
Sets a new Http request query param.- Parameters:
name
- The name of the request query parameter- Returns:
- The altered HttpMessage
-
queryParam
public HttpMessage queryParam(String name, String value)
Sets a new Http request query param.- Parameters:
name
- The name of the request query parametervalue
- The value of the request query parameter- Returns:
- The altered HttpMessage
-
path
public HttpMessage path(String path)
Sets request path that is dynamically added to base uri.- Parameters:
path
- The part of the path to add- Returns:
- The altered HttpMessage
-
header
public HttpMessage header(String headerName, Object headerValue)
Sets new header name value pair.- Parameters:
headerName
- The name of the headerheaderValue
- The value of the header- Returns:
- The altered HttpMessage
-
setHeader
public HttpMessage setHeader(String headerName, Object headerValue)
- Specified by:
setHeader
in interfaceMessage
- Overrides:
setHeader
in classDefaultMessage
-
addHeaderData
public HttpMessage addHeaderData(String headerData)
- Specified by:
addHeaderData
in interfaceMessage
- Overrides:
addHeaderData
in classDefaultMessage
-
getRequestMethod
public org.springframework.http.HttpMethod getRequestMethod()
Gets the Http request method.- Returns:
- The used HttpMethod
-
getUri
public String getUri()
Gets the Http request request uri.- Returns:
- The request uri
-
getContextPath
public String getContextPath()
Gets the Http request context path.- Returns:
- the context path
-
getContentType
public String getContentType()
Gets the Http content type header.- Returns:
- the content type header value
-
getAccept
public String getAccept()
Gets the accept header.- Returns:
- The accept header value
-
getQueryParams
public Map<String,Collection<String>> getQueryParams()
Gets the Http request query params.- Returns:
- The query parameters as a key value map
-
getQueryParamString
public String getQueryParamString()
Gets the Http request query param string.- Returns:
- The query parameter as string
-
getStatusCode
public org.springframework.http.HttpStatus getStatusCode()
Gets the Http response status code.- Returns:
- The status code of the message
-
getReasonPhrase
public String getReasonPhrase()
Gets the Http response reason phrase.- Returns:
- The reason phrase of the message
-
getVersion
public String getVersion()
Gets the Http version.- Returns:
- The http version of the message
-
getPath
public String getPath()
Gets the request path after the context path.- Returns:
- The request path of the message
-
getCookies
public List<javax.servlet.http.Cookie> getCookies()
Gets the cookies.- Returns:
- The list of cookies for this message
-
setCookies
public void setCookies(javax.servlet.http.Cookie[] cookies)
Sets the cookies.- Parameters:
cookies
- The cookies to set
-
cookie
public HttpMessage cookie(javax.servlet.http.Cookie cookie)
Adds new cookie to this http message.- Parameters:
cookie
- The Cookie to set- Returns:
- The altered HttpMessage
-
fromRequestData
public static HttpMessage fromRequestData(String requestData)
Reads request from complete request dump.- Parameters:
requestData
- The request dump to parse- Returns:
- The parsed dump as HttpMessage
-
fromResponseData
public static HttpMessage fromResponseData(String responseData)
Reads response from complete response dump.- Parameters:
responseData
- The response dump to parse- Returns:
- The parsed dump as HttpMessage
-
-