zoukankan      html  css  js  c++  java
  • 解决openfire中发送某些特殊字符会断开xmpp连接的问题

    在openfire中,如果发送某些特殊的字符(例如一些表情符合),会断开xmpp的连接,经查,是由以下的代码问题引起的:

    srcjavaorgjivesoftwareopenfire etMXParser.java


        protected char more() throws IOException, XmlPullParserException {
        	final char codePoint  = super.more(); // note - this does NOT return a codepoint now, but simply a (single byte) character!
    		if ((codePoint == 0x0) ||  // 0x0 is not allowed, but flash clients insist on sending this as the very first character of a stream. We should stop allowing this codepoint after the first byte has been parsed.
    				(codePoint == 0x9) ||          				     
    				(codePoint == 0xA) ||
    				(codePoint == 0xD) ||
    				((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
    				((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||
    				((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) {
    			return codePoint;
    		}
    		
    		throw new XmlPullParserException("Illegal XML character: " + Integer.parseInt(codePoint+"", 16));
        }

    由于在这里把特殊的字符当成了一个异常,所以openfire会断开连接。


    解决方法:

    把代码修改为如下:

        @Override
        protected char more() throws IOException, XmlPullParserException {
        	final char codePoint  = super.more(); // note - this does NOT return a codepoint now, but simply a (single byte) character!
    		if ((codePoint == 0x0) ||  // 0x0 is not allowed, but flash clients insist on sending this as the very first character of a stream. We should stop allowing this codepoint after the first byte has been parsed.
    				(codePoint == 0x9) ||          				     
    				(codePoint == 0xA) ||
    				(codePoint == 0xD) ||		
    				//fix some emotion
    				((codePoint >= 0x20) && (codePoint <= 0xFFFD)) ||				
    				((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) {
    			return codePoint;
    		}
    		
    		throw new XmlPullParserException("Illegal XML character: " + Integer.parseInt(codePoint+"", 16));
        }




    [文章作者]曾健生

    [作者邮箱]h6k65@126.com

    [作者QQ]190678908

    [新浪微博] @newjueqi

    [博客]http://blog.csdn.net/newjueqi

              http://blog.sina.com.cn/h6k65


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Java.util.Timer的灵活配置与使用
    js字符变量判空
    js获取当前时间格式化字符串
    Java快速获取格式化的日期字符串
    img标签显示图片方法总结
    Java获取给定日期的月初和月末两个日期
    SpringBoot学习--07配置Druid数据库连接池
    SpringBoot学习--06使用jackson返回json数据
    SpringBoot学习--05SpringBoot整合Mybatis(下)(mybatis中踩过的坑)--不定时更新
    SpringBoot学习--04SpringBoot整合Mybatis(上)(配置mybatis generator)
  • 原文地址:https://www.cnblogs.com/dingxiaoyue/p/4926832.html
Copyright © 2011-2022 走看看