Class HttpResponse
java.lang.Object
de.gematik.test.tiger.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
de.gematik.test.tiger.mockserver.model.ObjectWithJsonToString
de.gematik.test.tiger.mockserver.model.Action<HttpResponse>
de.gematik.test.tiger.mockserver.model.HttpResponse
- All Implemented Interfaces:
HttpMessage<HttpResponse,,BodyWithContentType> Message
public class HttpResponse
extends Action<HttpResponse>
implements HttpMessage<HttpResponse,BodyWithContentType>
-
Nested Class Summary
Nested classes/interfaces inherited from class de.gematik.test.tiger.mockserver.model.Action
Action.Direction, Action.Type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanclone()booleancontainsHeader(String name, String value) Returns true if a header with the specified name has been addedbooleangetBody()byte[]getFirstHeader(String name) intgetType()inthashCode()static HttpResponseStatic builder to create a not found response.removeHeader(String name) replaceHeader(Header header) Update header to return as a Header object, if a header with the same name already exists it will be modifiedstatic HttpResponseresponse()Static builder to create a response.static HttpResponseStatic builder to create a response with a 200 status code and the string response body.voidsetBody(BodyWithContentType body) voidsetCookies(Cookies cookies) voidsetHashCode(int hashCode) voidsetHeaders(Headers headers) voidsetReasonPhrase(String reasonPhrase) voidsetStatusCode(Integer statusCode) voidsetStreamId(Integer streamId) toString()withBody(byte[] body) Set response body to return as binary such as a pdf or imagewithBody(BodyWithContentType body) Set the body to return for example:Set response body to return as a string response body.Set response body to return a string response body with the specified encoding.Set response body to return a string response body with the specified encoding.withCookies(Cookies cookies) withHeader(Header header) Add a header to return as a Header object, if a header with the same name already exists this will NOT be modified but two headers will existwithHeader(String name, String... values) Add a header to return as a Header object, if a header with the same name already exists this will NOT be modified but two headers will existwithHeaders(Headers headers) withReasonPhrase(String reasonPhrase) The reason phrase to return, if no reason code is returned this will be defaulted to the standard reason phrase for the statusCode, i.e. for a statusCode of 200 the standard reason phrase is "OK"withStatusCode(Integer statusCode) The status code to return, such as 200, 404, the status code specified here will result in the default status message for this status code for example for 200 the status message "OK" is usedwithStreamId(Integer streamId) voidwrite(NettyResponseWriter nettyResponseWriter, HttpRequest request) Methods inherited from class de.gematik.test.tiger.mockserver.model.Action
getExpectationId, setExpectationIdMethods inherited from class de.gematik.test.tiger.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
Constructor Details
-
HttpResponse
public HttpResponse()
-
-
Method Details
-
response
Static builder to create a response. -
response
Static builder to create a response with a 200 status code and the string response body.- Parameters:
body- a string
-
notFoundResponse
Static builder to create a not found response. -
withStatusCode
The status code to return, such as 200, 404, the status code specified here will result in the default status message for this status code for example for 200 the status message "OK" is used- Parameters:
statusCode- an integer such as 200 or 404
-
withReasonPhrase
The reason phrase to return, if no reason code is returned this will be defaulted to the standard reason phrase for the statusCode, i.e. for a statusCode of 200 the standard reason phrase is "OK"- Parameters:
reasonPhrase- an string such as "Not Found" or "OK"
-
withBody
Set response body to return as a string response body. The character set will be determined by the Content-Type header on the response. To force the character set, usewithBody(String, Charset).- Specified by:
withBodyin interfaceHttpMessage<HttpResponse,BodyWithContentType> - Parameters:
body- a string
-
withBody
Set response body to return a string response body with the specified encoding. Note: The character set of the response will be forced to the specified charset, even if the Content-Type header specifies otherwise.- Specified by:
withBodyin interfaceHttpMessage<HttpResponse,BodyWithContentType> - Parameters:
body- a stringcharset- character set the string will be encoded in
-
withBody
Set response body to return a string response body with the specified encoding. Note: The character set of the response will be forced to the specified charset, even if the Content-Type header specifies otherwise.- Parameters:
body- a stringcontentType- media type, if charset is included this will be used for encoding string
-
withBody
Set response body to return as binary such as a pdf or image- Specified by:
withBodyin interfaceHttpMessage<HttpResponse,BodyWithContentType> - Parameters:
body- a byte array
-
withBody
Set the body to return for example:string body: - exact("
a simple string body");or
- new StringBody("
a simple string body")binary body: - binary(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
or
- new BinaryBody(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
-