diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-19 10:41:23 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-19 10:41:23 +1300 |
commit | c5e7beb05968c8e7e3fb5f9ed4434c8abc324a59 (patch) | |
tree | 5002f0bad609e35401cfbf1fa7035462948e993b | |
parent | 238e800a04b7bba6e83032f18e72086f7ec00deb (diff) | |
download | trackermap-server-c5e7beb05968c8e7e3fb5f9ed4434c8abc324a59.tar.gz trackermap-server-c5e7beb05968c8e7e3fb5f9ed4434c8abc324a59.tar.bz2 trackermap-server-c5e7beb05968c8e7e3fb5f9ed4434c8abc324a59.zip |
Add option to save original message
-rw-r--r-- | debug.xml | 3 | ||||
-rw-r--r-- | src/org/traccar/ExtendedObjectDecoder.java | 24 | ||||
-rw-r--r-- | src/org/traccar/model/Event.java | 1 |
3 files changed, 28 insertions, 0 deletions
@@ -48,7 +48,10 @@ <entry key='database.url'>jdbc:h2:./target/database</entry> <entry key='database.user'>sa</entry> <entry key='database.password'></entry> + <entry key='database.xml'>false</entry> + <entry key='database.saveOriginal'>false</entry> + <entry key='database.changelog'>./database/changelog-master.xml</entry> <entry key='database.selectServers'> 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"; |