diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-23 21:42:43 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-23 21:42:43 +1300 |
commit | ac2f547aa7799e471a8f4a71812fe8efdf5505c5 (patch) | |
tree | 163b16ca93714fb18be5c432324433177bff8f41 /src/org/traccar/BaseProtocolDecoder.java | |
parent | 23086613c6e88aa768afa795340fe9ac0ac3a7db (diff) | |
download | trackermap-server-ac2f547aa7799e471a8f4a71812fe8efdf5505c5.tar.gz trackermap-server-ac2f547aa7799e471a8f4a71812fe8efdf5505c5.tar.bz2 trackermap-server-ac2f547aa7799e471a8f4a71812fe8efdf5505c5.zip |
Fix Norad decoder (fix #610)
Diffstat (limited to 'src/org/traccar/BaseProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/BaseProtocolDecoder.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index 657e56258..447bf364b 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -15,6 +15,12 @@ */ package org.traccar; +import java.net.SocketAddress; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelEvent; +import org.jboss.netty.channel.ChannelHandlerContext; +import static org.jboss.netty.channel.Channels.fireMessageReceived; +import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.model.DataManager; @@ -51,5 +57,38 @@ public abstract class BaseProtocolDecoder extends OneToOneDecoder { dataManager = serverManager.getDataManager(); } } + + @Override + public void handleUpstream( + ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { + if (!(evt instanceof MessageEvent)) { + ctx.sendUpstream(evt); + return; + } + + MessageEvent e = (MessageEvent) evt; + Object originalMessage = e.getMessage(); + Object decodedMessage = decode(ctx, e.getChannel(), e.getRemoteAddress(), originalMessage); + if (originalMessage == decodedMessage) { + ctx.sendUpstream(evt); + } else if (decodedMessage != null) { + fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress()); + } + } + + protected Object decode( + ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + return decode(ctx, channel, msg); + + } + + @Override + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { + + return null; // default implementation + + } } |