aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/OsmAndProtocolDecoder.java
diff options
context:
space:
mode:
authorninioe <ninioe@gmail.com>2016-08-01 16:12:47 +0300
committerninioe <ninioe@gmail.com>2016-08-01 16:12:47 +0300
commit94781fa3ba35e494e309aee19a5e15c14d3193c1 (patch)
treea1e4a90e9a2fce3db8bc51981aeb8a23cced5e6d /src/org/traccar/protocol/OsmAndProtocolDecoder.java
parentb4841fa0a6293c0b895cf6bb65c6c2d871c78397 (diff)
parente177e7d083a4dd3f64172802661bf658d26d1163 (diff)
downloadtrackermap-server-94781fa3ba35e494e309aee19a5e15c14d3193c1.tar.gz
trackermap-server-94781fa3ba35e494e309aee19a5e15c14d3193c1.tar.bz2
trackermap-server-94781fa3ba35e494e309aee19a5e15c14d3193c1.zip
Merge remote-tracking branch 'refs/remotes/tananaev/master'
Diffstat (limited to 'src/org/traccar/protocol/OsmAndProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index f46511b27..c5884a4d0 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -17,7 +17,9 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpRequest;
+import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
@@ -40,6 +42,14 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ private void sendResponse(Channel channel, HttpResponseStatus status) {
+ if (channel != null) {
+ HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
+ response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
+ channel.write(response);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -63,10 +73,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
case "deviceid":
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession == null) {
- if (channel != null) {
- channel.write(
- new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST));
- }
+ sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
@@ -123,11 +130,14 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
position.setTime(new Date());
}
- if (channel != null) {
- channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession != null) {
+ sendResponse(channel, HttpResponseStatus.OK);
+ return position;
+ } else {
+ sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
+ return null;
}
-
- return position;
}
}