openfire以前的版本,可以在调试时,直接把xml输出到控制台。但现在不能输出了。我跟了下源码。调试输出是由插件 Debugger Plugin 实现的。
位于源码目录:src\plugins\xmldebugger
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
public void initializePlugin(PluginManager manager,File pluginDirectory) {
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
defaultPortFilter =
new RawPrintFilter(
"C2S");
SocketAcceptor socketAcceptor = connManager.getSocketAcceptor();
if (socketAcceptor !=
null) {
socketAcceptor.getFilterChain().addBefore(
"xmpp",
"rawDebugger",defaultPortFilter);
}
oldPortFilter =
"SSL");
SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor();
if (sslAcceptor !=
null) {
sslAcceptor.getFilterChain().addBefore(
"ExComp");
SocketAcceptor componentAcceptor = connManager.getComponentAcceptor();
if (componentAcceptor !=
null) {
componentAcceptor.getFilterChain().addBefore(
"CM");
SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor();
if (multiplexerAcceptor !=
null) {
multiplexerAcceptor.getFilterChain().addBefore(
new InterpretedXMLPrinter();
if (JiveGlobals.getBooleanProperty(
"plugin.debugger.interpretedAllowed")) {
InterceptorManager.getInstance().addInterceptor(interpretedPrinter);
}
PropertyEventDispatcher.addListener(
this);
}
从上面已经允许C2S打印日志输出。但是实际上openfire并没有打印C2S日志。再看RawPrintFilter实现:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
/** * 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. * * @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);
}
@Override
void messageReceived(NextFilter nextFilter,IoSession session,Object message)
throws Exception {
if (enabled && message
instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) message;
int currentPos = byteBuffer.position();
Charset encoder = Charset.forName(
"UTF-8");
CharBuffer charBuffer = encoder.decode(byteBuffer.asReadOnlyBuffer());
System.out.println(prefix +
" - RECV (" + session.hashCode() +
"): " + charBuffer);
byteBuffer.position(currentPos);
}
super.messageReceived(nextFilter,session,message);
}
void messageSent(NextFilter nextFilter,WriteRequest writeRequest)
throws Exception {
if (enabled && writeRequest.getMessage()
instanceof ByteBuffer) {
System.out.println(prefix +
" - SENT (" + session.hashCode() +
"): " +
Charset.forName(
"UTF-8").decode(((ByteBuffer) writeRequest.getMessage()).asReadOnlyBuffer()));
}
.messageSent(nextFilter,writeRequest);
}
boolean isEnabled() {
return enabled;
}
void setEnabled(
boolean enabled) {
this.enabled = enabled;
JiveGlobals.setProperty(
void shutdown() {
for (IoSession session : sessions) {
session.getFilterChain().remove(
"rawDebugger");
}
sessions =
null;
}
void sessionCreated(NextFilter nextFilter,IoSession session)
// Keep track of sessions using this filter
sessions.add(session);
super.sessionCreated(nextFilter,session);
}
void sessionClosed(NextFilter nextFilter,0);
Box-sizing: border-
Box;">// Update list of sessions using this filter
sessions.remove(session);
if (enabled) {
System.out.println(
"CLOSED (" + session.hashCode() +
") ");
}
super.sessionClosed(nextFilter,session);
}
}
在构造函数中,此类定义了一个开关enable。所以要打开c2s,需要设置 plugin.xmldebugger.c2s为 true。 如果要打开ssl打印日志。需要设置plugin.xmldebugger.ssl为true。等等。 如果要打开拦截器日志,则需要设置 plugin.debugger.interpretedAllowed 为 true 。 所以,登录管理端,把它加到服务器-》服务器管理-》系统属性中。xml 可以输出到控制端了。