aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/Context.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/Context.java')
-rw-r--r--src/org/traccar/Context.java111
1 files changed, 65 insertions, 46 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 511ec980e..3681cc2cc 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -71,6 +71,8 @@ import org.traccar.geolocation.GeolocationProvider;
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;
@@ -323,6 +325,9 @@ public final class Context {
objectMapper = new ObjectMapper();
objectMapper.setConfig(
objectMapper.getSerializationConfig().without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS));
+ if (Context.getConfig().getBoolean("mapper.prettyPrintedJson")) {
+ objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
+ }
if (config.hasKey("database.url")) {
dataManager = new DataManager(config);
@@ -349,24 +354,7 @@ public final class Context {
}
if (config.getBoolean("geolocation.enable")) {
- String type = config.getString("geolocation.type", "mozilla");
- String url = config.getString("geolocation.url");
- String key = config.getString("geolocation.key");
-
- switch (type) {
- case "google":
- geolocationProvider = new GoogleGeolocationProvider(key);
- break;
- case "opencellid":
- geolocationProvider = new OpenCellIdGeolocationProvider(key);
- break;
- case "unwired":
- geolocationProvider = new UnwiredGeolocationProvider(url, key);
- break;
- default:
- geolocationProvider = new MozillaGeolocationProvider(key);
- break;
- }
+ initGeolocationModule();
}
if (config.getBoolean("web.enable")) {
@@ -380,39 +368,17 @@ public final class Context {
tripsConfig = initTripsConfig();
if (config.getBoolean("event.enable")) {
- geofenceManager = new GeofenceManager(dataManager);
- calendarManager = new CalendarManager(dataManager);
- notificationManager = new NotificationManager(dataManager);
- Properties velocityProperties = new Properties();
- velocityProperties.setProperty("file.resource.loader.path",
- Context.getConfig().getString("templates.rootPath", "templates") + "/");
- velocityProperties.setProperty("runtime.log.logsystem.class",
- "org.apache.velocity.runtime.log.NullLogChute");
-
- String address;
- try {
- address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress());
- } catch (UnknownHostException e) {
- address = "localhost";
- }
-
- String webUrl = URIUtil.newURI("http", address, config.getInteger("web.port", 8082), "", "");
- webUrl = Context.getConfig().getString("web.url", webUrl);
- velocityProperties.setProperty("web.url", webUrl);
-
- velocityEngine = new VelocityEngine();
- velocityEngine.init(velocityProperties);
-
- motionEventHandler = new MotionEventHandler(tripsConfig);
- overspeedEventHandler = new OverspeedEventHandler(
- Context.getConfig().getLong("event.overspeed.minimalDuration") * 1000,
- Context.getConfig().getBoolean("event.overspeed.notRepeat"));
+ initEventsModule();
}
serverManager = new ServerManager();
if (config.getBoolean("event.forward.enable")) {
- eventForwarder = new EventForwarder();
+ if (Context.getConfig().getBoolean("event.forward.payloadAsParamMode")) {
+ eventForwarder = new MultiPartEventForwarder();
+ } else {
+ eventForwarder = new JsonTypeEventForwarder();
+ }
}
attributesManager = new AttributesManager(dataManager);
@@ -429,6 +395,59 @@ public final class Context {
}
+ private static void initGeolocationModule() {
+
+ String type = config.getString("geolocation.type", "mozilla");
+ String url = config.getString("geolocation.url");
+ String key = config.getString("geolocation.key");
+
+ switch (type) {
+ case "google":
+ geolocationProvider = new GoogleGeolocationProvider(key);
+ break;
+ case "opencellid":
+ geolocationProvider = new OpenCellIdGeolocationProvider(key);
+ break;
+ case "unwired":
+ geolocationProvider = new UnwiredGeolocationProvider(url, key);
+ break;
+ default:
+ geolocationProvider = new MozillaGeolocationProvider(key);
+ break;
+ }
+ }
+
+ private static void initEventsModule() {
+
+ geofenceManager = new GeofenceManager(dataManager);
+ calendarManager = new CalendarManager(dataManager);
+ notificationManager = new NotificationManager(dataManager);
+ Properties velocityProperties = new Properties();
+ velocityProperties.setProperty("file.resource.loader.path",
+ Context.getConfig().getString("templates.rootPath", "templates") + "/");
+ velocityProperties.setProperty("runtime.log.logsystem.class",
+ "org.apache.velocity.runtime.log.NullLogChute");
+
+ String address;
+ try {
+ address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress());
+ } catch (UnknownHostException e) {
+ address = "localhost";
+ }
+
+ String webUrl = URIUtil.newURI("http", address, config.getInteger("web.port", 8082), "", "");
+ webUrl = Context.getConfig().getString("web.url", webUrl);
+ velocityProperties.setProperty("web.url", webUrl);
+
+ velocityEngine = new VelocityEngine();
+ velocityEngine.init(velocityProperties);
+
+ motionEventHandler = new MotionEventHandler(tripsConfig);
+ overspeedEventHandler = new OverspeedEventHandler(
+ Context.getConfig().getLong("event.overspeed.minimalDuration") * 1000,
+ Context.getConfig().getBoolean("event.overspeed.notRepeat"));
+ }
+
public static void init(IdentityManager testIdentityManager) {
config = new Config();
objectMapper = new ObjectMapper();