aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BaseHttpProtocolDecoder.java21
-rw-r--r--src/org/traccar/protocol/OsmAndProtocol.java13
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java23
3 files changed, 32 insertions, 25 deletions
diff --git a/src/org/traccar/BaseHttpProtocolDecoder.java b/src/org/traccar/BaseHttpProtocolDecoder.java
index dbc6b087b..57a68acac 100644
--- a/src/org/traccar/BaseHttpProtocolDecoder.java
+++ b/src/org/traccar/BaseHttpProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 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.
@@ -15,18 +15,25 @@
*/
package org.traccar;
-public abstract class BaseHttpProtocolDecoder /*extends BaseProtocolDecoder*/ { // TODO implement later
+import io.netty.channel.Channel;
+import io.netty.handler.codec.http.DefaultFullHttpResponse;
+import io.netty.handler.codec.http.HttpHeaderNames;
+import io.netty.handler.codec.http.HttpResponse;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.HttpVersion;
- /*public BaseHttpProtocolDecoder(Protocol protocol) {
+public abstract class BaseHttpProtocolDecoder extends BaseProtocolDecoder {
+
+ public BaseHttpProtocolDecoder(Protocol protocol) {
super(protocol);
}
public 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);
+ HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status);
+ response.headers().add(HttpHeaderNames.CONTENT_LENGTH, 0);
+ channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
- }*/
+ }
}
diff --git a/src/org/traccar/protocol/OsmAndProtocol.java b/src/org/traccar/protocol/OsmAndProtocol.java
index 785f4bd75..a199f067a 100644
--- a/src/org/traccar/protocol/OsmAndProtocol.java
+++ b/src/org/traccar/protocol/OsmAndProtocol.java
@@ -15,11 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
+import io.netty.handler.codec.http.HttpObjectAggregator;
+import io.netty.handler.codec.http.HttpRequestDecoder;
+import io.netty.handler.codec.http.HttpResponseEncoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -32,11 +32,12 @@ public class OsmAndProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("httpEncoder", new HttpResponseEncoder());
pipeline.addLast("httpDecoder", new HttpRequestDecoder());
+ pipeline.addLast("httpAggregator", new HttpObjectAggregator(16384));
pipeline.addLast("objectDecoder", new OsmAndProtocolDecoder(OsmAndProtocol.this));
}
});
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 03abdd588..c75e9519c 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 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.
@@ -15,10 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.QueryStringDecoder;
+import io.netty.channel.Channel;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.QueryStringDecoder;
import org.joda.time.format.ISODateTimeFormat;
import org.traccar.BaseHttpProtocolDecoder;
import org.traccar.DeviceSession;
@@ -42,15 +42,14 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder {
}
@Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- HttpRequest request = (HttpRequest) msg;
- QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
- Map<String, List<String>> params = decoder.getParameters();
+ FullHttpRequest request = (FullHttpRequest) msg;
+ QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
+ Map<String, List<String>> params = decoder.parameters();
if (params.isEmpty()) {
- decoder = new QueryStringDecoder(request.getContent().toString(StandardCharsets.US_ASCII), false);
- params = decoder.getParameters();
+ decoder = new QueryStringDecoder(request.content().toString(StandardCharsets.US_ASCII), false);
+ params = decoder.parameters();
}
Position position = new Position(getProtocolName());