|
7 | 7 | import com.fasterxml.jackson.core.JsonProcessingException; |
8 | 8 | import com.fasterxml.jackson.core.type.TypeReference; |
9 | 9 | import org.apache.commons.lang3.StringUtils; |
10 | | -import org.apache.http.HttpEntity; |
11 | | -import org.apache.http.HttpHost; |
12 | | -import org.apache.http.HttpResponse; |
13 | | -import org.apache.http.NameValuePair; |
| 10 | +import org.apache.http.*; |
14 | 11 | import org.apache.http.auth.AuthScope; |
15 | 12 | import org.apache.http.auth.UsernamePasswordCredentials; |
16 | 13 | import org.apache.http.client.CredentialsProvider; |
17 | 14 | import org.apache.http.client.HttpClient; |
18 | | -import org.apache.http.client.entity.EntityBuilder; |
19 | 15 | import org.apache.http.client.methods.HttpUriRequest; |
20 | 16 | import org.apache.http.client.methods.RequestBuilder; |
21 | 17 | import org.apache.http.entity.ContentType; |
| 18 | +import org.apache.http.entity.StringEntity; |
22 | 19 | import org.apache.http.entity.mime.HttpMultipartMode; |
23 | 20 | import org.apache.http.entity.mime.MultipartEntityBuilder; |
24 | 21 | import org.apache.http.impl.client.BasicCredentialsProvider; |
@@ -311,8 +308,7 @@ public <T> T post(String path, TypeReference<T> type, Object payload, List<NameV |
311 | 308 | .addParameters(queryParams.toArray(new NameValuePair[queryParams.size()])); |
312 | 309 | if (payload != null) { |
313 | 310 | validatePayload(payload); |
314 | | - String stringPayload = jsonConverter.serialize(payload); |
315 | | - requestBuilder.setEntity(EntityBuilder.create().setText(stringPayload).build()); |
| 311 | + requestBuilder.setEntity(new StringEntity(jsonConverter.serialize(payload), Consts.UTF_8)); |
316 | 312 | logDebugPrettyJson("POST request to {} entity \n{}", uri, payload); |
317 | 313 | } else { |
318 | 314 | LOGGER.debug("POST request to {}", uri); |
@@ -365,11 +361,10 @@ public <T> T put(String path, TypeReference<T> type, Object payload, List<NameVa |
365 | 361 | try { |
366 | 362 | String uri = getApiBasePath() + path; |
367 | 363 | validatePayload(payload); |
368 | | - HttpEntity httpEntity = EntityBuilder.create().setText(jsonConverter.serialize(payload)).build(); |
369 | 364 | RequestBuilder requestBuilder = RequestBuilder.put(uri) |
370 | 365 | .setHeader(CONTENT_TYPE, APPLICATION_JSON.getMimeType()) |
371 | 366 | .addParameters(queryParams.toArray(new NameValuePair[queryParams.size()])) |
372 | | - .setEntity(httpEntity); |
| 367 | + .setEntity(new StringEntity(jsonConverter.serialize(payload), Consts.UTF_8)); |
373 | 368 | logDebugPrettyJson("PUT request to {} entity \n{}", uri, payload); |
374 | 369 |
|
375 | 370 | return doRequest(requestBuilder, type); |
@@ -471,7 +466,7 @@ private <T> T doRequest(RequestBuilder requestBuilder, TypeReference<T> type) th |
471 | 466 | private void verifyResponse(int statusCode, HttpEntity httpEntity) throws IOException { |
472 | 467 | if (statusCode >= 400) { |
473 | 468 | ErrorMessage message; |
474 | | - String stringResponse = EntityUtils.toString(httpEntity, "UTF-8"); |
| 469 | + String stringResponse = EntityUtils.toString(httpEntity, Consts.UTF_8); |
475 | 470 | try { |
476 | 471 | message = jsonConverter.deserialize(stringResponse, of(ErrorMessage.class)); |
477 | 472 | } catch (CallfireClientException e) { |
|
0 commit comments