aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java24
-rw-r--r--src/org/traccar/model/Event.java1
2 files changed, 25 insertions, 0 deletions
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
index ca4561a3f..900b7bdbc 100644
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ b/src/org/traccar/ExtendedObjectDecoder.java
@@ -17,15 +17,37 @@ package org.traccar;
import java.net.SocketAddress;
import java.util.Collection;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelEvent;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
+
+import javax.xml.bind.DatatypeConverter;
public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
+ private void saveOriginal(Object decodedMessage, Object originalMessage) {
+ if (Context.getConfig().getBoolean("database.saveOriginal")) {
+ if (decodedMessage instanceof Position) {
+ Position position = (Position) decodedMessage;
+ if (originalMessage instanceof ChannelBuffer) {
+ position.set(Event.KEY_ORIGINAL,
+ ChannelBuffers.hexDump((ChannelBuffer) originalMessage));
+ } else if (originalMessage instanceof String) {
+ position.set(Event.KEY_ORIGINAL,
+ DatatypeConverter.printHexBinary(((String) originalMessage).getBytes()));
+ }
+ }
+ }
+ }
+
@Override
public void handleUpstream(
ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
@@ -43,9 +65,11 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
} else if (decodedMessage != null) {
if (decodedMessage instanceof Collection) {
for (Object o : (Collection) decodedMessage) {
+ saveOriginal(o, originalMessage);
Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
}
} else {
+ saveOriginal(decodedMessage, originalMessage);
Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 221536530..d0e340973 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -20,6 +20,7 @@ import java.util.Date;
public abstract class Event extends Extensible {
// Words separated by dashes (word-second-third)
+ public static final String KEY_ORIGINAL = "raw";
public static final String KEY_INDEX = "index";
public static final String KEY_HDOP = "hdop";
public static final String KEY_SATELLITES = "sat";