diff options
Diffstat (limited to 'src/org/traccar/Context.java')
-rw-r--r-- | src/org/traccar/Context.java | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index abf9f7a8a..80be1ddc6 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +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.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; @@ -35,6 +37,7 @@ import org.traccar.database.DeviceManager; import org.traccar.database.DriversManager; import org.traccar.database.IdentityManager; import org.traccar.database.LdapProvider; +import org.traccar.database.MaintenancesManager; import org.traccar.database.MediaManager; import org.traccar.database.NotificationManager; import org.traccar.database.PermissionsManager; @@ -48,6 +51,7 @@ import org.traccar.geocoder.AddressFormat; import org.traccar.geocoder.BingMapsGeocoder; import org.traccar.geocoder.FactualGeocoder; import org.traccar.geocoder.GeocodeFarmGeocoder; +import org.traccar.geocoder.GeocodeXyzGeocoder; import org.traccar.geocoder.GisgraphyGeocoder; import org.traccar.geocoder.GoogleGeocoder; import org.traccar.geocoder.MapQuestGeocoder; @@ -64,6 +68,7 @@ import org.traccar.model.Device; import org.traccar.model.Driver; import org.traccar.model.Geofence; import org.traccar.model.Group; +import org.traccar.model.Maintenance; import org.traccar.model.Notification; import org.traccar.model.User; import org.traccar.geolocation.GoogleGeolocationProvider; @@ -72,14 +77,19 @@ 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.notification.NotificatorManager; import org.traccar.reports.model.TripsConfig; import org.traccar.sms.SMSManager; 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 = + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"; + private Context() { } @@ -209,10 +219,10 @@ public final class Context { return velocityEngine; } - private static final AsyncHttpClient ASYNC_HTTP_CLIENT = new AsyncHttpClient(); + private static Client client = ClientBuilder.newClient(); - public static AsyncHttpClient getAsyncHttpClient() { - return ASYNC_HTTP_CLIENT; + public static Client getClient() { + return client; } private static EventForwarder eventForwarder; @@ -239,6 +249,12 @@ public final class Context { return commandsManager; } + private static MaintenancesManager maintenancesManager; + + public static MaintenancesManager getMaintenancesManager() { + return maintenancesManager; + } + private static StatisticsManager statisticsManager; public static StatisticsManager getStatisticsManager() { @@ -310,6 +326,8 @@ public final class Context { return new FactualGeocoder(url, key, cacheSize, addressFormat); case "geocodefarm": return new GeocodeFarmGeocoder(key, language, cacheSize, addressFormat); + case "geocodexyz": + return new GeocodeXyzGeocoder(key, cacheSize, addressFormat); default: return new GoogleGeocoder(key, language, cacheSize, addressFormat); } @@ -330,12 +348,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); } @@ -388,18 +412,14 @@ 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); driversManager = new DriversManager(dataManager); - commandsManager = new CommandsManager(dataManager); + commandsManager = new CommandsManager(dataManager, config.getBoolean("commands.queueing")); statisticsManager = new StatisticsManager(); @@ -431,6 +451,7 @@ public final class Context { geofenceManager = new GeofenceManager(dataManager); calendarManager = new CalendarManager(dataManager); + maintenancesManager = new MaintenancesManager(dataManager); notificationManager = new NotificationManager(dataManager); notificatorManager = new NotificatorManager(); Properties velocityProperties = new Properties(); @@ -456,12 +477,17 @@ public final class Context { motionEventHandler = new MotionEventHandler(tripsConfig); overspeedEventHandler = new OverspeedEventHandler( Context.getConfig().getLong("event.overspeed.minimalDuration") * 1000, - Context.getConfig().getBoolean("event.overspeed.notRepeat")); + Context.getConfig().getBoolean("event.overspeed.notRepeat"), + Context.getConfig().getBoolean("event.overspeed.preferLowest")); } 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; } @@ -482,6 +508,8 @@ public final class Context { return (BaseObjectManager<T>) driversManager; } else if (clazz.equals(Command.class)) { return (BaseObjectManager<T>) commandsManager; + } else if (clazz.equals(Maintenance.class)) { + return (BaseObjectManager<T>) maintenancesManager; } else if (clazz.equals(Notification.class)) { return (BaseObjectManager<T>) notificationManager; } |