Skip to content

Commit 5c27cc7

Browse files
committed
set json content encoding to utf-8
1 parent 50d45d6 commit 5c27cc7

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Callfire API client Changelog
22
=============================
3+
4+
Version 1.7.17 - Nov 14 2017
5+
- set json content encoding to UTF-8
6+
37
Version 1.7.16 - Jun 15 2017
48
- added fromNumber to Recipient object for sending calls/texts
59
- added strictValidation flag for adding contacts to broadcast

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group = com.callfire
22
baseName = callfire-api-client
3-
version = 1.7.16
3+
version = 1.7.17

src/main/java/com/callfire/api/client/RestApiClient.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
import com.fasterxml.jackson.core.JsonProcessingException;
88
import com.fasterxml.jackson.core.type.TypeReference;
99
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.*;
1411
import org.apache.http.auth.AuthScope;
1512
import org.apache.http.auth.UsernamePasswordCredentials;
1613
import org.apache.http.client.CredentialsProvider;
1714
import org.apache.http.client.HttpClient;
18-
import org.apache.http.client.entity.EntityBuilder;
1915
import org.apache.http.client.methods.HttpUriRequest;
2016
import org.apache.http.client.methods.RequestBuilder;
2117
import org.apache.http.entity.ContentType;
18+
import org.apache.http.entity.StringEntity;
2219
import org.apache.http.entity.mime.HttpMultipartMode;
2320
import org.apache.http.entity.mime.MultipartEntityBuilder;
2421
import org.apache.http.impl.client.BasicCredentialsProvider;
@@ -311,8 +308,7 @@ public <T> T post(String path, TypeReference<T> type, Object payload, List<NameV
311308
.addParameters(queryParams.toArray(new NameValuePair[queryParams.size()]));
312309
if (payload != null) {
313310
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));
316312
logDebugPrettyJson("POST request to {} entity \n{}", uri, payload);
317313
} else {
318314
LOGGER.debug("POST request to {}", uri);
@@ -365,11 +361,10 @@ public <T> T put(String path, TypeReference<T> type, Object payload, List<NameVa
365361
try {
366362
String uri = getApiBasePath() + path;
367363
validatePayload(payload);
368-
HttpEntity httpEntity = EntityBuilder.create().setText(jsonConverter.serialize(payload)).build();
369364
RequestBuilder requestBuilder = RequestBuilder.put(uri)
370365
.setHeader(CONTENT_TYPE, APPLICATION_JSON.getMimeType())
371366
.addParameters(queryParams.toArray(new NameValuePair[queryParams.size()]))
372-
.setEntity(httpEntity);
367+
.setEntity(new StringEntity(jsonConverter.serialize(payload), Consts.UTF_8));
373368
logDebugPrettyJson("PUT request to {} entity \n{}", uri, payload);
374369

375370
return doRequest(requestBuilder, type);
@@ -471,7 +466,7 @@ private <T> T doRequest(RequestBuilder requestBuilder, TypeReference<T> type) th
471466
private void verifyResponse(int statusCode, HttpEntity httpEntity) throws IOException {
472467
if (statusCode >= 400) {
473468
ErrorMessage message;
474-
String stringResponse = EntityUtils.toString(httpEntity, "UTF-8");
469+
String stringResponse = EntityUtils.toString(httpEntity, Consts.UTF_8);
475470
try {
476471
message = jsonConverter.deserialize(stringResponse, of(ErrorMessage.class));
477472
} catch (CallfireClientException e) {

0 commit comments

Comments
 (0)