Class DefaultResponseCreator

java.lang.Object
org.springframework.test.web.client.response.DefaultResponseCreator
All Implemented Interfaces:
ResponseCreator

public class DefaultResponseCreator extends Object implements ResponseCreator
A ResponseCreator with builder-style methods for adding response details.
Since:
3.2
Author:
Rossen Stoyanchev
  • Constructor Details

    • DefaultResponseCreator

      protected DefaultResponseCreator(int statusCode)
      Protected constructor. Use static factory methods in MockRestResponseCreators.
      Since:
      5.3.17
    • DefaultResponseCreator

      protected DefaultResponseCreator(org.springframework.http.HttpStatusCode statusCode)
      Protected constructor. Use static factory methods in MockRestResponseCreators.
  • Method Details

    • body

      public DefaultResponseCreator body(String content)
      Set the body as a UTF-8 String.
    • body

      public DefaultResponseCreator body(String content, Charset charset)
      Set the body from a string using the given character set.
      Since:
      6.0
    • body

      public DefaultResponseCreator body(byte[] content)
      Set the body as a byte array.
    • body

      public DefaultResponseCreator body(org.springframework.core.io.Resource resource)
      Set the body from a Resource.
    • contentType

      public DefaultResponseCreator contentType(org.springframework.http.MediaType mediaType)
      Set the Content-Type header.
    • location

      public DefaultResponseCreator location(URI location)
      Set the Location header.
    • header

      public DefaultResponseCreator header(String name, String... headerValues)
      Add a response header with one or more values.
      Since:
      6.0
    • headers

      public DefaultResponseCreator headers(org.springframework.http.HttpHeaders headers)
      Copy all given headers.
    • cookies

      public DefaultResponseCreator cookies(org.springframework.http.ResponseCookie... 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 given MultiValueMap.
      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 interface ResponseCreator
      Parameters:
      request - the request
      Throws:
      IOException