3131import org .springframework .http .HttpStatus ;
3232import org .springframework .http .MediaType ;
3333import org .springframework .http .ResponseCookie ;
34+ import org .springframework .http .client .reactive .ClientHttpRequest ;
35+ import org .springframework .http .client .reactive .ClientHttpResponse ;
3436import org .springframework .lang .Nullable ;
3537import org .springframework .util .Assert ;
3638import org .springframework .util .MultiValueMap ;
@@ -58,31 +60,41 @@ public class ExchangeResult {
5860 MediaType .parseMediaType ("text/*" ), MediaType .APPLICATION_FORM_URLENCODED );
5961
6062
61- private final WiretapClientHttpRequest request ;
63+ private final ClientHttpRequest request ;
6264
63- private final WiretapClientHttpResponse response ;
65+ private final ClientHttpResponse response ;
66+
67+ private final MonoProcessor <byte []> requestBody ;
68+
69+ private final MonoProcessor <byte []> responseBody ;
6470
6571 @ Nullable
6672 private final String uriTemplate ;
6773
6874
6975 /**
70- * Constructor to use after the server response is first received in the
71- * {@link WiretapConnector} and the {@code ClientHttpResponse} created.
76+ * Create an instance with an HTTP request and response along with promises
77+ * for the serialized request and response body content.
78+ *
79+ * @param request the HTTP request
80+ * @param response the HTTP response
81+ * @param requestBody capture of serialized request body content
82+ * @param responseBody capture of serialized response body content
83+ * @param uriTemplate the URI template used to set up the request, if any
7284 */
73- ExchangeResult (WiretapClientHttpRequest request , WiretapClientHttpResponse response ) {
85+ ExchangeResult (ClientHttpRequest request , ClientHttpResponse response ,
86+ MonoProcessor <byte []> requestBody , MonoProcessor <byte []> responseBody ,
87+ @ Nullable String uriTemplate ) {
88+
89+ Assert .notNull (request , "ClientHttpRequest is required" );
90+ Assert .notNull (response , "ClientHttpResponse is required" );
91+ Assert .notNull (requestBody , "'requestBody' is required" );
92+ Assert .notNull (responseBody , "'responseBody' is required" );
93+
7494 this .request = request ;
7595 this .response = response ;
76- this .uriTemplate = null ;
77- }
78-
79- /**
80- * Constructor to copy the from the yet undecoded ExchangeResult with extra
81- * information to expose such as the original URI template used, if any.
82- */
83- ExchangeResult (ExchangeResult other , @ Nullable String uriTemplate ) {
84- this .request = other .request ;
85- this .response = other .response ;
96+ this .requestBody = requestBody ;
97+ this .responseBody = responseBody ;
8698 this .uriTemplate = uriTemplate ;
8799 }
88100
@@ -92,6 +104,8 @@ public class ExchangeResult {
92104 ExchangeResult (ExchangeResult other ) {
93105 this .request = other .request ;
94106 this .response = other .response ;
107+ this .requestBody = other .requestBody ;
108+ this .responseBody = other .responseBody ;
95109 this .uriTemplate = other .uriTemplate ;
96110 }
97111
@@ -131,7 +145,7 @@ public HttpHeaders getRequestHeaders() {
131145 */
132146 @ Nullable
133147 public byte [] getRequestBodyContent () {
134- MonoProcessor <byte []> body = this .request . getRecordedContent () ;
148+ MonoProcessor <byte []> body = this .requestBody ;
135149 Assert .isTrue (body .isTerminated (), "Request body incomplete." );
136150 return body .block (Duration .ZERO );
137151 }
@@ -164,7 +178,7 @@ public MultiValueMap<String, ResponseCookie> getResponseCookies() {
164178 */
165179 @ Nullable
166180 public byte [] getResponseBodyContent () {
167- MonoProcessor <byte []> body = this .response . getRecordedContent () ;
181+ MonoProcessor <byte []> body = this .responseBody ;
168182 Assert .state (body .isTerminated (), "Response body incomplete" );
169183 return body .block (Duration .ZERO );
170184 }
@@ -191,12 +205,12 @@ public String toString() {
191205 "> " + getMethod () + " " + getUrl () + "\n " +
192206 "> " + formatHeaders (getRequestHeaders (), "\n > " ) + "\n " +
193207 "\n " +
194- formatBody (getRequestHeaders ().getContentType (), this .request . getRecordedContent () ) + "\n " +
208+ formatBody (getRequestHeaders ().getContentType (), this .requestBody ) + "\n " +
195209 "\n " +
196210 "< " + getStatus () + " " + getStatusReason () + "\n " +
197211 "< " + formatHeaders (getResponseHeaders (), "\n < " ) + "\n " +
198212 "\n " +
199- formatBody (getResponseHeaders ().getContentType (), this .response . getRecordedContent () ) +"\n " ;
213+ formatBody (getResponseHeaders ().getContentType (), this .responseBody ) +"\n " ;
200214 }
201215
202216 private String getStatusReason () {
0 commit comments