Class ExecutingResponseCreator

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

public class ExecutingResponseCreator extends Object implements ResponseCreator
ResponseCreator that obtains the response by executing the request through a ClientHttpRequestFactory. This is useful in scenarios with multiple remote services where some need to be called rather than mocked.

The ClientHttpRequestFactory is typically obtained from the RestTemplate before it is passed to MockRestServiceServer, in effect using the original factory rather than the test factory:


 ResponseCreator withActualResponse = new ExecutingResponseCreator(restTemplate);
 MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
 //...
 server.expect(requestTo("/foo")).andRespond(withSuccess());
 server.expect(requestTo("/bar")).andRespond(withActualResponse);
 
Since:
6.0.4
Author:
Simon Baslé
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExecutingResponseCreator(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
    Create an instance with the given ClientHttpRequestFactory.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.client.ClientHttpResponse
    createResponse(org.springframework.http.client.ClientHttpRequest request)
    Create a response for the given request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExecutingResponseCreator

      public ExecutingResponseCreator(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
      Create an instance with the given ClientHttpRequestFactory.
      Parameters:
      requestFactory - the request factory to delegate to
  • Method Details

    • createResponse

      public org.springframework.http.client.ClientHttpResponse createResponse(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