diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/OsmAndProtocolDecoder.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index f46511b27..5d59c3b41 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -15,9 +15,11 @@ */ package org.traccar.protocol; +import org.eclipse.jetty.http.HttpHeader; import org.jboss.netty.channel.Channel; import org.jboss.netty.handler.codec.http.DefaultHttpResponse; 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(HttpHeader.CONTENT_LENGTH.asString(), 0); + channel.write(response); + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -64,8 +74,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { 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; } @@ -124,7 +133,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { } if (channel != null) { - channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)); + sendResponse(channel, HttpResponseStatus.OK); } return position; |