31
31
import org .springframework .http .HttpStatus ;
32
32
import org .springframework .http .MediaType ;
33
33
import org .springframework .http .ResponseCookie ;
34
+ import org .springframework .http .client .reactive .ClientHttpRequest ;
35
+ import org .springframework .http .client .reactive .ClientHttpResponse ;
34
36
import org .springframework .lang .Nullable ;
35
37
import org .springframework .util .Assert ;
36
38
import org .springframework .util .MultiValueMap ;
@@ -58,31 +60,41 @@ public class ExchangeResult {
58
60
MediaType .parseMediaType ("text/*" ), MediaType .APPLICATION_FORM_URLENCODED );
59
61
60
62
61
- private final WiretapClientHttpRequest request ;
63
+ private final ClientHttpRequest request ;
62
64
63
- private final WiretapClientHttpResponse response ;
65
+ private final ClientHttpResponse response ;
66
+
67
+ private final MonoProcessor <byte []> requestBody ;
68
+
69
+ private final MonoProcessor <byte []> responseBody ;
64
70
65
71
@ Nullable
66
72
private final String uriTemplate ;
67
73
68
74
69
75
/**
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
72
84
*/
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
+
74
94
this .request = request ;
75
95
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 ;
86
98
this .uriTemplate = uriTemplate ;
87
99
}
88
100
@@ -92,6 +104,8 @@ public class ExchangeResult {
92
104
ExchangeResult (ExchangeResult other ) {
93
105
this .request = other .request ;
94
106
this .response = other .response ;
107
+ this .requestBody = other .requestBody ;
108
+ this .responseBody = other .responseBody ;
95
109
this .uriTemplate = other .uriTemplate ;
96
110
}
97
111
@@ -131,7 +145,7 @@ public HttpHeaders getRequestHeaders() {
131
145
*/
132
146
@ Nullable
133
147
public byte [] getRequestBodyContent () {
134
- MonoProcessor <byte []> body = this .request . getRecordedContent () ;
148
+ MonoProcessor <byte []> body = this .requestBody ;
135
149
Assert .isTrue (body .isTerminated (), "Request body incomplete." );
136
150
return body .block (Duration .ZERO );
137
151
}
@@ -164,7 +178,7 @@ public MultiValueMap<String, ResponseCookie> getResponseCookies() {
164
178
*/
165
179
@ Nullable
166
180
public byte [] getResponseBodyContent () {
167
- MonoProcessor <byte []> body = this .response . getRecordedContent () ;
181
+ MonoProcessor <byte []> body = this .responseBody ;
168
182
Assert .state (body .isTerminated (), "Response body incomplete" );
169
183
return body .block (Duration .ZERO );
170
184
}
@@ -191,12 +205,12 @@ public String toString() {
191
205
"> " + getMethod () + " " + getUrl () + "\n " +
192
206
"> " + formatHeaders (getRequestHeaders (), "\n > " ) + "\n " +
193
207
"\n " +
194
- formatBody (getRequestHeaders ().getContentType (), this .request . getRecordedContent () ) + "\n " +
208
+ formatBody (getRequestHeaders ().getContentType (), this .requestBody ) + "\n " +
195
209
"\n " +
196
210
"< " + getStatus () + " " + getStatusReason () + "\n " +
197
211
"< " + formatHeaders (getResponseHeaders (), "\n < " ) + "\n " +
198
212
"\n " +
199
- formatBody (getResponseHeaders ().getContentType (), this .response . getRecordedContent () ) +"\n " ;
213
+ formatBody (getResponseHeaders ().getContentType (), this .responseBody ) +"\n " ;
200
214
}
201
215
202
216
private String getStatusReason () {
0 commit comments