aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/BaseProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-30 14:48:42 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-30 14:48:42 -0700
commit0202dbf7258df8cbe8168ddc985e774b1cadf964 (patch)
tree4828e614e29715e6bdfd10c5db86b52e43229ab3 /src/main/java/org/traccar/BaseProtocolEncoder.java
parent014cf82a9e63a36e944e293932f9edf27e452919 (diff)
downloadtrackermap-server-0202dbf7258df8cbe8168ddc985e774b1cadf964.tar.gz
trackermap-server-0202dbf7258df8cbe8168ddc985e774b1cadf964.tar.bz2
trackermap-server-0202dbf7258df8cbe8168ddc985e774b1cadf964.zip
Decouple more tests from context
Diffstat (limited to 'src/main/java/org/traccar/BaseProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/BaseProtocolEncoder.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/BaseProtocolEncoder.java b/src/main/java/org/traccar/BaseProtocolEncoder.java
index 71fa61e4e..10b780fc8 100644
--- a/src/main/java/org/traccar/BaseProtocolEncoder.java
+++ b/src/main/java/org/traccar/BaseProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 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.
@@ -15,12 +15,14 @@
*/
package org.traccar;
+import com.google.inject.Inject;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.traccar.database.IdentityManager;
import org.traccar.helper.NetworkUtil;
import org.traccar.model.Command;
@@ -32,21 +34,32 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter
private final Protocol protocol;
+ private IdentityManager identityManager;
+
public BaseProtocolEncoder(Protocol protocol) {
this.protocol = protocol;
}
+ public IdentityManager getIdentityManager() {
+ return identityManager;
+ }
+
+ @Inject
+ public void setIdentityManager(IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ }
+
public String getProtocolName() {
return protocol != null ? protocol.getName() : PROTOCOL_UNKNOWN;
}
protected String getUniqueId(long deviceId) {
- return Context.getIdentityManager().getById(deviceId).getUniqueId();
+ return identityManager.getById(deviceId).getUniqueId();
}
protected void initDevicePassword(Command command, String defaultPassword) {
if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
- String password = Context.getIdentityManager()
+ String password = identityManager
.getDevicePassword(command.getDeviceId(), getProtocolName(), defaultPassword);
command.set(Command.KEY_DEVICE_PASSWORD, password);
}