Commit 4bb2b8d7 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1) Added support for debugging connection managers

2) Added UI configuration from admin console

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10443 b35dd754-fafc-0310-a699-88a17e54d16e
parent bd5b6ba4
......@@ -44,6 +44,17 @@
XML Debugger Plugin Changelog
</h1>
<p><b>1.2.0</b> -- May 26, 2008</p>
<ul>
<li>Added connection managers monitoring support.</li>
<li>Added configuration from admin console.</li>
</ul>
<p><b>1.1.0</b> -- March 28, 2007</p>
<ul>
<li>Added external component monitoring support.</li>
</ul>
<p><b>1.0.0</b> -- September 5, 2007</p>
<ul>
<li>Initial release.</li>
......
......@@ -8,6 +8,18 @@
<name>Debugger Plugin</name>
<description>Prints XML traffic to the stdout (raw and interpreted XML)</description>
<author>Jive Software</author>
<version>1.0</version>
<minServerVersion>3.2.0</minServerVersion>
<version>1.2</version>
<date>5/26/2008</date>
<minServerVersion>3.5.0</minServerVersion>
<adminconsole>
<tab id="tab-server">
<sidebar id="sidebar-server-settings">
<item id="debugger-conf"
name="Debugger Properties"
url="debugger-conf.jsp"
description="Edit debugger plugin properties" />
</sidebar>
</tab>
</adminconsole>
</plugin>
\ No newline at end of file
......@@ -37,6 +37,7 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
private RawPrintFilter defaultPortFilter;
private RawPrintFilter oldPortFilter;
private RawPrintFilter componentPortFilter;
private RawPrintFilter multiplexerPortFilter;
private InterpretedXMLPrinter interpretedPrinter;
......@@ -60,6 +61,12 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
componentAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", componentPortFilter);
}
multiplexerPortFilter = new RawPrintFilter("CM");
SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor();
if (multiplexerAcceptor != null) {
multiplexerAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", multiplexerPortFilter);
}
interpretedPrinter = new InterpretedXMLPrinter();
if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) {
// Add the packet interceptor that prints interpreted XML
......@@ -86,6 +93,10 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
connManager.getComponentAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getComponentAcceptor().getFilterChain().remove("rawDebugger");
}
if (connManager.getMultiplexerSocketAcceptor() != null &&
connManager.getMultiplexerSocketAcceptor().getFilterChain().contains("rawDebugger")) {
connManager.getMultiplexerSocketAcceptor().getFilterChain().remove("rawDebugger");
}
// Remove the filters from existing sessions
if (defaultPortFilter != null) {
defaultPortFilter.shutdown();
......@@ -96,6 +107,9 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
if (componentPortFilter != null) {
componentPortFilter.shutdown();
}
if (multiplexerPortFilter != null) {
multiplexerPortFilter.shutdown();
}
// Remove the packet interceptor that prints interpreted XML
InterceptorManager.getInstance().removeInterceptor(interpretedPrinter);
......@@ -104,8 +118,24 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
oldPortFilter = null;
componentPortFilter = null;
interpretedPrinter = null;
multiplexerPortFilter = null;
}
public RawPrintFilter getDefaultPortFilter() {
return defaultPortFilter;
}
public RawPrintFilter getOldPortFilter() {
return oldPortFilter;
}
public RawPrintFilter getComponentPortFilter() {
return componentPortFilter;
}
public RawPrintFilter getMultiplexerPortFilter() {
return multiplexerPortFilter;
}
public void propertySet(String property, Map<String, Object> params) {
if (property.equals("plugin.debugger.interpretedAllowed")) {
......
......@@ -15,6 +15,7 @@ package org.jivesoftware.openfire.plugin;
import org.apache.mina.common.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.charset.Charset;
......@@ -29,16 +30,18 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* @author Gaston Dombiak
*/
public class RawPrintFilter extends IoFilterAdapter {
private boolean enabled = true;
private String prefix;
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>();
public RawPrintFilter(String prefix) {
this.prefix = prefix;
this.enabled = JiveGlobals.getBooleanProperty("plugin.xmldebugger." + prefix.toLowerCase(), true);
}
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
// Decode the bytebuffer and print it to the stdout
if (message instanceof ByteBuffer) {
if (enabled && message instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) message;
// Keep current position in the buffer
int currentPos = byteBuffer.position();
......@@ -55,13 +58,23 @@ public class RawPrintFilter extends IoFilterAdapter {
}
public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws Exception {
System.out.println(prefix + " - SENT (" + session.hashCode() + "): " +
Charset.forName("UTF-8").decode(((ByteBuffer) message).buf()));
if (enabled) {
System.out.println(prefix + " - SENT (" + session.hashCode() + "): " +
Charset.forName("UTF-8").decode(((ByteBuffer) message).buf()));
}
// Pass the message to the next filter
super.messageSent(nextFilter, session, message);
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
JiveGlobals.setProperty("plugin.xmldebugger." + prefix.toLowerCase(), Boolean.toString(enabled));
}
public void shutdown() {
// Remove this filter from sessions that are using it
......@@ -81,8 +94,10 @@ public class RawPrintFilter extends IoFilterAdapter {
public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception {
// Update list of sessions using this filter
sessions.remove(session);
// Print that a session was closed
System.out.println("CLOSED (" + session.hashCode() + ") ");
if (enabled) {
// Print that a session was closed
System.out.println("CLOSED (" + session.hashCode() + ") ");
}
super.sessionClosed(nextFilter, session);
}
......
<%@ page import="org.jivesoftware.util.ParamUtils"
%>
<%@ page import="org.jivesoftware.openfire.plugin.DebuggerPlugin" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<html>
<head>
<title>XML Debugger Properties</title>
<meta name="pageID" content="debugger-conf"/>
</head>
<body>
<%
boolean update = request.getParameter("update") != null;
boolean c2s = ParamUtils.getBooleanParameter(request,"c2s");
boolean ssl = ParamUtils.getBooleanParameter(request,"ssl");
boolean extcomp = ParamUtils.getBooleanParameter(request,"extcomp");
boolean cm = ParamUtils.getBooleanParameter(request,"cm");
DebuggerPlugin plugin = (DebuggerPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("xmldebugger");
if (update) {
// Save new settings
plugin.getDefaultPortFilter().setEnabled(c2s);
plugin.getOldPortFilter().setEnabled(ssl);
plugin.getComponentPortFilter().setEnabled(extcomp);
plugin.getMultiplexerPortFilter().setEnabled(cm);
}
else {
// Set current values
c2s = plugin.getDefaultPortFilter().isEnabled();
ssl = plugin.getOldPortFilter().isEnabled();
extcomp = plugin.getComponentPortFilter().isEnabled();
cm = plugin.getMultiplexerPortFilter().isEnabled();
}
%>
<form name="f" action="debugger-conf.jsp">
<div class="jive-contentBoxHeader">
Debug connections
</div>
<div class="jive-contentBox">
<table cellpadding="3" cellspacing="0" border="0">
<tbody>
<tr valign="middle">
<td width="1%" nowrap>
<input id="rb01" type="checkbox" name="c2s" <%= (c2s ? "checked" : "") %>/>
</td>
<td width="99%">
<label for="rb01">
Client (default port)
</label>
</td>
</tr>
<tr valign="middle">
<td width="1%" nowrap>
<input id="rb02" type="checkbox" name="ssl" <%= (ssl ? "checked" : "") %>/>
</td>
<td width="99%">
<label for="rb02">
Client (old SSL port)
</label>
</td>
</tr>
<tr valign="middle">
<td width="1%" nowrap>
<input id="rb03" type="checkbox" name="extcomp" <%= (extcomp ? "checked" : "") %>/>
</td>
<td width="99%">
<label for="rb03">
External Component
</label>
</td>
</tr>
<tr valign="middle">
<td width="1%" nowrap>
<input id="rb04" type="checkbox" name="cm" <%= (cm ? "checked" : "") %>/>
</td>
<td width="99%">
<label for="rb04">
Connection Manager
</label>
</td>
</tr>
</tbody>
</table>
</div>
<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">
</form>
</body>
</html>
\ 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