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@H_502_146@ void@H_502_146@ initializePlugin@H_502_146@(PluginManager manager,File pluginDirectory) {- // Add filter to filter chain builder@H_502_146@
- ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
- defaultPortFilter = new@H_502_146@ RawPrintFilter("C2S"@H_502_146@);
- SocketAcceptor socketAcceptor = connManager.getSocketAcceptor();
- if@H_502_146@ (socketAcceptor != null@H_502_146@) {
- socketAcceptor.getFilterChain().addBefore("xmpp"@H_502_146@,"rawDebugger"@H_502_146@,defaultPortFilter);
- }
- oldPortFilter = "SSL"@H_502_146@);
- SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor();
- if@H_502_146@ (sslAcceptor != null@H_502_146@) {
- sslAcceptor.getFilterChain().addBefore("ExComp"@H_502_146@);
- SocketAcceptor componentAcceptor = connManager.getComponentAcceptor();
- if@H_502_146@ (componentAcceptor != null@H_502_146@) {
- componentAcceptor.getFilterChain().addBefore("CM"@H_502_146@);
- SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor();
- if@H_502_146@ (multiplexerAcceptor != null@H_502_146@) {
- multiplexerAcceptor.getFilterChain().addBefore(new@H_502_146@ InterpretedXMLPrinter();
- if@H_502_146@ (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed"@H_502_146@)) {
- // Add the packet interceptor that prints interpreted XML@H_502_146@
- InterceptorManager.getInstance().addInterceptor(interpretedPrinter);
- }
- // Listen to property events@H_502_146@
- PropertyEventDispatcher.addListener(this@H_502_146@);
- }
从上面已经允许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@H_502_146@ Gaston Dombiak */@H_502_146@- public@H_502_146@ class@H_502_146@ RawPrintFilter@H_502_146@ extends@H_502_146@ IoFilterAdapter@H_502_146@ {@H_502_146@
- private@H_502_146@ boolean@H_502_146@ enabled = true@H_502_146@;
- private@H_502_146@ String prefix;
- private@H_502_146@ Collection<IoSession> sessions = new@H_502_146@ ConcurrentLinkedQueue<IoSession>();
- public@H_502_146@ RawPrintFilter@H_502_146@(String prefix) {
- this@H_502_146@.prefix = prefix;
- this@H_502_146@.enabled = JiveGlobals.getBooleanProperty("plugin.xmldebugger."@H_502_146@ + prefix.toLowerCase(),true@H_502_146@);
- }
- @Override@H_502_146@
- void@H_502_146@ messageReceived@H_502_146@(NextFilter nextFilter,IoSession session,Object message) throws@H_502_146@ Exception {
- // Decode the bytebuffer and print it to the stdout@H_502_146@
- if@H_502_146@ (enabled && message instanceof@H_502_146@ ByteBuffer) {
- ByteBuffer byteBuffer = (ByteBuffer) message;
- // Keep current position in the buffer@H_502_146@
- int@H_502_146@ currentPos = byteBuffer.position();
- // Decode buffer@H_502_146@
- Charset encoder = Charset.forName("UTF-8"@H_502_146@);
- CharBuffer charBuffer = encoder.decode(byteBuffer.asReadOnlyBuffer());
- // Print buffer content@H_502_146@
- System.out.println(prefix + " - RECV ("@H_502_146@ + session.hashCode() + "): "@H_502_146@ + charBuffer);
- // Reset to old position in the buffer@H_502_146@
- byteBuffer.position(currentPos);
- }
- // Pass the message to the next filter@H_502_146@
- super@H_502_146@.messageReceived(nextFilter,session,message);
- }
- void@H_502_146@ messageSent@H_502_146@(NextFilter nextFilter,WriteRequest writeRequest) throws@H_502_146@ Exception {
- if@H_502_146@ (enabled && writeRequest.getMessage() instanceof@H_502_146@ ByteBuffer) {
- System.out.println(prefix + " - SENT ("@H_502_146@ + session.hashCode() + "): "@H_502_146@ +
- Charset.forName("UTF-8"@H_502_146@).decode(((ByteBuffer) writeRequest.getMessage()).asReadOnlyBuffer()));
- }
- super@H_502_146@.messageSent(nextFilter,writeRequest);
- }
- boolean@H_502_146@ isEnabled@H_502_146@() {
- return@H_502_146@ enabled;
- }
- void@H_502_146@ setEnabled@H_502_146@(boolean@H_502_146@ enabled) {
- this@H_502_146@.enabled = enabled;
- JiveGlobals.setProperty(void@H_502_146@ shutdown@H_502_146@() {
- // Remove this filter from sessions that are using it@H_502_146@
- for@H_502_146@ (IoSession session : sessions) {
- session.getFilterChain().remove("rawDebugger"@H_502_146@);
- }
- sessions = null@H_502_146@;
- }
- void@H_502_146@ sessionCreated@H_502_146@(NextFilter nextFilter,IoSession session) // Keep track of sessions using this filter@H_502_146@
- sessions.add(session);
- super@H_502_146@.sessionCreated(nextFilter,session);
- }
- void@H_502_146@ sessionClosed@H_502_146@(NextFilter nextFilter,0); Box-sizing: border-Box;">// Update list of sessions using this filter@H_502_146@
- sessions.remove(session);
- if@H_502_146@ (enabled) {
- // Print that a session was closed@H_502_146@
- System.out.println("CLOSED ("@H_502_146@ + session.hashCode() + ") "@H_502_146@);
- }
- super@H_502_146@.sessionClosed(nextFilter,session);
- }
- }
在构造函数中,此类定义了一个开关enable。所以要打开c2s,需要设置 plugin.xmldebugger.c2s为 true。 如果要打开ssl打印日志。需要设置plugin.xmldebugger.ssl为true。等等。 如果要打开拦截器日志,则需要设置 plugin.debugger.interpretedAllowed 为 true 。 所以,登录管理端,把它加到服务器-》服务器管理-》系统属性中。xml 可以输出到控制端了。