aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/HoopoProtocol.java11
-rw-r--r--src/main/java/org/traccar/protocol/HoopoProtocolDecoder.java14
-rw-r--r--src/main/java/org/traccar/protocol/JsonFrameDecoder.java (renamed from src/main/java/org/traccar/protocol/StbFrameDecoder.java)2
-rw-r--r--src/main/java/org/traccar/protocol/StbProtocol.java2
-rw-r--r--src/test/java/org/traccar/protocol/HoopoProtocolDecoderTest.java5
-rw-r--r--src/test/java/org/traccar/protocol/JsonFrameDecoderTest.java (renamed from src/test/java/org/traccar/protocol/StbFrameDecoderTest.java)4
6 files changed, 14 insertions, 24 deletions
diff --git a/src/main/java/org/traccar/protocol/HoopoProtocol.java b/src/main/java/org/traccar/protocol/HoopoProtocol.java
index d47327ad8..387b967d3 100644
--- a/src/main/java/org/traccar/protocol/HoopoProtocol.java
+++ b/src/main/java/org/traccar/protocol/HoopoProtocol.java
@@ -15,9 +15,8 @@
*/
package org.traccar.protocol;
-import io.netty.handler.codec.http.HttpObjectAggregator;
-import io.netty.handler.codec.http.HttpRequestDecoder;
-import io.netty.handler.codec.http.HttpResponseEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
@@ -28,9 +27,9 @@ public class HoopoProtocol extends BaseProtocol {
addServer(new TrackerServer(false, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
- pipeline.addLast(new HttpResponseEncoder());
- pipeline.addLast(new HttpRequestDecoder());
- pipeline.addLast(new HttpObjectAggregator(65535));
+ pipeline.addLast(new JsonFrameDecoder());
+ pipeline.addLast(new StringEncoder());
+ pipeline.addLast(new StringDecoder());
pipeline.addLast(new HoopoProtocolDecoder(HoopoProtocol.this));
}
});
diff --git a/src/main/java/org/traccar/protocol/HoopoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HoopoProtocolDecoder.java
index 4f6b3d546..5db7f0bc0 100644
--- a/src/main/java/org/traccar/protocol/HoopoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HoopoProtocolDecoder.java
@@ -16,9 +16,7 @@
package org.traccar.protocol;
import io.netty.channel.Channel;
-import io.netty.handler.codec.http.FullHttpRequest;
-import io.netty.handler.codec.http.HttpResponseStatus;
-import org.traccar.BaseHttpProtocolDecoder;
+import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.model.Position;
@@ -27,11 +25,10 @@ import javax.json.Json;
import javax.json.JsonObject;
import java.io.StringReader;
import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.Date;
-public class HoopoProtocolDecoder extends BaseHttpProtocolDecoder {
+public class HoopoProtocolDecoder extends BaseProtocolDecoder {
public HoopoProtocolDecoder(Protocol protocol) {
super(protocol);
@@ -41,13 +38,10 @@ public class HoopoProtocolDecoder extends BaseHttpProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- FullHttpRequest request = (FullHttpRequest) msg;
- String content = request.content().toString(StandardCharsets.UTF_8);
- JsonObject json = Json.createReader(new StringReader(content)).readObject();
+ JsonObject json = Json.createReader(new StringReader((String) msg)).readObject();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, json.getString("deviceId"));
if (deviceSession == null) {
- sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
return null;
}
@@ -72,8 +66,6 @@ public class HoopoProtocolDecoder extends BaseHttpProtocolDecoder {
}
- sendResponse(channel, HttpResponseStatus.OK);
-
return null;
}
diff --git a/src/main/java/org/traccar/protocol/StbFrameDecoder.java b/src/main/java/org/traccar/protocol/JsonFrameDecoder.java
index 6a4157f17..b2d7fbd53 100644
--- a/src/main/java/org/traccar/protocol/StbFrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/JsonFrameDecoder.java
@@ -20,7 +20,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.traccar.BaseFrameDecoder;
-public class StbFrameDecoder extends BaseFrameDecoder {
+public class JsonFrameDecoder extends BaseFrameDecoder {
@Override
protected Object decode(
diff --git a/src/main/java/org/traccar/protocol/StbProtocol.java b/src/main/java/org/traccar/protocol/StbProtocol.java
index ca95787d0..002ed86c7 100644
--- a/src/main/java/org/traccar/protocol/StbProtocol.java
+++ b/src/main/java/org/traccar/protocol/StbProtocol.java
@@ -27,7 +27,7 @@ public class StbProtocol extends BaseProtocol {
addServer(new TrackerServer(false, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
- pipeline.addLast(new StbFrameDecoder());
+ pipeline.addLast(new JsonFrameDecoder());
pipeline.addLast(new StringEncoder());
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StbProtocolDecoder(StbProtocol.this));
diff --git a/src/test/java/org/traccar/protocol/HoopoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/HoopoProtocolDecoderTest.java
index 37f838dd4..35d0f1423 100644
--- a/src/test/java/org/traccar/protocol/HoopoProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/HoopoProtocolDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import io.netty.handler.codec.http.HttpMethod;
import org.junit.Test;
import org.traccar.ProtocolTest;
@@ -11,8 +10,8 @@ public class HoopoProtocolDecoderTest extends ProtocolTest {
var decoder = new HoopoProtocolDecoder(null);
- verifyPosition(decoder, request(HttpMethod.POST, "/",
- buffer("{ \"deviceId\": \"BCCD0654\", \"assetName\": \"BCCD0654\", \"assetType\": \"???? ?????? - ??? 8\", \"eventData\": { \"latitude\": 31.97498, \"longitude\": 34.80802, \"locationName\": \"\", \"accuracyLevel\": \"High\", \"eventType\": \"Arrival\", \"batteryLevel\": 100, \"receiveTime\": \"2021-09-20T18:52:32Z\" }, \"eventTime\": \"2021-09-20T08:52:02Z\", \"serverReportTime\": \"0001-01-01T00:00:00Z\" }")));
+ verifyPosition(decoder, text(
+ "{ \"deviceId\": \"BCCD0654\", \"assetName\": \"BCCD0654\", \"assetType\": \"???? ?????? - ??? 8\", \"eventData\": { \"latitude\": 31.97498, \"longitude\": 34.80802, \"locationName\": \"\", \"accuracyLevel\": \"High\", \"eventType\": \"Arrival\", \"batteryLevel\": 100, \"receiveTime\": \"2021-09-20T18:52:32Z\" }, \"eventTime\": \"2021-09-20T08:52:02Z\", \"serverReportTime\": \"0001-01-01T00:00:00Z\" }"));
}
diff --git a/src/test/java/org/traccar/protocol/StbFrameDecoderTest.java b/src/test/java/org/traccar/protocol/JsonFrameDecoderTest.java
index 45d998fb1..42777e419 100644
--- a/src/test/java/org/traccar/protocol/StbFrameDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/JsonFrameDecoderTest.java
@@ -3,12 +3,12 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
-public class StbFrameDecoderTest extends ProtocolTest {
+public class JsonFrameDecoderTest extends ProtocolTest {
@Test
public void testDecode() throws Exception {
- var decoder = new StbFrameDecoder();
+ var decoder = new JsonFrameDecoder();
verifyFrame(
binary("7b226465764964223a2243485a4430384b504430323130343235303436222c2264657654797065223a322c226861726456657273696f6e223a224844545456413139222c226d736754797065223a3131302c2270726f746f636f6c56657273696f6e223a225631222c22736f667456657273696f6e223a22332e312e38222c22737769746368436162537461747573223a2231222c2274786e4e6f223a2231363235323132373431353337227d"),