aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/geolocation
diff options
context:
space:
mode:
authorValerii Vyshniak <valeravi@vi-soft.com.ua>2017-01-23 00:58:55 +0100
committerValerii Vyshniak <valeravi@vi-soft.com.ua>2017-01-28 22:19:54 +0100
commit6520470b767a0882277a7489b3870c676761cebf (patch)
treebeae5da8d09f7580f4dbaf04f969a4a4dcb97052 /src/org/traccar/geolocation
parent26175114ee573caa1774a04157253789d4a93998 (diff)
downloadtrackermap-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/org/traccar/geolocation')
-rw-r--r--src/org/traccar/geolocation/UniversalGeolocationProvider.java7
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())) {