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;
public class DebuggerPlugin implements Plugin, PropertyEventListener {
private RawPrintFilter defaultPortFilter;
private RawPrintFilter oldPortFilter;
private RawPrintFilter componentPortFilter;
private InterpretedXMLPrinter interpretedPrinter;
public void initializePlugin(PluginManager manager, File pluginDirectory) {
// Add filter to filter chain builder
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
defaultPortFilter = new RawPrintFilter();
defaultPortFilter = new RawPrintFilter("C2S");
SocketAcceptor socketAcceptor = connManager.getSocketAcceptor();
if (socketAcceptor != null) {
socketAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", defaultPortFilter);
}
oldPortFilter = new RawPrintFilter();
oldPortFilter = new RawPrintFilter("SSL");
SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor();
if (sslAcceptor != null) {
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();
if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) {
// Add the packet interceptor that prints interpreted XML
......@@ -74,6 +81,10 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
connManager.getSSLSocketAcceptor().getFilterChain().contains("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
if (defaultPortFilter != null) {
defaultPortFilter.shutdown();
......@@ -81,12 +92,16 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
if (oldPortFilter != null) {
oldPortFilter.shutdown();
}
if (componentPortFilter != null) {
componentPortFilter.shutdown();
}
// Remove the packet interceptor that prints interpreted XML
InterceptorManager.getInstance().removeInterceptor(interpretedPrinter);
defaultPortFilter = null;
oldPortFilter = null;
componentPortFilter = null;
interpretedPrinter = null;
}
......
......@@ -28,8 +28,13 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* @author Gaston Dombiak
*/
public class RawPrintFilter extends IoFilterAdapter {
private String prefix;
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>();
public RawPrintFilter(String prefix) {
this.prefix = prefix;
}
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
// Decode the bytebuffer and print it to the stdout
if (message instanceof ByteBuffer) {
......@@ -40,7 +45,7 @@ public class RawPrintFilter extends IoFilterAdapter {
Charset encoder = Charset.forName("UTF-8");
CharBuffer charBuffer = encoder.decode(byteBuffer.buf());
// Print buffer content
System.out.println("RECV (" + session.hashCode() + "): " + charBuffer);
System.out.println(prefix + " - RECV (" + session.hashCode() + "): " + charBuffer);
// Reset to old position in the buffer
byteBuffer.position(currentPos);
}
......@@ -49,7 +54,7 @@ public class RawPrintFilter extends IoFilterAdapter {
}
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()));
// Pass the message to the next filter
......@@ -80,4 +85,4 @@ public class RawPrintFilter extends IoFilterAdapter {
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