Commit f24ddf0c authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added printing of components traffic.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10146 b35dd754-fafc-0310-a699-88a17e54d16e
parent fa7928d9
...@@ -35,23 +35,30 @@ import java.util.Map; ...@@ -35,23 +35,30 @@ import java.util.Map;
public class DebuggerPlugin implements Plugin, PropertyEventListener { public class DebuggerPlugin implements Plugin, PropertyEventListener {
private RawPrintFilter defaultPortFilter; private RawPrintFilter defaultPortFilter;
private RawPrintFilter oldPortFilter; private RawPrintFilter oldPortFilter;
private RawPrintFilter componentPortFilter;
private InterpretedXMLPrinter interpretedPrinter; private InterpretedXMLPrinter interpretedPrinter;
public void initializePlugin(PluginManager manager, File pluginDirectory) { public void initializePlugin(PluginManager manager, File pluginDirectory) {
// 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(); 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().addBefore("xmpp", "rawDebugger", defaultPortFilter);
} }
oldPortFilter = new RawPrintFilter(); 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().addBefore("xmpp", "rawDebugger", oldPortFilter);
} }
componentPortFilter = new RawPrintFilter("ExComp");
SocketAcceptor componentAcceptor = connManager.getComponentAcceptor();
if (componentAcceptor != null) {
componentAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", componentPortFilter);
}
interpretedPrinter = new InterpretedXMLPrinter(); interpretedPrinter = new InterpretedXMLPrinter();
if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) { if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) {
// Add the packet interceptor that prints interpreted XML // Add the packet interceptor that prints interpreted XML
...@@ -74,6 +81,10 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener { ...@@ -74,6 +81,10 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
connManager.getSSLSocketAcceptor().getFilterChain().contains("rawDebugger")) { connManager.getSSLSocketAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getSSLSocketAcceptor().getFilterChain().remove("rawDebugger"); connManager.getSSLSocketAcceptor().getFilterChain().remove("rawDebugger");
} }
if (connManager.getComponentAcceptor() != null &&
connManager.getComponentAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getComponentAcceptor().getFilterChain().remove("rawDebugger");
}
// Remove the filters from existing sessions // Remove the filters from existing sessions
if (defaultPortFilter != null) { if (defaultPortFilter != null) {
defaultPortFilter.shutdown(); defaultPortFilter.shutdown();
...@@ -81,12 +92,16 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener { ...@@ -81,12 +92,16 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
if (oldPortFilter != null) { if (oldPortFilter != null) {
oldPortFilter.shutdown(); oldPortFilter.shutdown();
} }
if (componentPortFilter != null) {
componentPortFilter.shutdown();
}
// Remove the packet interceptor that prints interpreted XML // Remove the packet interceptor that prints interpreted XML
InterceptorManager.getInstance().removeInterceptor(interpretedPrinter); InterceptorManager.getInstance().removeInterceptor(interpretedPrinter);
defaultPortFilter = null; defaultPortFilter = null;
oldPortFilter = null; oldPortFilter = null;
componentPortFilter = null;
interpretedPrinter = null; interpretedPrinter = null;
} }
......
...@@ -23,61 +23,66 @@ import java.util.concurrent.ConcurrentLinkedQueue; ...@@ -23,61 +23,66 @@ import java.util.concurrent.ConcurrentLinkedQueue;
/** /**
* 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
* a session is closed. * a session is closed.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class RawPrintFilter extends IoFilterAdapter { public class RawPrintFilter extends IoFilterAdapter {
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>(); private String prefix;
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>();
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { public RawPrintFilter(String prefix) {
// Decode the bytebuffer and print it to the stdout this.prefix = prefix;
if (message instanceof ByteBuffer) { }
ByteBuffer byteBuffer = (ByteBuffer) message;
// Keep current position in the buffer public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
int currentPos = byteBuffer.position(); // Decode the bytebuffer and print it to the stdout
// Decode buffer if (message instanceof ByteBuffer) {
Charset encoder = Charset.forName("UTF-8"); ByteBuffer byteBuffer = (ByteBuffer) message;
CharBuffer charBuffer = encoder.decode(byteBuffer.buf()); // Keep current position in the buffer
// Print buffer content int currentPos = byteBuffer.position();
System.out.println("RECV (" + session.hashCode() + "): " + charBuffer); // Decode buffer
// Reset to old position in the buffer Charset encoder = Charset.forName("UTF-8");
byteBuffer.position(currentPos); CharBuffer charBuffer = encoder.decode(byteBuffer.buf());
} // Print buffer content
// Pass the message to the next filter System.out.println(prefix + " - RECV (" + session.hashCode() + "): " + charBuffer);
super.messageReceived(nextFilter, session, message); // Reset to old position in the buffer
byteBuffer.position(currentPos);
} }
// Pass the message to the next filter
super.messageReceived(nextFilter, session, message);
}
public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws Exception { public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws Exception {
System.out.println("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).buf()));
// Pass the message to the next filter // Pass the message to the next filter
super.messageSent(nextFilter, session, message); super.messageSent(nextFilter, session, message);
} }
public void shutdown() { public void shutdown() {
// Remove this filter from sessions that are using it // Remove this filter from sessions that are using it
for (IoSession session : sessions) { for (IoSession session : sessions) {
session.getFilterChain().remove("rawDebugger"); session.getFilterChain().remove("rawDebugger");
}
sessions = null;
} }
sessions = null;
}
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);
super.sessionCreated(nextFilter, session); super.sessionCreated(nextFilter, session);
} }
public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception { public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception {
// Update list of sessions using this filter // Update list of sessions using this filter
sessions.remove(session); sessions.remove(session);
// Print that a session was closed // Print that a session was closed
System.out.println("CLOSED (" + session.hashCode() + ") "); System.out.println("CLOSED (" + session.hashCode() + ") ");
super.sessionClosed(nextFilter, session); super.sessionClosed(nextFilter, session);
} }
} }
\ No newline at end of file \ 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