From 6520470b767a0882277a7489b3870c676761cebf Mon Sep 17 00:00:00 2001 From: Valerii Vyshniak Date: Mon, 23 Jan 2017 00:58:55 +0100 Subject: 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. --- src/org/traccar/geolocation/UniversalGeolocationProvider.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/geolocation') 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())) { -- cgit v1.2.3