Class DefaultResponseCreator
java.lang.Object
org.springframework.test.web.client.response.DefaultResponseCreator
- All Implemented Interfaces:
ResponseCreator
A
ResponseCreator
with builder-style methods for adding response details.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
-
Constructor Summary
ModifierConstructorDescriptionprotected
DefaultResponseCreator
(int statusCode) Protected constructor.protected
DefaultResponseCreator
(org.springframework.http.HttpStatusCode statusCode) Protected constructor. -
Method Summary
Modifier and TypeMethodDescriptionbody
(byte[] content) Set the body as a byte array.Set the body as a UTF-8 String.Set the body from a string using the given character set.body
(org.springframework.core.io.Resource resource) Set the body from aResource
.contentType
(org.springframework.http.MediaType mediaType) Set theContent-Type
header.cookies
(org.springframework.http.ResponseCookie... cookies) Add one or more cookies.cookies
(org.springframework.util.MultiValueMap<String, org.springframework.http.ResponseCookie> multiValueMap) Copy all cookies from the givenMultiValueMap
.org.springframework.http.client.ClientHttpResponse
createResponse
(org.springframework.http.client.ClientHttpRequest request) Create a response for the given request.Add a response header with one or more values.headers
(org.springframework.http.HttpHeaders headers) Copy all given headers.Set theLocation
header.
-
Constructor Details
-
DefaultResponseCreator
protected DefaultResponseCreator(int statusCode) Protected constructor. Use static factory methods inMockRestResponseCreators
.- Since:
- 5.3.17
-
DefaultResponseCreator
protected DefaultResponseCreator(org.springframework.http.HttpStatusCode statusCode) Protected constructor. Use static factory methods inMockRestResponseCreators
.
-
-
Method Details
-
body
Set the body as a UTF-8 String. -
body
Set the body from a string using the given character set.- Since:
- 6.0
-
body
Set the body as a byte array. -
body
Set the body from aResource
. -
contentType
Set theContent-Type
header. -
location
Set theLocation
header. -
header
Add a response header with one or more values.- Since:
- 6.0
-
headers
Copy all given headers. -
cookies
Add one or more cookies.- Since:
- 6.0
-
cookies
public DefaultResponseCreator cookies(org.springframework.util.MultiValueMap<String, org.springframework.http.ResponseCookie> multiValueMap) Copy all cookies from the givenMultiValueMap
.- Since:
- 6.0
-
createResponse
public org.springframework.http.client.ClientHttpResponse createResponse(@Nullable org.springframework.http.client.ClientHttpRequest request) throws IOException Description copied from interface:ResponseCreator
Create a response for the given request.- Specified by:
createResponse
in interfaceResponseCreator
- Parameters:
request
- the request- Throws:
IOException
-