aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml3
-rw-r--r--pom.xml5
-rw-r--r--src/org/traccar/BasePipelineFactory.java8
-rw-r--r--src/org/traccar/Context.java12
-rw-r--r--src/org/traccar/DefaultDataHandler.java37
-rw-r--r--src/org/traccar/MainEventHandler.java13
-rw-r--r--src/org/traccar/WebDataHandler.java44
7 files changed, 110 insertions, 12 deletions
diff --git a/debug.xml b/debug.xml
index 9ffc5b1bd..8e3e46f1d 100644
--- a/debug.xml
+++ b/debug.xml
@@ -25,6 +25,9 @@
<entry key='filter.zero'>true</entry>
<entry key='filter.duplicate'>true</entry>
<entry key='filter.distance'>50</entry>-->
+
+ <!--<entry key='forward.enable'>true</entry>
+ <entry key='forward.url'>http://localhost:5055?id={deviceId}&amp;timestamp={fixTime}&amp;lat={latitude}&amp;lon={longitude}</entry>-->
<entry key='logger.enable'>true</entry>
<entry key='logger.level'>all</entry>
diff --git a/pom.xml b/pom.xml
index 7547c2fc1..5ecdafba5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,11 @@
<version>3.10.3.Final</version>
</dependency>
<dependency>
+ <groupId>com.ning</groupId>
+ <artifactId>async-http-client</artifactId>
+ <version>1.9.29</version>
+ </dependency>
+ <dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 4ff4030f0..689b63ab6 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -125,7 +125,13 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("geocoder", new ReverseGeocoderHandler(Context.getReverseGeocoder(), processInvalidPositions));
}
pipeline.addLast("remoteAddress", new RemoteAddressHandler());
- pipeline.addLast("handler", new MainEventHandler());
+ if (Context.getDataManager() != null) {
+ pipeline.addLast("dataHandler", new DefaultDataHandler());
+ }
+ if (Boolean.valueOf(Context.getProps().getProperty("forward.enable"))) {
+ pipeline.addLast("webHandler", new WebDataHandler(Context.getProps().getProperty("forward.url")));
+ }
+ pipeline.addLast("mainHandler", new MainEventHandler());
return pipeline;
}
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index cc7501c9a..6fb812f4f 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -35,6 +35,18 @@ public class Context {
public static Properties getProps() {
return properties;
}
+
+ /*public static boolean getPropBoolean(String key) {
+ return Boolean.valueOf(properties.getProperty(key));
+ }
+
+ public static int getPropInt() {
+ return Integer.valueOf(null);
+ }
+
+ public static String getPropString() {
+ return null;
+ }*/
private static boolean loggerEnabled;
diff --git a/src/org/traccar/DefaultDataHandler.java b/src/org/traccar/DefaultDataHandler.java
new file mode 100644
index 000000000..430e20776
--- /dev/null
+++ b/src/org/traccar/DefaultDataHandler.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar;
+
+import org.traccar.helper.Log;
+import org.traccar.model.Position;
+
+public class DefaultDataHandler extends BaseDataHandler {
+
+ @Override
+ protected Position handlePosition(Position position) {
+
+ try {
+ Context.getDataManager().addPosition(position);
+ Context.getDataManager().updateLatestPosition(position);
+ Context.getConnectionManager().update(position);
+ } catch (Exception error) {
+ Log.warning(error);
+ }
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
index 30ec75f58..b32d577de 100644
--- a/src/org/traccar/MainEventHandler.java
+++ b/src/org/traccar/MainEventHandler.java
@@ -31,27 +31,18 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
if (e.getMessage() != null) {
-
if (e.getMessage() instanceof Position) {
Position position = (Position) e.getMessage();
// Log position
StringBuilder s = new StringBuilder();
- s.append("device: ").append(position.getDeviceId()).append(", ");
+ s.append(formatChannel(e.getChannel())).append(" ");
+ s.append("id: ").append(position.getDeviceId()).append(", ");
s.append("time: ").append(position.getFixTime()).append(", ");
s.append("lat: ").append(position.getLatitude()).append(", ");
s.append("lon: ").append(position.getLongitude());
Log.info(s.toString());
-
- try {
- Context.getDataManager().addPosition(position);
- Context.getDataManager().updateLatestPosition(position);
- Context.getConnectionManager().update(position);
- } catch (Exception error) {
- Log.warning(error);
- }
-
}
}
}
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java
new file mode 100644
index 000000000..bb1a540a9
--- /dev/null
+++ b/src/org/traccar/WebDataHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar;
+
+import com.ning.http.client.AsyncHttpClient;
+import org.traccar.model.Position;
+
+public class WebDataHandler extends BaseDataHandler {
+
+ private final String url;
+
+ public WebDataHandler(String url) {
+ this.url = url;
+ }
+
+ @Override
+ protected Position handlePosition(Position position) {
+ String request = url.
+ //replaceAll("\\{uniqueId}", String.valueOf(position.getDeviceId())).
+ replaceAll("\\{deviceId}", String.valueOf(position.getDeviceId())).
+ replaceAll("\\{fixTime}", String.valueOf(position.getFixTime().getTime())).
+ replaceAll("\\{latitude}", String.valueOf(position.getLatitude())).
+ replaceAll("\\{longitude}", String.valueOf(position.getLongitude()));
+
+ AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
+ asyncHttpClient.prepareGet(request).execute();
+
+ return position;
+ }
+
+}