Commit 7032818e authored by Tom Evans's avatar Tom Evans

OF-421: Update xmldebugger for Mina API changes

Adjust xmldebugger for changes in the MINA 2.0.7 filtering API
parent b117b186
...@@ -20,7 +20,10 @@ ...@@ -20,7 +20,10 @@
package org.jivesoftware.openfire.plugin; package org.jivesoftware.openfire.plugin;
import org.apache.mina.transport.socket.nio.SocketAcceptor; import java.io.File;
import java.util.Map;
import org.apache.mina.transport.socket.SocketAcceptor;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin; import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.container.PluginManager;
...@@ -30,9 +33,6 @@ import org.jivesoftware.util.JiveGlobals; ...@@ -30,9 +33,6 @@ import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener; import org.jivesoftware.util.PropertyEventListener;
import java.io.File;
import java.util.Map;
/** /**
* Debugger plugin that prints XML traffic to stdout. By default it will only print * Debugger plugin that prints XML traffic to stdout. By default it will only print
* raw XML traffic (by using a MINA filter). To turn on printing of interpreted XML * raw XML traffic (by using a MINA filter). To turn on printing of interpreted XML
......
...@@ -20,16 +20,17 @@ ...@@ -20,16 +20,17 @@
package org.jivesoftware.openfire.plugin; package org.jivesoftware.openfire.plugin;
import org.apache.mina.common.ByteBuffer; import java.nio.ByteBuffer;
import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoSession;
import org.jivesoftware.util.JiveGlobals;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.mina.core.filterchain.IoFilterAdapter;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.write.WriteRequest;
import org.jivesoftware.util.JiveGlobals;
/** /**
* MINA filter that prints to the stdout received XML stanzas before they are actually parsed and * MINA filter that prints to the stdout received XML stanzas before they are actually parsed and
* also prints XML stanzas as sent to the XMPP entities. Moreover, it also prints information when * also prints XML stanzas as sent to the XMPP entities. Moreover, it also prints information when
...@@ -50,13 +51,13 @@ public class RawPrintFilter extends IoFilterAdapter { ...@@ -50,13 +51,13 @@ public class RawPrintFilter extends IoFilterAdapter {
@Override @Override
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
// Decode the bytebuffer and print it to the stdout // Decode the bytebuffer and print it to the stdout
if (enabled && message instanceof ByteBuffer) { if (enabled && message instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) message; ByteBuffer byteBuffer = (ByteBuffer) message;
// Keep current position in the buffer // Keep current position in the buffer
int currentPos = byteBuffer.position(); int currentPos = byteBuffer.position();
// Decode buffer // Decode buffer
Charset encoder = Charset.forName("UTF-8"); Charset encoder = Charset.forName("UTF-8");
CharBuffer charBuffer = encoder.decode(byteBuffer.buf()); CharBuffer charBuffer = encoder.decode(byteBuffer.asReadOnlyBuffer());
// Print buffer content // Print buffer content
System.out.println(prefix + " - RECV (" + session.hashCode() + "): " + charBuffer); System.out.println(prefix + " - RECV (" + session.hashCode() + "): " + charBuffer);
// Reset to old position in the buffer // Reset to old position in the buffer
...@@ -67,10 +68,10 @@ public class RawPrintFilter extends IoFilterAdapter { ...@@ -67,10 +68,10 @@ public class RawPrintFilter extends IoFilterAdapter {
} }
@Override @Override
public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws Exception { public void messageSent(NextFilter nextFilter, IoSession session, WriteRequest message) throws Exception {
if (enabled) { if (enabled) {
System.out.println(prefix + " - SENT (" + session.hashCode() + "): " + System.out.println(prefix + " - SENT (" + session.hashCode() + "): " +
Charset.forName("UTF-8").decode(((ByteBuffer) message).buf())); Charset.forName("UTF-8").decode(((ByteBuffer) message).asReadOnlyBuffer()));
} }
// Pass the message to the next filter // Pass the message to the next filter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment