Handle see-other-host in smack

懵懂的女人 提交于 2019-12-11 18:48:12

问题


I'm trying to use smack in order to connect to Microsoft's Xmpp Msn api. Last april they made a change in their implementation which forces clients to implement the "see-other-host" xmpp specification. When I try to connect to "xmpp.messenger.live.com" I get

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

I'm debugging and I can see the raw received packets

    <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>

But I'm unable to find a way in order to intercept and handle that redirect. Has anybody done this? Any help would be appreciated. Thanks.

BTW I've already post this on smack forums but got no reply, hope this is isn't considered cross-posting.


回答1:


This background may help in fixing the problem

The see-other-host stream error redirects a client to another server. In the case of Messenger, it's intended to allow clients to cleanly switch to another server should their current server go out of service, or to connect to another server for load-balancing purposes.

Based on Sample Java Codes that uses SAMCK there are two problems:

  1. The registered connection listeners don't receive notification of the exception
  2. there's no way to access the text element of a stream error from XMPPException

Handling the redirection internally would be the friendliest solution, but notifying the client of the new server would at least allow clients to make a new connection without user intervention.




回答2:


I added see-other-host support to SMACK API for try. Now i can get see-other-host address as an Exception. For Example when i try to connect to messenger.live.com address i'm successfully getting see-other-host : BAYMSG1020118.gateway.messenger.live.com . Then i try to connect BAYMSG1020118.gateway.messenger.live.com , i'm getting see-other-host again with different address: BY2MSG4010610.gateway.messenger.live.com Finally when i try to connect BY2MSG4010610.gateway.messenger.live.com , i'm getting this exception :

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)

I'll share this result with Smack guys also. If you want, I can send to you the capture of our xmpp traffic via email. Best Regards, Alper Ozdamar




回答3:


I finally found a solution for this issue by changing hostname from messenger.live.com to 64.4.61.217 in ConnectionConfiguration constructor as shown in the code below:

I got this IP by executing (nslookup messenger.live.com) in Dos Command Prompt then I got an Address which I have used in the 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);

Hope this would help,,,



来源:https://stackoverflow.com/questions/11308734/handle-see-other-host-in-smack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!