diff options
Diffstat (limited to 'src/org/traccar/WebDataHandler.java')
-rw-r--r-- | src/org/traccar/WebDataHandler.java | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java index cdd9d0c11..763493437 100644 --- a/src/org/traccar/WebDataHandler.java +++ b/src/org/traccar/WebDataHandler.java @@ -16,12 +16,12 @@ package org.traccar; import com.fasterxml.jackson.core.JsonProcessingException; -import com.ning.http.client.AsyncHttpClient; import org.traccar.helper.Checksum; import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Position; +import javax.ws.rs.client.Entity; import java.util.HashMap; import java.util.Map; import java.io.UnsupportedEncodingException; @@ -98,6 +98,7 @@ public class WebDataHandler extends BaseDataHandler { .replace("{altitude}", String.valueOf(position.getAltitude())) .replace("{speed}", String.valueOf(position.getSpeed())) .replace("{course}", String.valueOf(position.getCourse())) + .replace("{accuracy}", String.valueOf(position.getAccuracy())) .replace("{statusCode}", calculateStatus(position)); if (position.getAddress() != null) { @@ -129,21 +130,14 @@ public class WebDataHandler extends BaseDataHandler { @Override protected Position handlePosition(Position position) { if (json) { - AsyncHttpClient.BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url); - requestBuilder.setBodyEncoding(StandardCharsets.UTF_8.name()); - - requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8"); - - requestBuilder.setBody(prepareJsonPayload(position)); - requestBuilder.execute(); - + Context.getClient().target(url).request().async().post(Entity.json(prepareJsonPayload(position))); } else { - Context.getAsyncHttpClient().prepareGet(formatRequest(position)).execute(); + Context.getClient().target(formatRequest(position)).request().async().get(); } return position; } - protected String prepareJsonPayload(Position position) { + protected Map<String, Object> prepareJsonPayload(Position position) { Map<String, Object> data = new HashMap<>(); Device device = Context.getIdentityManager().getById(position.getDeviceId()); @@ -154,11 +148,7 @@ public class WebDataHandler extends BaseDataHandler { data.put(KEY_DEVICE, device); } - try { - return Context.getObjectMapper().writeValueAsString(data); - } catch (JsonProcessingException e) { - Log.warning(e); - return null; - } + return data; } + } |