【问题标题】:Handle see-other-host in smack在 smack 中处理 see-other-host
【发布时间】:2012-07-03 10:12:52
【问题描述】:

我正在尝试使用 smack 来连接到 Microsoft 的 Xmpp Msn api。去年 4 月,他们对实现进行了更改,强制客户端实现“see-other-host”xmpp 规范。当我尝试连接到“xmpp.messenger.live.com”时,我得到了

stream:error (see-other-host) 在 org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:260) 在 org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43) 在 org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

我正在调试,我可以看到原始接收数据包

    <stream:stream from="messenger.live.com" version="1.0" id="59784" xmlns="jabber:client"     xmlns:stream="http://etherx.jabber.org/streams">
<stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required /></starttls></stream:features>
<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
<stream:stream from="messenger.live.com" version="1.0" id="59785" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams">
<stream:error xmlns:stream="http://etherx.jabber.org/streams"><see-other-host xmlns="urn:ietf:params:xml:ns:xmpp-streams">BY2MSG3020517.gateway.edge.messenge r.live.com</see-other-host></stream:error>

但我无法找到拦截和处理该重定向的方法。 有人做过吗?任何帮助,将不胜感激。谢谢。

顺便说一句,我已经在 smack 论坛上发布了这个但没有得到回复,希望这不是交叉发布。

【问题讨论】:

    标签: xmpp smack msn msn-messenger liveconnect


    【解决方案1】:

    此背景可能有助于解决问题

    see-other-host 流错误将客户端重定向到另一台服务器。就 Messenger 而言,它旨在允许客户端在其当前服务器停止服务时干净地切换到另一台服务器,或连接到另一台服务器以实现负载平衡。

    基于使用 SAMCK 的示例 Java 代码存在两个问题:

    1. 注册的连接监听器没有收到异常通知
    2. 无法从 XMPPException 访问流错误的文本元素

    在内部处理重定向将是最友好的解决方案,但将新服务器通知客户端至少可以让客户端在无需用户干预的情况下建立新连接。

    【讨论】:

    • @alscu 您是否介意向我们提供您在评论中提到的 hacky 方式,因为我们可能会从中受益并讨论它并帮助其他人应对这个 SMACK BUG ... 谢谢
    【解决方案2】:

    我为 SMACK API 添加了 see-other-host 支持以进行尝试。现在我可以将看到其他主机地址作为例外。例如,当我尝试连接到 messenger.live.com 地址时,我成功获得了 see-other-host:BAYMSG1020118.gateway.messenger.live.com。 然后我尝试连接 BAYMSG1020118.gateway.messenger.live.com ,我再次看到不同的地址:BY2MSG4010610.gateway.messenger.live.com 最后,当我尝试连接 BY2MSG4010610.gateway.messenger.live.com 时,我得到了这个异常:

    No response from the server.: 
    java.lang.NullPointerException
    at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:73)
    at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:211)
    at org.jivesoftware.smack.Connection.login(Connection.java:348)
    at com.ms.wlm.XmppClient.logIn(XmppClient.java:161)
    at com.ms.wlm.Program.main(Program.java:62)
    

    我也将与 Smack 家伙分享这个结果。如果您愿意,我可以通过电子邮件将我们的 xmpp 流量捕获发送给您。 最好的祝福, 阿尔珀·奥兹达马尔

    【讨论】:

    • 我们最终修改了 smack 代码,以一种 hacky 的方式,只是为了处理 see-other-host,直到 smack 正式支持它。感谢您的回复。
    【解决方案3】:

    我终于找到了解决此问题的方法,方法是在 ConnectionConfiguration 构造函数中将主机名从 messenger.live.com 更改为 64.4.61.217,如下代码所示:

    我通过在 Dos 命令提示符中执行 (nslookup messenger.live.com) 获得了这个 IP,然后我获得了我在 ConnectionConfiguration 中使用的地址。

        SASLAuthentication.registerSASLMechanism("X-MESSENGER-OAUTH2",
                XMessengerOAuth2.class);
        SASLAuthentication.supportSASLMechanism("X-MESSENGER-OAUTH2");
            ConnectionConfiguration config = new ConnectionConfiguration("64.4.61.217", 5222, "messenger.live.com");
            config.setRosterLoadedAtLogin(true);
            config.setSASLAuthenticationEnabled(true);
            connection = new XMPPConnection(config);
    
            connection.connect();
    
            connection.login(username, password);
    

    希望这会有所帮助,,,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-15
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 2016-02-26
      • 2011-12-28
      • 2013-02-06
      相关资源
      最近更新 更多