Class HttpRequest
-
- All Implemented Interfaces:
HttpMessage<HttpRequest,Body>,Message
public class HttpRequest extends RequestDefinition implements HttpMessage<HttpRequest,Body>
- Author:
- jamesdbloom
-
-
Constructor Summary
Constructors Constructor Description HttpRequest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequestclone()booleancontainsHeader(String name)Returns true if a header with the specified name has been addedbooleancontainsHeader(String name, String value)Returns true if a header with the specified name and value has been addedstatic HttpRequestdelete(String path)booleanequals(Object o)static HttpRequestget(String path)BodygetBody()StringgetBodyAsJsonOrXmlString()byte[]getBodyAsRawBytes()StringgetBodyAsString()List<X509Certificate>getClientCertificateChain()List<Cookie>getCookieList()CookiesgetCookies()StringgetFirstHeader(String name)StringgetFirstPathParameter(String name)StringgetFirstQueryStringParameter(String name)List<String>getHeader(String name)List<Header>getHeaderList()HeadersgetHeaders()StringgetLocalAddress()NottableStringgetMethod()StringgetMethod(String defaultValue)NottableStringgetPath()List<Parameter>getPathParameterList()ParametersgetPathParameters()ProtocolgetProtocol()List<Parameter>getQueryStringParameterList()ParametersgetQueryStringParameters()StringgetRemoteAddress()BooleangetRespondBeforeBody()SocketAddressgetSocketAddress()IntegergetStreamId()inthashCode()booleanhasPathParameter(String name, String value)booleanhasPathParameter(NottableString name, NottableString value)booleanhasQueryStringParameter(String name, String value)booleanhasQueryStringParameter(NottableString name, NottableString value)static HttpRequesthead(String path)BooleanisKeepAlive()BooleanisSecure()booleanmatches(String method)booleanmatches(String method, String... paths)static HttpRequestoptions(String path)static HttpRequestpatch(String path)static HttpRequestpost(String path)static HttpRequestput(String path)HttpRequestremoveHeader(String name)HttpRequestremoveHeader(NottableString name)HttpRequestreplaceHeader(Header header)Adds one header to match on as a Header object where the header values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)static HttpRequestrequest()static HttpRequestrequest(String path)HttpRequestshallowClone()InetSocketAddresssocketAddressFromHostHeader()static String[]splitHostPort(String hostPort)HttpRequestupdate(HttpRequest requestOverride, HttpRequestModifier requestModifier)HttpRequestwithBody(byte[] body)The body to match on as binary data such as a pdf or imageHttpRequestwithBody(String body)The exact string body to match on such as "this is an exact string body"HttpRequestwithBody(String body, Charset charset)The exact string body to match on such as "this is an exact string body"HttpRequestwithBody(Body body)The body match rules on such as using one of the Body subclasses as follows:HttpRequestwithClientCertificateChain(List<X509Certificate> clientCertificateChain)HttpRequestwithContentType(MediaType mediaType)HttpRequestwithCookie(String name, String value)Adds one cookie to match on, which the value is plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithCookie(Cookie cookie)Adds one cookie to match on as a Cookie object where the cookie values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithCookie(NottableString name, NottableString value)Adds one cookie to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithCookies(List<Cookie> cookies)The cookies to match on as a list of Cookie objects where the values or keys of each cookie can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithCookies(Cookie... cookies)The cookies to match on as a varags Cookie objects where the values or keys of each cookie can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithCookies(Cookies cookies)HttpRequestwithHeader(String name, String... values)Adds one header to match which can specified using plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithHeader(Header header)Adds one header to match on as a Header object where the header values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithHeader(NottableString name, NottableString... values)Adds one header to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can also be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithHeaders(List<Header> headers)The headers to match on as a list of Header objects where the values or keys of each header can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithHeaders(Header... headers)The headers to match on as a varags of Header objects where the values or keys of each header can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithHeaders(Headers headers)HttpRequestwithKeepAlive(Boolean isKeepAlive)Match on whether the request was made using an HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuseHttpRequestwithLocalAddress(String localAddress)HttpRequestwithMethod(String method)The HTTP method to match on such as "GET" or "POST"HttpRequestwithMethod(NottableString method)The HTTP method all method except a specific value using the "not" operator, for example this allows operations such as not("GET")HttpRequestwithMethodSchema(String method)The HTTP method to match on as a JSON Schema for example:HttpRequestwithPath(String path)The path to match on such as "/some_mocked_path" any servlet context path is ignored for matching and should not be specified here regex values are also supported such as ".HttpRequestwithPath(NottableString path)The path to not match on for example not("/some_mocked_path") with match any path not equal to "/some_mocked_path", the servlet context path is ignored for matching and should not be specified hereregex values are also supported such as not(".HttpRequestwithPathParameter(String name, String... values)Adds one path parameter to match which can specified using plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithPathParameter(NottableString name, NottableString... values)Adds one path parameter to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can also be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithPathParameter(Parameter parameter)Adds one path parameter to match on as a Parameter object where the parameter values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithPathParameters(List<Parameter> parameters)The path parameter to match on as a list of Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithPathParameters(Map<String,List<String>> parameters)The path parameter to match on as a Map<String, List<String>> where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithPathParameters(Parameter... parameters)The path parameter to match on as a varags Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithPathParameters(Parameters parameters)HttpRequestwithPathSchema(String path)The path to match on as a JSON Schema for example:HttpRequestwithProtocol(Protocol protocol)Match on whether the request was made over HTTP or HTTP2HttpRequestwithQueryStringParameter(String name, String... values)Adds one query string parameter to match which the values are plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithQueryStringParameter(NottableString name, NottableString... values)Adds one query string parameter to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can also be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithQueryStringParameter(Parameter parameter)Adds one query string parameter to match on as a Parameter object where the parameter values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithQueryStringParameters(List<Parameter> parameters)The query string parameters to match on as a list of Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithQueryStringParameters(Map<String,List<String>> parameters)The query string parameters to match on as a Map<String, List<String>> where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithQueryStringParameters(Parameter... parameters)The query string parameters to match on as a varags Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)HttpRequestwithQueryStringParameters(Parameters parameters)HttpRequestwithRemoteAddress(String remoteAddress)HttpRequestwithRespondBeforeBody(Boolean respondBeforeBody)Match this request without waiting for the body to be received, and send the configured response before the body is consumed.HttpRequestwithSchemaCookie(String name, String value)Adds one cookie to match on, which the value the values is JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)HttpRequestwithSchemaHeader(String name, String... values)Adds one header to match which the values are JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)HttpRequestwithSchemaPathParameter(String name, String... values)Adds one path parameter to match which the values are JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)HttpRequestwithSchemaQueryStringParameter(String name, String... values)Adds one query string parameter to match which the values are JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)HttpRequestwithSecure(Boolean isSecure)Match on whether the request was made over TLS or SSL (i.e.HttpRequestwithSocketAddress(Boolean isSecure, String host, Integer port)Specify remote address by attempting to derive it from the host header and / or the specified portHttpRequestwithSocketAddress(String host, Integer port)Specify remote address by attempting to derive it from the host header and / or the specified portHttpRequestwithSocketAddress(String host, Integer port, SocketAddress.Scheme scheme)Specify remote address if the remote address can't be derived from the host header, if no value is specified the host header will be used to determine remote addressHttpRequestwithSocketAddress(SocketAddress socketAddress)Specify remote address if the remote address can't be derived from the host header, if no value is specified the host header will be used to determine remote addressHttpRequestwithSocketAddressFromHostHeader()Specify remote address by attempting to derive it from the host headerHttpRequestwithStreamId(Integer streamId)HTTP2 stream id request was received on-
Methods inherited from class org.mockserver.model.RequestDefinition
cloneWithLogCorrelationId, getLogCorrelationId, withLogCorrelationId
-
Methods inherited from class org.mockserver.model.ObjectWithJsonToString
toString
-
Methods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
-
-
-
Method Detail
-
request
public static HttpRequest request()
-
request
public static HttpRequest request(String path)
-
get
public static HttpRequest get(String path)
-
post
public static HttpRequest post(String path)
-
put
public static HttpRequest put(String path)
-
delete
public static HttpRequest delete(String path)
-
patch
public static HttpRequest patch(String path)
-
head
public static HttpRequest head(String path)
-
options
public static HttpRequest options(String path)
-
isKeepAlive
public Boolean isKeepAlive()
-
withKeepAlive
public HttpRequest withKeepAlive(Boolean isKeepAlive)
Match on whether the request was made using an HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse- Parameters:
isKeepAlive- true if the request was made with an HTTP persistent connection
-
isSecure
public Boolean isSecure()
-
withSecure
public HttpRequest withSecure(Boolean isSecure)
Match on whether the request was made over TLS or SSL (i.e. HTTPS)- Parameters:
isSecure- true if the request was made with TLS or SSL
-
getRespondBeforeBody
public Boolean getRespondBeforeBody()
-
withRespondBeforeBody
public HttpRequest withRespondBeforeBody(Boolean respondBeforeBody)
Match this request without waiting for the body to be received, and send the configured response before the body is consumed. Matchers with respondBeforeBody=true must not specify a body matcher and must use a RESPONSE or ERROR action; combine with connectionOptions.closeSocket=true on the response to close the connection after the response is sent. Useful for testing client behaviour when a server responds and closes mid-upload.- Parameters:
respondBeforeBody- true to dispatch the matched response before the request body is read
-
getProtocol
public Protocol getProtocol()
-
withProtocol
public HttpRequest withProtocol(Protocol protocol)
Match on whether the request was made over HTTP or HTTP2- Parameters:
protocol- used to indicate HTTP or HTTP2
-
getStreamId
public Integer getStreamId()
-
withStreamId
public HttpRequest withStreamId(Integer streamId)
HTTP2 stream id request was received on- Parameters:
streamId- HTTP2 stream id request was received on
-
getClientCertificateChain
public List<X509Certificate> getClientCertificateChain()
-
withClientCertificateChain
public HttpRequest withClientCertificateChain(List<X509Certificate> clientCertificateChain)
-
getSocketAddress
public SocketAddress getSocketAddress()
-
withSocketAddress
public HttpRequest withSocketAddress(SocketAddress socketAddress)
Specify remote address if the remote address can't be derived from the host header, if no value is specified the host header will be used to determine remote address- Parameters:
socketAddress- the remote address to send request to
-
withSocketAddress
public HttpRequest withSocketAddress(String host, Integer port, SocketAddress.Scheme scheme)
Specify remote address if the remote address can't be derived from the host header, if no value is specified the host header will be used to determine remote address- Parameters:
host- the remote host or ip to send request toport- the remote port to send request toscheme- the scheme to use for remote socket
-
withSocketAddress
public HttpRequest withSocketAddress(String host, Integer port)
Specify remote address by attempting to derive it from the host header and / or the specified port- Parameters:
host- the remote host or ip to send request toport- the remote port to send request to
-
withSocketAddressFromHostHeader
public HttpRequest withSocketAddressFromHostHeader()
Specify remote address by attempting to derive it from the host header
-
withSocketAddress
public HttpRequest withSocketAddress(Boolean isSecure, String host, Integer port)
Specify remote address by attempting to derive it from the host header and / or the specified port- Parameters:
isSecure- true if the request was made with TLS or SSLhost- the remote host or ip to send request toport- the remote port to send request to
-
withLocalAddress
public HttpRequest withLocalAddress(String localAddress)
-
getLocalAddress
public String getLocalAddress()
-
withRemoteAddress
public HttpRequest withRemoteAddress(String remoteAddress)
-
getRemoteAddress
public String getRemoteAddress()
-
withMethod
public HttpRequest withMethod(String method)
The HTTP method to match on such as "GET" or "POST"- Parameters:
method- the HTTP method such as "GET" or "POST"
-
withMethodSchema
public HttpRequest withMethodSchema(String method)
The HTTP method to match on as a JSON Schema for example:{ "type": "string", "minLength": 2, "maxLength": 3 } or { "type": "string", "pattern": "^P.{2,3}$" } or { "type": "string", "format": "ipv4" }For full details of JSON Schema see, https://json-schema.org/understanding-json-schema/reference/string.html
- Parameters:
method- the HTTP method to match on as a JSON Schema
-
withMethod
public HttpRequest withMethod(NottableString method)
The HTTP method all method except a specific value using the "not" operator, for example this allows operations such as not("GET")- Parameters:
method- the HTTP method to not match on not("GET") or not("POST")
-
getMethod
public NottableString getMethod()
-
withPath
public HttpRequest withPath(String path)
The path to match on such as "/some_mocked_path" any servlet context path is ignored for matching and should not be specified here regex values are also supported such as ".*_path", see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html for full details of the supported regex syntax- Parameters:
path- the path such as "/some_mocked_path" or a regex
-
withPath
public HttpRequest withPath(NottableString path)
The path to not match on for example not("/some_mocked_path") with match any path not equal to "/some_mocked_path", the servlet context path is ignored for matching and should not be specified hereregex values are also supported such as not(".*_path"), see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html for full details of the supported regex syntax- Parameters:
path- the path to not match on such as not("/some_mocked_path") or not(".*_path")
-
withPathSchema
public HttpRequest withPathSchema(String path)
The path to match on as a JSON Schema for example:{ "type": "string", "minLength": 2, "maxLength": 3 } or { "type": "string", "pattern": "^simp.{2}$" } or { "type": "string", "format": "ipv4" }For full details of JSON Schema see, https://json-schema.org/understanding-json-schema/reference/string.html
- Parameters:
path- the path to match on as a JSON Schema
-
getPath
public NottableString getPath()
-
matches
public boolean matches(String method)
-
getPathParameters
public Parameters getPathParameters()
-
withPathParameters
public HttpRequest withPathParameters(Parameters parameters)
-
withPathParameters
public HttpRequest withPathParameters(List<Parameter> parameters)
The path parameter to match on as a list of Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameters- the list of Parameter objects where the values or keys of each parameter can be either a string or a regex
-
withPathParameters
public HttpRequest withPathParameters(Parameter... parameters)
The path parameter to match on as a varags Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameters- the varags Parameter objects where the values or keys of each parameter can be either a string or a regex
-
withPathParameters
public HttpRequest withPathParameters(Map<String,List<String>> parameters)
The path parameter to match on as a Map<String, List<String>> where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameters- the Map<String, List<String>> object where the values or keys of each parameter can be either a string or a regex
-
withPathParameter
public HttpRequest withPathParameter(Parameter parameter)
Adds one path parameter to match on as a Parameter object where the parameter values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameter- the Parameter object which can have a values list of strings or regular expressions
-
withPathParameter
public HttpRequest withPathParameter(String name, String... values)
Adds one path parameter to match which can specified using plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
name- the parameter namevalues- the parameter values which can be a varags of strings or regular expressions
-
withSchemaPathParameter
public HttpRequest withSchemaPathParameter(String name, String... values)
Adds one path parameter to match which the values are JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)- Parameters:
name- the parameter namevalues- the parameter values which can be a varags of JSON schemas
-
withPathParameter
public HttpRequest withPathParameter(NottableString name, NottableString... values)
Adds one path parameter to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can also be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
name- the parameter name as a NottableStringvalues- the parameter values which can be a varags of NottableStrings
-
hasPathParameter
public boolean hasPathParameter(NottableString name, NottableString value)
-
getQueryStringParameters
public Parameters getQueryStringParameters()
-
withQueryStringParameters
public HttpRequest withQueryStringParameters(Parameters parameters)
-
withQueryStringParameters
public HttpRequest withQueryStringParameters(List<Parameter> parameters)
The query string parameters to match on as a list of Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameters- the list of Parameter objects where the values or keys of each parameter can be either a string or a regex
-
withQueryStringParameters
public HttpRequest withQueryStringParameters(Parameter... parameters)
The query string parameters to match on as a varags Parameter objects where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameters- the varags Parameter objects where the values or keys of each parameter can be either a string or a regex
-
withQueryStringParameters
public HttpRequest withQueryStringParameters(Map<String,List<String>> parameters)
The query string parameters to match on as a Map<String, List<String>> where the values or keys of each parameter can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameters- the Map<String, List<String>> object where the values or keys of each parameter can be either a string or a regex
-
withQueryStringParameter
public HttpRequest withQueryStringParameter(Parameter parameter)
Adds one query string parameter to match on as a Parameter object where the parameter values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
parameter- the Parameter object which can have a values list of strings or regular expressions
-
withQueryStringParameter
public HttpRequest withQueryStringParameter(String name, String... values)
Adds one query string parameter to match which the values are plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
name- the parameter namevalues- the parameter values which can be a varags of strings or regular expressions
-
withSchemaQueryStringParameter
public HttpRequest withSchemaQueryStringParameter(String name, String... values)
Adds one query string parameter to match which the values are JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)- Parameters:
name- the parameter namevalues- the parameter values which can be a varags of JSON schemas
-
withQueryStringParameter
public HttpRequest withQueryStringParameter(NottableString name, NottableString... values)
Adds one query string parameter to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can also be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Parameters:
name- the parameter name as a NottableStringvalues- the parameter values which can be a varags of NottableStrings
-
hasQueryStringParameter
public boolean hasQueryStringParameter(NottableString name, NottableString value)
-
withBody
public HttpRequest withBody(String body)
The exact string body to match on such as "this is an exact string body"- Specified by:
withBodyin interfaceHttpMessage<HttpRequest,Body>- Parameters:
body- the body on such as "this is an exact string body"
-
withBody
public HttpRequest withBody(String body, Charset charset)
The exact string body to match on such as "this is an exact string body"- Specified by:
withBodyin interfaceHttpMessage<HttpRequest,Body>- Parameters:
body- the body on such as "this is an exact string body"charset- character set the string will be encoded in
-
withBody
public HttpRequest withBody(byte[] body)
The body to match on as binary data such as a pdf or image- Specified by:
withBodyin interfaceHttpMessage<HttpRequest,Body>- Parameters:
body- a byte array
-
withBody
public HttpRequest withBody(Body body)
The body match rules on such as using one of the Body subclasses as follows:exact string match: - exact("this is an exact string body");
or
- new StringBody("this is an exact string body")
regular expression match: - regex("username[a-z]{4}");
or
- new RegexBody("username[a-z]{4}");
json match: - json("{username: 'foo', password: 'bar'}");
or
- json("{username: 'foo', password: 'bar'}", MatchType.STRICT);
or
- new JsonBody("{username: 'foo', password: 'bar'}");
json schema match: - jsonSchema("{type: 'object', properties: { 'username': { 'type': 'string' }, 'password': { 'type': 'string' } }, 'required': ['username', 'password']}");
or
- jsonSchemaFromResource("org/mockserver/model/loginSchema.json");
or
- new JsonSchemaBody("{type: 'object', properties: { 'username': { 'type': 'string' }, 'password': { 'type': 'string' } }, 'required': ['username', 'password']}");
xpath match: - xpath("/element[key = 'some_key' and value = 'some_value']");
or
- new XPathBody("/element[key = 'some_key' and value = 'some_value']");
body parameter match: - params( param("name_one", "value_one_one", "value_one_two") param("name_two", "value_two") );
or
- new ParameterBody( new Parameter("name_one", "value_one_one", "value_one_two") new Parameter("name_two", "value_two") );
binary match: - binary(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
or
- new BinaryBody(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
for more details of the supported regular expression syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html for more details of the supported json syntax see http://jsonassert.skyscreamer.org for more details of the supported json schema syntax see http://json-schema.org/ for more detail of XPath syntax see http://saxon.sourceforge.net/saxon6.5.3/expressions.html
- Specified by:
withBodyin interfaceHttpMessage<HttpRequest,Body>- Parameters:
body- an instance of one of the Body subclasses including StringBody, ParameterBody or BinaryBody
-
getBody
public Body getBody()
- Specified by:
getBodyin interfaceHttpMessage<HttpRequest,Body>
-
getBodyAsRawBytes
public byte[] getBodyAsRawBytes()
- Specified by:
getBodyAsRawBytesin interfaceHttpMessage<HttpRequest,Body>
-
getBodyAsString
public String getBodyAsString()
- Specified by:
getBodyAsStringin interfaceHttpMessage<HttpRequest,Body>
-
getBodyAsJsonOrXmlString
public String getBodyAsJsonOrXmlString()
-
getHeaders
public Headers getHeaders()
- Specified by:
getHeadersin interfaceHttpMessage<HttpRequest,Body>
-
withHeaders
public HttpRequest withHeaders(Headers headers)
- Specified by:
withHeadersin interfaceHttpMessage<HttpRequest,Body>
-
withHeaders
public HttpRequest withHeaders(List<Header> headers)
The headers to match on as a list of Header objects where the values or keys of each header can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withHeadersin interfaceHttpMessage<HttpRequest,Body>- Parameters:
headers- the list of Header objects where the values or keys of each header can be either a string or a regex
-
withHeaders
public HttpRequest withHeaders(Header... headers)
The headers to match on as a varags of Header objects where the values or keys of each header can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withHeadersin interfaceHttpMessage<HttpRequest,Body>- Parameters:
headers- the varags of Header objects where the values or keys of each header can be either a string or a regex
-
withHeader
public HttpRequest withHeader(Header header)
Adds one header to match on as a Header object where the header values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withHeaderin interfaceHttpMessage<HttpRequest,Body>- Parameters:
header- the Header object which can have a values list of strings or regular expressions
-
withHeader
public HttpRequest withHeader(String name, String... values)
Adds one header to match which can specified using plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withHeaderin interfaceHttpMessage<HttpRequest,Body>- Parameters:
name- the header namevalues- the header values which can be a varags of strings or regular expressions
-
withSchemaHeader
public HttpRequest withSchemaHeader(String name, String... values)
Adds one header to match which the values are JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)- Parameters:
name- the header namevalues- the header values which can be a varags of JSON schemas
-
withHeader
public HttpRequest withHeader(NottableString name, NottableString... values)
Adds one header to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can also be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withHeaderin interfaceHttpMessage<HttpRequest,Body>- Parameters:
name- the header name as a NottableStringvalues- the header values which can be a varags of NottableStrings
-
withContentType
public HttpRequest withContentType(MediaType mediaType)
- Specified by:
withContentTypein interfaceHttpMessage<HttpRequest,Body>
-
replaceHeader
public HttpRequest replaceHeader(Header header)
Adds one header to match on as a Header object where the header values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
replaceHeaderin interfaceHttpMessage<HttpRequest,Body>- Parameters:
header- the Header object which can have a values list of strings or regular expressions
-
getHeaderList
public List<Header> getHeaderList()
- Specified by:
getHeaderListin interfaceHttpMessage<HttpRequest,Body>
-
getHeader
public List<String> getHeader(String name)
- Specified by:
getHeaderin interfaceHttpMessage<HttpRequest,Body>
-
getFirstHeader
public String getFirstHeader(String name)
- Specified by:
getFirstHeaderin interfaceHttpMessage<HttpRequest,Body>
-
containsHeader
public boolean containsHeader(String name)
Returns true if a header with the specified name has been added- Specified by:
containsHeaderin interfaceHttpMessage<HttpRequest,Body>- Parameters:
name- the header name- Returns:
- true if a header has been added with that name otherwise false
-
containsHeader
public boolean containsHeader(String name, String value)
Returns true if a header with the specified name and value has been added- Parameters:
name- the header namevalue- the header value- Returns:
- true if a header has been added with that name otherwise false
-
removeHeader
public HttpRequest removeHeader(String name)
- Specified by:
removeHeaderin interfaceHttpMessage<HttpRequest,Body>
-
removeHeader
public HttpRequest removeHeader(NottableString name)
- Specified by:
removeHeaderin interfaceHttpMessage<HttpRequest,Body>
-
getCookies
public Cookies getCookies()
- Specified by:
getCookiesin interfaceHttpMessage<HttpRequest,Body>
-
withCookies
public HttpRequest withCookies(Cookies cookies)
- Specified by:
withCookiesin interfaceHttpMessage<HttpRequest,Body>
-
withCookies
public HttpRequest withCookies(List<Cookie> cookies)
The cookies to match on as a list of Cookie objects where the values or keys of each cookie can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withCookiesin interfaceHttpMessage<HttpRequest,Body>- Parameters:
cookies- a list of Cookie objects
-
withCookies
public HttpRequest withCookies(Cookie... cookies)
The cookies to match on as a varags Cookie objects where the values or keys of each cookie can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withCookiesin interfaceHttpMessage<HttpRequest,Body>- Parameters:
cookies- a varargs of Cookie objects
-
withCookie
public HttpRequest withCookie(Cookie cookie)
Adds one cookie to match on as a Cookie object where the cookie values list can be a list of strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withCookiein interfaceHttpMessage<HttpRequest,Body>- Parameters:
cookie- a Cookie object
-
withCookie
public HttpRequest withCookie(String name, String value)
Adds one cookie to match on, which the value is plain strings or regular expressions (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withCookiein interfaceHttpMessage<HttpRequest,Body>- Parameters:
name- the cookies namevalue- the cookies value
-
withSchemaCookie
public HttpRequest withSchemaCookie(String name, String value)
Adds one cookie to match on, which the value the values is JSON schema i.e. "{ \"type\": \"string\", \"pattern\": \"^someV[a-z]{4}$\" }" (for more details of the supported JSON schema see https://json-schema.org)- Parameters:
name- the cookies namevalue- the cookies value as JSON schema
-
withCookie
public HttpRequest withCookie(NottableString name, NottableString value)
Adds one cookie to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString can be a plain string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)- Specified by:
withCookiein interfaceHttpMessage<HttpRequest,Body>- Parameters:
name- the cookies namevalue- the cookies value
-
getCookieList
public List<Cookie> getCookieList()
- Specified by:
getCookieListin interfaceHttpMessage<HttpRequest,Body>
-
socketAddressFromHostHeader
public InetSocketAddress socketAddressFromHostHeader()
-
shallowClone
public HttpRequest shallowClone()
- Specified by:
shallowClonein classRequestDefinition
-
clone
public HttpRequest clone()
-
update
public HttpRequest update(HttpRequest requestOverride, HttpRequestModifier requestModifier)
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classRequestDefinition
-
hashCode
public int hashCode()
- Overrides:
hashCodein classRequestDefinition
-
-