aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/BaseProtocolEncoder.java
diff options
context:
space:
mode:
authorcasswarry0 <casswarry0@gmail.com>2023-01-17 17:14:53 -0700
committercasswarry0 <casswarry0@gmail.com>2023-01-17 17:14:53 -0700
commit7338b8730949ed027b3f8b31d7dca20687ebbb8b (patch)
treec2d171e6121818ab511460a786f69aab97a2a628 /src/main/java/org/traccar/BaseProtocolEncoder.java
parentcdecd3fa4427a382c0b09f8ad9d69ec14388960a (diff)
parent85501f9cf4918d5eee345f83aed7a31eecb26b8d (diff)
downloadtrackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.tar.gz
trackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.tar.bz2
trackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.zip
Merge branch 'master' into develop
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) {