Commit 27c5cc74 authored by Guus der Kinderen's avatar Guus der Kinderen Committed by GitHub

Merge pull request #610 from GregDThomas/OF-1152

OF-1152: Ensure that raw XML is logged;
parents bfc13370 b227b3cb
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>Broadcast Plugin Changelog</title> <title>XML Debugger Plugin Changelog</title>
<style type="text/css"> <style type="text/css">
BODY { BODY {
font-size : 100%; font-size : 100%;
...@@ -43,6 +43,11 @@ ...@@ -43,6 +43,11 @@
<h1> <h1>
XML Debugger Plugin Changelog XML Debugger Plugin Changelog
</h1> </h1>
<p><b>1.6.0</b> -- June 20, 2016</p>
<li>[<a href='http://issues.igniterealtime.org/browse/OF-1152'>OF-1152</a>] - Ensure that the plugin prints raw XML.</li>
<li>Requires Openfire 4</li>
<p><b>1.5.0</b> -- October 12, 2015</p> <p><b>1.5.0</b> -- October 12, 2015</p>
<ul> <ul>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-953'>OF-953</a>] - Updated JSP libraries.</li> <li>[<a href='http://www.igniterealtime.org/issues/browse/OF-953'>OF-953</a>] - Updated JSP libraries.</li>
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
<name>Debugger Plugin</name> <name>Debugger Plugin</name>
<description>Prints XML traffic to the stdout (raw and interpreted XML)</description> <description>Prints XML traffic to the stdout (raw and interpreted XML)</description>
<author>Jive Software</author> <author>Jive Software</author>
<version>1.5.0</version> <version>1.6.0</version>
<date>10/12/2015</date> <date>06/20/2016</date>
<minServerVersion>4.0.0</minServerVersion> <minServerVersion>4.0.0</minServerVersion>
<adminconsole> <adminconsole>
......
...@@ -27,6 +27,7 @@ import org.apache.mina.transport.socket.SocketAcceptor; ...@@ -27,6 +27,7 @@ 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;
import org.jivesoftware.openfire.container.PluginManagerListener;
import org.jivesoftware.openfire.interceptor.InterceptorManager; import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.jivesoftware.openfire.spi.ConnectionManagerImpl; import org.jivesoftware.openfire.spi.ConnectionManagerImpl;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
...@@ -49,30 +50,45 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener { ...@@ -49,30 +50,45 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
private InterpretedXMLPrinter interpretedPrinter; private InterpretedXMLPrinter interpretedPrinter;
public void initializePlugin(PluginManager manager, File pluginDirectory) { public void initializePlugin(final PluginManager pluginManager, final File pluginDirectory) {
if (pluginManager.isExecuted()) {
addInterceptors();
} else {
pluginManager.addPluginManagerListener(new PluginManagerListener() {
public void pluginsMonitored() {
// Stop listening for plugin events
pluginManager.removePluginManagerListener(this);
// Start listeners
addInterceptors();
}
});
}
}
private void addInterceptors() {
// Add filter to filter chain builder // Add filter to filter chain builder
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager(); ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
defaultPortFilter = new RawPrintFilter("C2S"); defaultPortFilter = new RawPrintFilter("C2S");
SocketAcceptor socketAcceptor = connManager.getSocketAcceptor(); SocketAcceptor socketAcceptor = connManager.getSocketAcceptor();
if (socketAcceptor != null) { if (socketAcceptor != null) {
socketAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", defaultPortFilter); socketAcceptor.getFilterChain().addFirst("rawDebugger", defaultPortFilter);
} }
oldPortFilter = new RawPrintFilter("SSL"); oldPortFilter = new RawPrintFilter("SSL");
SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor(); SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor();
if (sslAcceptor != null) { if (sslAcceptor != null) {
sslAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", oldPortFilter); sslAcceptor.getFilterChain().addFirst("rawDebugger", oldPortFilter);
} }
componentPortFilter = new RawPrintFilter("ExComp"); componentPortFilter = new RawPrintFilter("ExComp");
SocketAcceptor componentAcceptor = connManager.getComponentAcceptor(); SocketAcceptor componentAcceptor = connManager.getComponentAcceptor();
if (componentAcceptor != null) { if (componentAcceptor != null) {
componentAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", componentPortFilter); componentAcceptor.getFilterChain().addFirst("rawDebugger", componentPortFilter);
} }
multiplexerPortFilter = new RawPrintFilter("CM"); multiplexerPortFilter = new RawPrintFilter("CM");
SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor(); SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor();
if (multiplexerAcceptor != null) { if (multiplexerAcceptor != null) {
multiplexerAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", multiplexerPortFilter); multiplexerAcceptor.getFilterChain().addFirst("rawDebugger", multiplexerPortFilter);
} }
interpretedPrinter = new InterpretedXMLPrinter(); interpretedPrinter = new InterpretedXMLPrinter();
......
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
package org.jivesoftware.openfire.plugin; package org.jivesoftware.openfire.plugin;
import java.nio.ByteBuffer;
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.buffer.IoBuffer;
import org.apache.mina.core.filterchain.IoFilterAdapter; import org.apache.mina.core.filterchain.IoFilterAdapter;
import org.apache.mina.core.session.IoSession; import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.write.WriteRequest; import org.apache.mina.core.write.WriteRequest;
...@@ -51,29 +51,33 @@ public class RawPrintFilter extends IoFilterAdapter { ...@@ -51,29 +51,33 @@ 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 IoBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) message; logBuffer(session, (IoBuffer) message, "RECV");
// Keep current position in the buffer
int currentPos = byteBuffer.position();
// Decode buffer
Charset encoder = Charset.forName("UTF-8");
CharBuffer charBuffer = encoder.decode(byteBuffer.asReadOnlyBuffer());
// Print buffer content
System.out.println(prefix + " - RECV (" + session.hashCode() + "): " + charBuffer);
// Reset to old position in the buffer
byteBuffer.position(currentPos);
} }
// Pass the message to the next filter // Pass the message to the next filter
super.messageReceived(nextFilter, session, message); super.messageReceived(nextFilter, session, message);
} }
private void logBuffer(final IoSession session, final IoBuffer ioBuffer, final String receiveOrSend) {
// Keep current position in the buffer
int currentPos = ioBuffer.position();
// Decode buffer
CharBuffer charBuffer = Charset.forName("UTF-8").decode(ioBuffer.buf());
// Print buffer content
System.out.println(messagePrefix(session, receiveOrSend) + ": " + charBuffer);
// Reset to old position in the buffer
ioBuffer.position(currentPos);
}
private String messagePrefix(final IoSession session, final String messageType) {
return prefix + " - " + messageType + String.format(" - (%1$11s)", session.hashCode());
}
@Override @Override
public void messageSent(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception { public void messageSent(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception {
if (enabled && writeRequest.getMessage() instanceof ByteBuffer) { if (enabled && writeRequest.getMessage() instanceof IoBuffer) {
System.out.println(prefix + " - SENT (" + session.hashCode() + "): " + logBuffer(session, (IoBuffer) writeRequest.getMessage(), "SENT");
Charset.forName("UTF-8").decode(((ByteBuffer) writeRequest.getMessage()).asReadOnlyBuffer()));
} }
// Pass the message to the next filter // Pass the message to the next filter
super.messageSent(nextFilter, session, writeRequest); super.messageSent(nextFilter, session, writeRequest);
} }
...@@ -99,7 +103,10 @@ public class RawPrintFilter extends IoFilterAdapter { ...@@ -99,7 +103,10 @@ public class RawPrintFilter extends IoFilterAdapter {
public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception { public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception {
// Keep track of sessions using this filter // Keep track of sessions using this filter
sessions.add(session); sessions.add(session);
if (enabled) {
// Print that a session was closed
System.out.println(messagePrefix(session, "OPEN"));
}
super.sessionCreated(nextFilter, session); super.sessionCreated(nextFilter, session);
} }
...@@ -109,9 +116,8 @@ public class RawPrintFilter extends IoFilterAdapter { ...@@ -109,9 +116,8 @@ public class RawPrintFilter extends IoFilterAdapter {
sessions.remove(session); sessions.remove(session);
if (enabled) { if (enabled) {
// Print that a session was closed // Print that a session was closed
System.out.println("CLOSED (" + session.hashCode() + ") "); System.out.println(messagePrefix(session, "CLSD"));
} }
super.sessionClosed(nextFilter, session); super.sessionClosed(nextFilter, session);
} }
} }
\ No newline at end of file
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