aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/Context.java2
-rw-r--r--src/main/java/org/traccar/MainEventHandler.java2
-rw-r--r--src/main/java/org/traccar/api/CorsResponseFilter.java3
-rw-r--r--src/main/java/org/traccar/config/Keys.java38
-rw-r--r--src/main/java/org/traccar/protocol/EsealProtocolDecoder.java7
-rw-r--r--src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java5
-rw-r--r--src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java5
-rw-r--r--src/main/java/org/traccar/web/WebServer.java4
8 files changed, 54 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index 488dd9a15..3ba8843f0 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -295,7 +295,7 @@ public final class Context {
mailManager = new MailManager();
- mediaManager = new MediaManager(config.getString("media.path"));
+ mediaManager = new MediaManager(config.getString(Keys.MEDIA_PATH));
if (dataManager != null) {
usersManager = new UsersManager(dataManager);
diff --git a/src/main/java/org/traccar/MainEventHandler.java b/src/main/java/org/traccar/MainEventHandler.java
index df17dce0b..4889f6a2e 100644
--- a/src/main/java/org/traccar/MainEventHandler.java
+++ b/src/main/java/org/traccar/MainEventHandler.java
@@ -42,7 +42,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter {
private final Set<String> logAttributes = new LinkedHashSet<>();
public MainEventHandler() {
- String connectionlessProtocolList = Context.getConfig().getString("status.ignoreOffline");
+ String connectionlessProtocolList = Context.getConfig().getString(Keys.STATUS_IGNORE_OFFLINE);
if (connectionlessProtocolList != null) {
connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split("[, ]")));
}
diff --git a/src/main/java/org/traccar/api/CorsResponseFilter.java b/src/main/java/org/traccar/api/CorsResponseFilter.java
index 227f80609..91aea5718 100644
--- a/src/main/java/org/traccar/api/CorsResponseFilter.java
+++ b/src/main/java/org/traccar/api/CorsResponseFilter.java
@@ -17,6 +17,7 @@ package org.traccar.api;
import io.netty.handler.codec.http.HttpHeaderNames;
import org.traccar.Context;
+import org.traccar.config.Keys;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
@@ -45,7 +46,7 @@ public class CorsResponseFilter implements ContainerResponseFilter {
if (!response.getHeaders().containsKey(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString())) {
String origin = request.getHeaderString(HttpHeaderNames.ORIGIN.toString());
- String allowed = Context.getConfig().getString("web.origin");
+ String allowed = Context.getConfig().getString(Keys.WEB_ORIGIN);
if (origin == null) {
response.getHeaders().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), ORIGIN_ALL);
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 598cac66f..6b779baea 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -131,6 +131,13 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
+ * Protocol configuration. Required for some devices for decoding incoming data.
+ */
+ public static final ConfigSuffix<String> PROTOCOL_CONFIG = new ConfigSuffix<>(
+ ".config",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
* Alarm mapping for Atrack protocol.
*/
public static final ConfigSuffix<String> PROTOCOL_ALARM_MAP = new ConfigSuffix<>(
@@ -454,6 +461,22 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
+ * List of protocol names to ignore offline status. Can be useful to not trigger status change when devices are
+ * configured to disconnect after reporting a batch of data.
+ */
+ public static final ConfigKey<String> STATUS_IGNORE_OFFLINE = new ConfigKey<>(
+ "status.ignoreOffline",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Path to the media folder. Server stores audio, video and photo files in that folder. Sub-folders will be
+ * automatically created for each device by unique id.
+ */
+ public static final ConfigKey<String> MEDIA_PATH = new ConfigKey<>(
+ "media.path",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
* Optional parameter to specify network interface for web interface to bind to. By default server will bind to all
* available interfaces.
*/
@@ -500,6 +523,21 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
+ * Cross-origin resource sharing origin header value.
+ */
+ public static final ConfigKey<String> WEB_ORIGIN = new ConfigKey<>(
+ "web.origin",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Cache control header value. By default resources are cached for one hour.
+ */
+ public static final ConfigKey<String> WEB_CACHE_CONTROL = new ConfigKey<>(
+ "web.cacheControl",
+ Collections.singletonList(KeyType.GLOBAL),
+ "max-age=3600,public");
+
+ /**
* URL to forward positions. Data is passed through URL parameters. For example, {uniqueId} for device identifier,
* {latitude} and {longitude} for coordinates.
*/
diff --git a/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java b/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java
index 7a1fd7022..cc7f6e935 100644
--- a/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2020 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.
@@ -21,6 +21,7 @@ import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
+import org.traccar.config.Keys;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
@@ -31,11 +32,11 @@ import java.util.regex.Pattern;
public class EsealProtocolDecoder extends BaseProtocolDecoder {
- private String config;
+ private final String config;
public EsealProtocolDecoder(Protocol protocol) {
super(protocol);
- config = Context.getConfig().getString(getProtocolName() + ".config");
+ config = Context.getConfig().getString(Keys.PROTOCOL_CONFIG.withPrefix(getProtocolName()));
}
private static final Pattern PATTERN = new PatternBuilder()
diff --git a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
index 4d0cc314b..630fe5aed 100644
--- a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2020 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.
@@ -22,6 +22,7 @@ import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
+import org.traccar.config.Keys;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -39,7 +40,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
public XirgoProtocolDecoder(Protocol protocol) {
super(protocol);
- form = Context.getConfig().getString(getProtocolName() + ".form");
+ form = Context.getConfig().getString(Keys.PROTOCOL_FORM.withPrefix(getProtocolName()));
}
public void setForm(String form) {
diff --git a/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
index 31a1bbb11..85e8e140f 100644
--- a/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2020 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.
@@ -21,6 +21,7 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
+import org.traccar.config.Keys;
import org.traccar.helper.DataConverter;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -38,7 +39,7 @@ public class Xt2400ProtocolDecoder extends BaseProtocolDecoder {
public Xt2400ProtocolDecoder(Protocol protocol) {
super(protocol);
- String config = Context.getConfig().getString(getProtocolName() + ".config");
+ String config = Context.getConfig().getString(Keys.PROTOCOL_CONFIG.withPrefix(getProtocolName()));
if (config != null) {
setConfig(config);
}
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java
index ba4dbff3c..92e0ca958 100644
--- a/src/main/java/org/traccar/web/WebServer.java
+++ b/src/main/java/org/traccar/web/WebServer.java
@@ -138,7 +138,7 @@ public class WebServer {
if (config.getBoolean(Keys.WEB_DEBUG)) {
servletHandler.setWelcomeFiles(new String[] {"debug.html", "index.html"});
} else {
- String cache = config.getString("web.cacheControl");
+ String cache = config.getString(Keys.WEB_CACHE_CONTROL);
if (cache != null && !cache.isEmpty()) {
servletHolder.setInitParameter("cacheControl", cache);
}
@@ -153,7 +153,7 @@ public class WebServer {
if (config.hasKey("media.path")) {
ServletHolder servletHolder = new ServletHolder(DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", new File(config.getString("media.path")).getAbsolutePath());
- servletHolder.setInitParameter("dirAllowed", config.getString("media.dirAllowed", "false"));
+ servletHolder.setInitParameter("dirAllowed", "false");
servletHolder.setInitParameter("pathInfoOnly", "true");
servletHandler.addServlet(servletHolder, "/api/media/*");
servletHandler.addFilter(MediaFilter.class, "/api/media/*", EnumSet.allOf(DispatcherType.class));