diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-02 14:17:51 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-02 14:17:51 +1200 |
commit | 5a9811c3771d92832c9bba718b5ec935844978e8 (patch) | |
tree | 6c2f5024fb0297c66d9eb184fab259e7c3017927 /src/org/traccar/Context.java | |
parent | bfc7cb8efcaa9f9ec7bf24fd528b370a10c4f0ac (diff) | |
download | trackermap-server-5a9811c3771d92832c9bba718b5ec935844978e8.tar.gz trackermap-server-5a9811c3771d92832c9bba718b5ec935844978e8.tar.bz2 trackermap-server-5a9811c3771d92832c9bba718b5ec935844978e8.zip |
Remove async HTTP client dependency
Diffstat (limited to 'src/org/traccar/Context.java')
-rw-r--r-- | src/org/traccar/Context.java | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index 23d0a983e..7224fd742 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -17,13 +17,14 @@ package org.traccar; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.ning.http.client.AsyncHttpClient; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Properties; -import com.ning.http.client.AsyncHttpClientConfigDefaults; +import com.fasterxml.jackson.datatype.jsr353.JSR353Module; +import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; import org.apache.velocity.app.VelocityEngine; import org.eclipse.jetty.util.URIUtil; import org.traccar.database.CalendarManager; @@ -76,11 +77,13 @@ import org.traccar.geolocation.MozillaGeolocationProvider; import org.traccar.geolocation.OpenCellIdGeolocationProvider; import org.traccar.notification.EventForwarder; import org.traccar.notification.JsonTypeEventForwarder; -import org.traccar.notification.MultiPartEventForwarder; import org.traccar.reports.model.TripsConfig; import org.traccar.smpp.SmppClient; import org.traccar.web.WebServer; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; + public final class Context { private static final String USER_AGENT = @@ -209,15 +212,10 @@ public final class Context { return velocityEngine; } - private static AsyncHttpClient asyncHttpClient; - - static { - System.setProperty(AsyncHttpClientConfigDefaults.ASYNC_CLIENT + "userAgent", USER_AGENT); - asyncHttpClient = new AsyncHttpClient(); - } + private static Client client = ClientBuilder.newClient(); - public static AsyncHttpClient getAsyncHttpClient() { - return asyncHttpClient; + public static Client getClient() { + return client; } private static EventForwarder eventForwarder; @@ -343,12 +341,18 @@ public final class Context { } objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JSR353Module()); objectMapper.setConfig( objectMapper.getSerializationConfig().without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)); if (Context.getConfig().getBoolean("mapper.prettyPrintedJson")) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } + JacksonJsonProvider jsonProvider = + new JacksonJaxbJsonProvider(objectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS); + client = ClientBuilder.newClient().register(jsonProvider); + + if (config.hasKey("database.url")) { dataManager = new DataManager(config); } @@ -392,11 +396,7 @@ public final class Context { serverManager = new ServerManager(); if (config.getBoolean("event.forward.enable")) { - if (Context.getConfig().getBoolean("event.forward.payloadAsParamMode")) { - eventForwarder = new MultiPartEventForwarder(); - } else { - eventForwarder = new JsonTypeEventForwarder(); - } + eventForwarder = new JsonTypeEventForwarder(); } attributesManager = new AttributesManager(dataManager); @@ -471,6 +471,10 @@ public final class Context { public static void init(IdentityManager testIdentityManager) { config = new Config(); objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JSR353Module()); + JacksonJsonProvider jsonProvider = + new JacksonJaxbJsonProvider(objectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS); + client = ClientBuilder.newClient().register(jsonProvider); identityManager = testIdentityManager; } |