Class DefaultResponseCreator
- java.lang.Object
- org.springframework.test.web.client.response.DefaultResponseCreator
- All Implemented Interfaces:
ResponseCreator
public class DefaultResponseCreator extends Object implements ResponseCreator
AResponseCreator
with builder-style methods for adding response details.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultResponseCreator(HttpStatus statusCode)
Protected constructor.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DefaultResponseCreator
body(byte[] content)
Set the body as a byte array.DefaultResponseCreator
body(String content)
Set the body as a UTF-8 String.DefaultResponseCreator
body(Resource resource)
Set the body as aResource
.DefaultResponseCreator
contentType(MediaType mediaType)
Set theContent-Type
header.ClientHttpResponse
createResponse(ClientHttpRequest request)
Create a response for the given request.DefaultResponseCreator
headers(HttpHeaders headers)
Copy all given headers.DefaultResponseCreator
location(URI location)
Set theLocation
header.
Constructor Detail
DefaultResponseCreator
protected DefaultResponseCreator(HttpStatus statusCode)
Protected constructor. Use static factory methods inMockRestResponseCreators
.
Method Detail
body
public DefaultResponseCreator body(String content)
Set the body as a UTF-8 String.
body
public DefaultResponseCreator body(byte[] content)
Set the body as a byte array.
body
public DefaultResponseCreator body(Resource resource)
Set the body as aResource
.
contentType
public DefaultResponseCreator contentType(MediaType mediaType)
Set theContent-Type
header.
location
public DefaultResponseCreator location(URI location)
Set theLocation
header.
headers
public DefaultResponseCreator headers(HttpHeaders headers)
Copy all given headers.
createResponse
public ClientHttpResponse createResponse(@Nullable 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