mirror of
https://github.com/traccar/traccar.git
synced 2025-01-08 11:47:49 +08:00
Add option to save original message
This commit is contained in:
parent
238e800a04
commit
c5e7beb059
@ -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'>
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user