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

Ported changes from trunk.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/openfire_3_5_2@10444 b35dd754-fafc-0310-a699-88a17e54d16e
parent dc970028
......@@ -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
......@@ -3,7 +3,7 @@
* $Revision: $
* $Date: $
*
* Copyright (C) 2008 Jive Software. All rights reserved.
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
......@@ -36,23 +36,37 @@ import java.util.Map;
public class DebuggerPlugin implements Plugin, PropertyEventListener {
private RawPrintFilter defaultPortFilter;
private RawPrintFilter oldPortFilter;
private RawPrintFilter componentPortFilter;
private RawPrintFilter multiplexerPortFilter;
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);
}
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
......@@ -75,6 +89,14 @@ 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");
}
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();
......@@ -82,15 +104,38 @@ public class DebuggerPlugin implements Plugin, PropertyEventListener {
if (oldPortFilter != null) {
oldPortFilter.shutdown();
}
if (componentPortFilter != null) {
componentPortFilter.shutdown();
}
if (multiplexerPortFilter != null) {
multiplexerPortFilter.shutdown();
}
// Remove the packet interceptor that prints interpreted XML
InterceptorManager.getInstance().removeInterceptor(interpretedPrinter);
defaultPortFilter = null;
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")) {
......
......@@ -3,7 +3,7 @@
* $Revision: $
* $Date: $
*
* Copyright (C) 2008 Jive Software. All rights reserved.
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
......
......@@ -3,7 +3,7 @@
* $Revision: $
* $Date: $
*
* Copyright (C) 2008 Jive Software. All rights reserved.
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
......@@ -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;
......@@ -24,61 +25,80 @@ import java.util.concurrent.ConcurrentLinkedQueue;
/**
* 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
* a session is closed.
* a session is closed.
*
* @author Gaston Dombiak
*/
public class RawPrintFilter extends IoFilterAdapter {
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>();
private boolean enabled = true;
private String prefix;
private Collection<IoSession> sessions = new ConcurrentLinkedQueue<IoSession>();
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
// Decode the bytebuffer and print it to the stdout
if (message instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) message;
// Keep current position in the buffer
int currentPos = byteBuffer.position();
// Decode buffer
Charset encoder = Charset.forName("UTF-8");
CharBuffer charBuffer = encoder.decode(byteBuffer.buf());
// Print buffer content
System.out.println("RECV (" + session.hashCode() + "): " + charBuffer);
// Reset to old position in the buffer
byteBuffer.position(currentPos);
}
// Pass the message to the next filter
super.messageReceived(nextFilter, session, message);
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 (enabled && message instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) message;
// Keep current position in the buffer
int currentPos = byteBuffer.position();
// Decode buffer
Charset encoder = Charset.forName("UTF-8");
CharBuffer charBuffer = encoder.decode(byteBuffer.buf());
// 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
super.messageReceived(nextFilter, session, message);
}
public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws Exception {
System.out.println("SENT (" + session.hashCode() + "): " +
public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws Exception {
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);
}
// Pass the message to the next filter
super.messageSent(nextFilter, session, message);
}
public void shutdown() {
// Remove this filter from sessions that are using it
for (IoSession session : sessions) {
session.getFilterChain().remove("rawDebugger");
}
sessions = null;
}
public boolean isEnabled() {
return enabled;
}
public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception {
// Keep track of sessions using this filter
sessions.add(session);
public void setEnabled(boolean enabled) {
this.enabled = enabled;
JiveGlobals.setProperty("plugin.xmldebugger." + prefix.toLowerCase(), Boolean.toString(enabled));
}
super.sessionCreated(nextFilter, session);
public void shutdown() {
// Remove this filter from sessions that are using it
for (IoSession session : sessions) {
session.getFilterChain().remove("rawDebugger");
}
sessions = null;
}
public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception {
// Keep track of sessions using this filter
sessions.add(session);
public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception {
// Update list of sessions using this filter
sessions.remove(session);
super.sessionCreated(nextFilter, session);
}
public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception {
// Update list of sessions using this filter
sessions.remove(session);
if (enabled) {
// Print that a session was closed
System.out.println("CLOSED (" + session.hashCode() + ") ");
super.sessionClosed(nextFilter, session);
}
}
\ No newline at end of file
super.sessionClosed(nextFilter, session);
}
}
\ No newline at end of file
<%@ 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