aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/BaseProtocolEncoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/BaseProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/BaseProtocolEncoder.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/BaseProtocolEncoder.java b/src/main/java/org/traccar/BaseProtocolEncoder.java
index b6df07b98..9c3934184 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.
@@ -21,7 +21,13 @@ import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.traccar.helper.NetworkUtil;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
+import org.traccar.model.Device;
+import org.traccar.session.cache.CacheManager;
+
+import javax.inject.Inject;
public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter {
@@ -31,22 +37,33 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter
private final Protocol protocol;
+ private CacheManager cacheManager;
+
public BaseProtocolEncoder(Protocol protocol) {
this.protocol = protocol;
}
+ public CacheManager getCacheManager() {
+ return cacheManager;
+ }
+
+ @Inject
+ public void setCacheManager(CacheManager cacheManager) {
+ this.cacheManager = cacheManager;
+ }
+
public String getProtocolName() {
return protocol != null ? protocol.getName() : PROTOCOL_UNKNOWN;
}
protected String getUniqueId(long deviceId) {
- return Context.getIdentityManager().getById(deviceId).getUniqueId();
+ return cacheManager.getObject(Device.class, deviceId).getUniqueId();
}
protected void initDevicePassword(Command command, String defaultPassword) {
- if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
- String password = Context.getIdentityManager()
- .getDevicePassword(command.getDeviceId(), getProtocolName(), defaultPassword);
+ if (!command.hasAttribute(Command.KEY_DEVICE_PASSWORD)) {
+ String password = AttributeUtil.getDevicePassword(
+ cacheManager, command.getDeviceId(), getProtocolName(), defaultPassword);
command.set(Command.KEY_DEVICE_PASSWORD, password);
}
}
@@ -62,7 +79,7 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter
Object encodedCommand = encodeCommand(ctx.channel(), command);
StringBuilder s = new StringBuilder();
- s.append("[").append(ctx.channel().id().asShortText()).append("] ");
+ s.append("[").append(NetworkUtil.session(ctx.channel())).append("] ");
s.append("id: ").append(getUniqueId(command.getDeviceId())).append(", ");
s.append("command type: ").append(command.getType()).append(" ");
if (encodedCommand != null) {