diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-11-11 20:23:08 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2021-11-11 20:23:08 -0800 |
commit | 965ef9eb530963e71ce33c2a06af389c78192b51 (patch) | |
tree | e8ad77c995524d71289d7667f32ab5bb8efc03e0 | |
parent | f78da0d7ead0e445f129eac486cc468bedff7c73 (diff) | |
download | trackermap-server-965ef9eb530963e71ce33c2a06af389c78192b51.tar.gz trackermap-server-965ef9eb530963e71ce33c2a06af389c78192b51.tar.bz2 trackermap-server-965ef9eb530963e71ce33c2a06af389c78192b51.zip |
Handle new lines
3 files changed, 7 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/MobilogixProtocol.java b/src/main/java/org/traccar/protocol/MobilogixProtocol.java index ebf2c9c7f..28380a2af 100644 --- a/src/main/java/org/traccar/protocol/MobilogixProtocol.java +++ b/src/main/java/org/traccar/protocol/MobilogixProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2020 - 2021 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. @@ -28,7 +28,7 @@ public class MobilogixProtocol extends BaseProtocol { addServer(new TrackerServer(false, getName()) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline) { - pipeline.addLast(new CharacterDelimiterFrameDecoder(1024, "]\r\n", "]")); + pipeline.addLast(new CharacterDelimiterFrameDecoder(1024, ']')); pipeline.addLast(new StringEncoder()); pipeline.addLast(new StringDecoder()); pipeline.addLast(new MobilogixProtocolDecoder(MobilogixProtocol.this)); diff --git a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java index 7947d0c26..f3b70e40c 100644 --- a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2020 - 2021 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. @@ -83,7 +83,7 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = (String) msg; + String sentence = ((String) msg).trim(); String type = sentence.substring(21, sentence.indexOf(',', 21)); if (channel != null) { diff --git a/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java index aca6b9f29..ddfa6ad8b 100644 --- a/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java @@ -14,6 +14,9 @@ public class MobilogixProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, text( "[2021-08-20 19:27:14,T14,1,V1.3.5,201909000982,53,12.18")); + verifyAttributes(decoder, text( + "\r\n[2021-08-20 19:27:14,T14,1,V1.3.5,201909000982,53,12.18")); + verifyNull(decoder, text( "[2020-12-01 14:00:22,T1,1,V1.1.1,201951132031,,,12345678,724108005415815,359366080211420")); |