Skip to content

Commit

Permalink
set json content encoding to utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-mhl committed Nov 14, 2017
1 parent 50d45d6 commit 5c27cc7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Callfire API client Changelog
=============================

Version 1.7.17 - Nov 14 2017
- set json content encoding to UTF-8

Version 1.7.16 - Jun 15 2017
- added fromNumber to Recipient object for sending calls/texts
- added strictValidation flag for adding contacts to broadcast
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group = com.callfire
baseName = callfire-api-client
version = 1.7.16
version = 1.7.17
15 changes: 5 additions & 10 deletions src/main/java/com/callfire/api/client/RestApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.*;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.EntityBuilder;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.BasicCredentialsProvider;
Expand Down Expand Up @@ -311,8 +308,7 @@ public <T> T post(String path, TypeReference<T> type, Object payload, List<NameV
.addParameters(queryParams.toArray(new NameValuePair[queryParams.size()]));
if (payload != null) {
validatePayload(payload);
String stringPayload = jsonConverter.serialize(payload);
requestBuilder.setEntity(EntityBuilder.create().setText(stringPayload).build());
requestBuilder.setEntity(new StringEntity(jsonConverter.serialize(payload), Consts.UTF_8));
logDebugPrettyJson("POST request to {} entity \n{}", uri, payload);
} else {
LOGGER.debug("POST request to {}", uri);
Expand Down Expand Up @@ -365,11 +361,10 @@ public <T> T put(String path, TypeReference<T> type, Object payload, List<NameVa
try {
String uri = getApiBasePath() + path;
validatePayload(payload);
HttpEntity httpEntity = EntityBuilder.create().setText(jsonConverter.serialize(payload)).build();
RequestBuilder requestBuilder = RequestBuilder.put(uri)
.setHeader(CONTENT_TYPE, APPLICATION_JSON.getMimeType())
.addParameters(queryParams.toArray(new NameValuePair[queryParams.size()]))
.setEntity(httpEntity);
.setEntity(new StringEntity(jsonConverter.serialize(payload), Consts.UTF_8));
logDebugPrettyJson("PUT request to {} entity \n{}", uri, payload);

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

0 comments on commit 5c27cc7

Please sign in to comment.