diff options
-rw-r--r-- | src/org/traccar/protocol/OsmAndProtocolDecoder.java | 7 | ||||
-rwxr-xr-x | tools/test-generator.py | 13 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index da502ca65..f46511b27 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -48,8 +48,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); Map<String, List<String>> params = decoder.getParameters(); if (params.isEmpty()) { - decoder = new QueryStringDecoder( - request.getContent().toString(StandardCharsets.US_ASCII), false); + decoder = new QueryStringDecoder(request.getContent().toString(StandardCharsets.US_ASCII), false); params = decoder.getParameters(); } @@ -64,6 +63,10 @@ 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)); + } return null; } position.setDeviceId(deviceSession.getDeviceId()); diff --git a/tools/test-generator.py b/tools/test-generator.py index 681d1755d..8d7377c2c 100755 --- a/tools/test-generator.py +++ b/tools/test-generator.py @@ -3,11 +3,11 @@ import sys import math import urllib -import urllib2 +import httplib import time id = '123456789012345' -server = 'http://localhost:5055' +server = 'localhost:5055' period = 1 step = 0.001 @@ -32,9 +32,10 @@ for i in range(0, len(waypoints)): lon = lon1 + (lon2 - lon1) * j / count points.append((lat, lon)) -def send(lat, lon, course): +def send(conn, lat, lon, course): params = (('id', id), ('timestamp', int(time.time())), ('lat', lat), ('lon', lon), ('bearing', course)) - urllib2.urlopen(server + '?' + urllib.urlencode(params)).read() + conn.request('GET', '?' + urllib.urlencode(params)) + conn.getresponse() def course(lat1, lon1, lat2, lon2): lat1 = lat1 * math.pi / 180 @@ -47,9 +48,11 @@ def course(lat1, lon1, lat2, lon2): index = 0 +conn = httplib.HTTPConnection(server) + while True: (lat1, lon1) = points[index % len(points)] (lat2, lon2) = points[(index + 1) % len(points)] - send(lat1, lon1, course(lat1, lon1, lat2, lon2)) + send(conn, lat1, lon1, course(lat1, lon1, lat2, lon2)) time.sleep(period) index += 1 |