aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-23 15:40:41 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-23 15:40:41 -0800
commita129cfd3159c02b4f3996dbdfb5299ac95a6720c (patch)
tree1d85533a859e444eff32d92730d0805f6aac08c5 /src
parentb7d48127e60bcaa5d01f45d8df5203f28f9a1667 (diff)
downloadtraccar-server-a129cfd3159c02b4f3996dbdfb5299ac95a6720c.tar.gz
traccar-server-a129cfd3159c02b4f3996dbdfb5299ac95a6720c.tar.bz2
traccar-server-a129cfd3159c02b4f3996dbdfb5299ac95a6720c.zip
Refactor remote address handler
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java10
-rw-r--r--src/org/traccar/MainModule.java10
-rw-r--r--src/org/traccar/config/Keys.java4
-rw-r--r--src/org/traccar/handler/ComputedAttributesHandler.java2
-rw-r--r--src/org/traccar/handler/CopyAttributesHandler.java2
-rw-r--r--src/org/traccar/handler/RemoteAddressHandler.java (renamed from src/org/traccar/RemoteAddressHandler.java)2
6 files changed, 20 insertions, 10 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index d32e1fc6c..d5a90390e 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -40,6 +40,7 @@ import org.traccar.handler.DistanceHandler;
import org.traccar.handler.FilterHandler;
import org.traccar.handler.NetworkMessageHandler;
import org.traccar.handler.OpenChannelHandler;
+import org.traccar.handler.RemoteAddressHandler;
import org.traccar.handler.StandardLoggingHandler;
import java.util.Map;
@@ -52,7 +53,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
private int timeout;
private EngineHoursHandler engineHoursHandler;
- private RemoteAddressHandler remoteAddressHandler;
private MotionHandler motionHandler;
private GeocoderHandler geocoderHandler;
private GeolocationHandler geolocationHandler;
@@ -78,10 +78,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
timeout = Context.getConfig().getInteger(Keys.SERVER_TIMEOUT);
}
- if (Context.getConfig().getBoolean("handler.remoteAddress.enable")) {
- remoteAddressHandler = new RemoteAddressHandler();
- }
-
if (Context.getGeocoder() != null && !Context.getConfig().getBoolean("geocoder.ignorePositions")) {
geocoderHandler = new GeocoderHandler(
Context.getGeocoder(),
@@ -105,7 +101,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
hemisphereHandler = new HemisphereHandler();
}
- if (Context.getConfig().getBoolean("handler.copyAttributes.enable")) {
+ if (Context.getConfig().getBoolean("processing.copyAttributes.enable")) {
copyAttributesHandler = new CopyAttributesHandler();
}
@@ -178,7 +174,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
geolocationHandler,
hemisphereHandler,
Main.getInjector().getInstance(DistanceHandler.class),
- remoteAddressHandler);
+ Main.getInjector().getInstance(RemoteAddressHandler.class));
addDynamicHandlers(pipeline);
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index 9b16185df..d9ff93b21 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -24,6 +24,7 @@ import org.traccar.config.Keys;
import org.traccar.database.IdentityManager;
import org.traccar.handler.DistanceHandler;
import org.traccar.handler.FilterHandler;
+import org.traccar.handler.RemoteAddressHandler;
import javax.ws.rs.client.Client;
@@ -66,6 +67,15 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
+ public static RemoteAddressHandler provideRemoteAddressHandler(Config config) {
+ if (config.getBoolean(Keys.PROCESSING_REMOTE_ADDRESS_ENABLE)) {
+ return new RemoteAddressHandler();
+ }
+ return null;
+ }
+
+ @Singleton
+ @Provides
public static WebDataHandler provideWebDataHandler(
Config config, IdentityManager identityManager, ObjectMapper objectMapper, Client client) {
if (config.getBoolean(Keys.FORWARD_ENABLE)) {
diff --git a/src/org/traccar/config/Keys.java b/src/org/traccar/config/Keys.java
index 6d4653a94..655a61c1d 100644
--- a/src/org/traccar/config/Keys.java
+++ b/src/org/traccar/config/Keys.java
@@ -143,6 +143,10 @@ public final class Keys {
"Distance in meters. Distances above this value gets handled like explained in 'coordinates.filter', but "
+ "only if Position is also marked as 'invalid'.");
+ public static final ConfigKey PROCESSING_REMOTE_ADDRESS_ENABLE = new ConfigKey(
+ "processing.remoteAddress.enable",
+ Boolean.class,
+ "Enable to save device IP addresses information. Disabled by default.");
private Keys() {
}
diff --git a/src/org/traccar/handler/ComputedAttributesHandler.java b/src/org/traccar/handler/ComputedAttributesHandler.java
index 4b5b8c20d..5ceadafdd 100644
--- a/src/org/traccar/handler/ComputedAttributesHandler.java
+++ b/src/org/traccar/handler/ComputedAttributesHandler.java
@@ -51,7 +51,7 @@ public class ComputedAttributesHandler extends BaseDataHandler {
engine.setStrict(true);
engine.setFunctions(Collections.singletonMap("math", (Object) Math.class));
if (Context.getConfig() != null) {
- mapDeviceAttributes = Context.getConfig().getBoolean("handler.computedAttributes.deviceAttributes");
+ mapDeviceAttributes = Context.getConfig().getBoolean("processing.computedAttributes.deviceAttributes");
}
}
diff --git a/src/org/traccar/handler/CopyAttributesHandler.java b/src/org/traccar/handler/CopyAttributesHandler.java
index ce37e09cc..73642d81b 100644
--- a/src/org/traccar/handler/CopyAttributesHandler.java
+++ b/src/org/traccar/handler/CopyAttributesHandler.java
@@ -34,7 +34,7 @@ public class CopyAttributesHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
String attributesString = Context.getDeviceManager().lookupAttributeString(
- position.getDeviceId(), "handler.copyAttributes", "", true);
+ position.getDeviceId(), "processing.copyAttributes", "", true);
Position last = getLastPosition(position.getDeviceId());
if (attributesString.isEmpty()) {
attributesString = Position.KEY_DRIVER_UNIQUE_ID;
diff --git a/src/org/traccar/RemoteAddressHandler.java b/src/org/traccar/handler/RemoteAddressHandler.java
index aabc5715e..c09b8c39a 100644
--- a/src/org/traccar/RemoteAddressHandler.java
+++ b/src/org/traccar/handler/RemoteAddressHandler.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.traccar;
+package org.traccar.handler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;