openfire 开发时输出xml到控制台

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) { // Add filter to filter chain builder 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")) { // Add the packet interceptor that prints interpreted XML InterceptorManager.getInstance().addInterceptor(interpretedPrinter); } // Listen to property events 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 { // 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.asReadOnlyBuffer()); // 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); } 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())); } super.messageSent(nextFilter,writeRequest); } boolean isEnabled() { return enabled; } void setEnabled(boolean enabled) { this.enabled = enabled; JiveGlobals.setProperty(void shutdown() { // Remove this filter from sessions that are using it 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) { // Print that a session was closed 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 可以输出到控制端了。

    版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

    相关推荐


    php输出xml格式字符串
    J2ME Mobile 3D入门教程系列文章之一
    XML轻松学习手册
    XML入门的常见问题(一)
    XML入门的常见问题(三)
    XML轻松学习手册(2)XML概念
    xml文件介绍及使用
    xml编程(一)-xml语法
    XML文件结构和基本语法
    第2章 包装类
    XML入门的常见问题(二)
    Java对象的强、软、弱和虚引用
    JS解析XML文件和XML字符串详解
    java中枚举的详细使用介绍
    了解Xml格式
    XML入门的常见问题(四)
    深入SQLite多线程的使用总结详解
    PlayFramework完整实现一个APP(一)
    XML和YAML的使用方法
    XML轻松学习总节篇