|
47 | 47 | import org.apache.hc.client5.http.protocol.HttpClientContext; |
48 | 48 | import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; |
49 | 49 | import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder; |
| 50 | +import org.apache.hc.core5.http.ClassicHttpRequest; |
50 | 51 | import org.apache.hc.core5.http.ClassicHttpResponse; |
51 | 52 | import org.apache.hc.core5.http.ContentType; |
52 | 53 | import org.apache.hc.core5.http.HttpEntity; |
53 | 54 | import org.apache.hc.core5.http.HttpHost; |
54 | 55 | import org.apache.hc.core5.http.config.CharCodingConfig; |
55 | 56 | import org.apache.hc.core5.http.io.entity.InputStreamEntity; |
56 | 57 | import org.apache.hc.core5.http.io.entity.StringEntity; |
| 58 | +import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; |
57 | 59 | import org.apache.hc.core5.ssl.SSLContexts; |
58 | 60 |
|
59 | 61 | public class WireMockTestClient { |
@@ -107,6 +109,11 @@ public WireMockResponse get(String url, TestHttpHeader... headers) { |
107 | 109 | return executeMethodAndConvertExceptions(httpRequest, headers); |
108 | 110 | } |
109 | 111 |
|
| 112 | + public WireMockResponse getWithBody( |
| 113 | + String url, String body, String contentType, TestHttpHeader... headers) { |
| 114 | + return requestWithBody("GET", url, body, contentType, headers); |
| 115 | + } |
| 116 | + |
110 | 117 | public WireMockResponse getViaProxy(String url) { |
111 | 118 | return getViaProxy(url, port); |
112 | 119 | } |
@@ -171,7 +178,7 @@ public WireMockResponse patchWithBody( |
171 | 178 | } |
172 | 179 |
|
173 | 180 | private WireMockResponse requestWithBody( |
174 | | - HttpUriRequestBase request, String body, String contentType, TestHttpHeader... headers) { |
| 181 | + ClassicHttpRequest request, String body, String contentType, TestHttpHeader... headers) { |
175 | 182 | request.setEntity(new StringEntity(body, ContentType.create(contentType, "utf-8"))); |
176 | 183 | return executeMethodAndConvertExceptions(request, headers); |
177 | 184 | } |
@@ -236,11 +243,23 @@ public WireMockResponse delete(String url) { |
236 | 243 | return executeMethodAndConvertExceptions(httpDelete); |
237 | 244 | } |
238 | 245 |
|
| 246 | + public WireMockResponse deleteWithBody( |
| 247 | + String url, String body, String contentType, TestHttpHeader... headers) { |
| 248 | + return requestWithBody("DELETE", url, body, contentType, headers); |
| 249 | + } |
| 250 | + |
239 | 251 | public WireMockResponse options(String url, TestHttpHeader... headers) { |
240 | 252 | HttpOptions httpOptions = new HttpOptions(mockServiceUrlFor(url)); |
241 | 253 | return executeMethodAndConvertExceptions(httpOptions, headers); |
242 | 254 | } |
243 | 255 |
|
| 256 | + private WireMockResponse requestWithBody( |
| 257 | + String method, String url, String body, String contentType, TestHttpHeader[] headers) { |
| 258 | + String actualUrl = URI.create(url).isAbsolute() ? url : mockServiceUrlFor(url); |
| 259 | + ClassicHttpRequest httpRequest = ClassicRequestBuilder.create(method).setUri(actualUrl).build(); |
| 260 | + return requestWithBody(httpRequest, body, contentType, headers); |
| 261 | + } |
| 262 | + |
244 | 263 | public void addResponse(String responseSpecJson) { |
245 | 264 | addResponse(responseSpecJson, "utf-8"); |
246 | 265 | } |
@@ -318,7 +337,7 @@ private int postEmptyBodyAndReturnStatus(String url) { |
318 | 337 | } |
319 | 338 |
|
320 | 339 | private WireMockResponse executeMethodAndConvertExceptions( |
321 | | - HttpUriRequest httpRequest, TestHttpHeader... headers) { |
| 340 | + ClassicHttpRequest httpRequest, TestHttpHeader... headers) { |
322 | 341 | try { |
323 | 342 | for (TestHttpHeader header : headers) { |
324 | 343 | httpRequest.addHeader(header.getName(), header.getValue()); |
|
0 commit comments