diff options
author | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-01-23 00:58:55 +0100 |
---|---|---|
committer | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-01-28 22:19:54 +0100 |
commit | 6520470b767a0882277a7489b3870c676761cebf (patch) | |
tree | beae5da8d09f7580f4dbaf04f969a4a4dcb97052 /src | |
parent | 26175114ee573caa1774a04157253789d4a93998 (diff) | |
download | trackermap-server-6520470b767a0882277a7489b3870c676761cebf.tar.gz trackermap-server-6520470b767a0882277a7489b3870c676761cebf.tar.bz2 trackermap-server-6520470b767a0882277a7489b3870c676761cebf.zip |
Set Content Type in http header of geolocation request
Google geolocation API does not work correctly if
"Content-Type:application/json" is not present in http header.
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/geolocation/UniversalGeolocationProvider.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/org/traccar/geolocation/UniversalGeolocationProvider.java b/src/org/traccar/geolocation/UniversalGeolocationProvider.java index 48152f7df..6416b2633 100644 --- a/src/org/traccar/geolocation/UniversalGeolocationProvider.java +++ b/src/org/traccar/geolocation/UniversalGeolocationProvider.java @@ -24,6 +24,8 @@ import org.traccar.model.Network; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonReader; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; public class UniversalGeolocationProvider implements GeolocationProvider { @@ -37,7 +39,10 @@ public class UniversalGeolocationProvider implements GeolocationProvider { public void getLocation(Network network, final LocationProviderCallback callback) { try { String request = Context.getObjectMapper().writeValueAsString(network); - Context.getAsyncHttpClient().preparePost(url).setBody(request).execute(new AsyncCompletionHandler() { + Context.getAsyncHttpClient().preparePost(url) + .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(request.length())) + .setBody(request).execute(new AsyncCompletionHandler() { @Override public Object onCompleted(Response response) throws Exception { try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) { |