Java - 尝试使用 bosh 预绑定 converse.js 但无法获取 sid 并摆脱...使用 smack bosh [英] Java - trying to prebind converse.js using bosh but not able to get the sid and rid...using the smack bosh

查看:25
本文介绍了Java - 尝试使用 bosh 预绑定 converse.js 但无法获取 sid 并摆脱...使用 smack bosh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 smack bosh 连接到明火,并尝试在网页中预绑定 converse.js.我的密码

BOSHConfiguration config = new BOSHConfiguration(false, "host", 7070, "/http-bind/", "", "xmpp:127.0.0.1:5222");BOSHConnection 连接 = 新 BOSHConnection(config);尝试 {连接.connect();connection.login("un", "pw");字符串 sss = connection.getConnectionID();字符串 bosh = connection.BOSH_URI;} 捕获(异常 e){}

有人可以帮助我如何建立bosh连接并从会话中获取所需的sid、rid和jid....

非常感谢任何帮助.

解决方案

我设法通过在 Smack BOSHConnection 库类中添加以下函数来做到这一点:

public class BOSHConnection extends Connection {...公共字符串 getSid() {返回 client.getSid();}公共长 getRid() {返回 client.getRid();}...}

然后您需要记住 Rid 是 Smack 库使用的最后一个 id,对于您的预绑定,您需要为下一个请求增加它.

Jid 已经可以通过 BOSHConnection.getUser() 获得;

我还应该标记为使用 Smack 进行 converse 预绑定,我还必须更改 BOSHConnection.login 函数.

//更改:保留当前 api - 调用新的预绑定感知函数公共无效登录(字符串用户名,字符串密码,字符串资源)抛出 XMPPException {登录(用户名,密码,资源,假);}//添加:使用具有预绑定感知的原始登录功能公共无效登录(字符串用户名,字符串密码,字符串资源,布尔预绑定)抛出 XMPPException {如果 (!isConnected()) {throw new IllegalStateException("未连接到服务器.");}... 不变//表明我们现在已通过身份验证.已认证 = 真;匿名 = 假;//添加:预绑定只需要连接和认证如果(预绑定){返回;}

然后在 Web 应用程序中

//仅使用预绑定登录connection.login(userName, password, "", true);

这是必需的,因为 converse 做的第一件事就是执行登录功能后半部分所做的所有花名册和出席信息.我的理由是,XMPP 服务器实际上会看到两个连接(一个来自 SMACK,一个来自 converse),它是发送状态的连接,最终将成为 XMPP 消息的目标 - 我们希望它是 converse.

更长的代码示例是在另一个 StackOverflow 答案中

I am trying to connect to the open fire using the smack bosh and trying to prebind the converse.js in the web page. My bosh code

BOSHConfiguration config = new BOSHConfiguration(false, "host", 7070, "/http-bind/", "<host>", "xmpp:127.0.0.1:5222");
BOSHConnection connection = new BOSHConnection(config);
try {
connection.connect();
connection.login("un", "pw");
String sss = connection.getConnectionID();
String bosh = connection.BOSH_URI;
} catch (Exception e) {
}

Can some one help me how to establish a bosh connection and get the required sid, rid and jid from the session....

Any help is much appreciated.

解决方案

I managed to do this by adding the following functions in the Smack BOSHConnection library class:

public class BOSHConnection extends Connection {
    ...
    public String getSid() {
        return client.getSid();
    }

    public Long getRid() {
        return client.getRid();
    }
    ...
}

you then need to remember that the Rid is the last id used by the Smack library and for your pre-bind you need to increment this for next request.

Jid is already available via BOSHConnection.getUser();

I should also flag that to get converse pre-bind working with Smack I also had to change the BOSHConnection.login functon.

// Changed: preserve current api - call new pre-bind aware function
public void login(String username, String password, String resource)
        throws XMPPException {
    login(username, password, resource, false);         

}

// Added: Using original login function with prebind awareness
public void login(String username, String password, String resource, boolean preBind)         
        throws XMPPException {
    if (!isConnected()) {
        throw new IllegalStateException("Not connected to server.");
    }

    ... unchanged

    // Indicate that we're now authenticated.
    authenticated = true;
    anonymous = false;

    // Added: Prebind only requires connect and authenticate
    if (preBind) {
        return;
    }

then in Web app

// login with pre-bind only
connection.login(userName, password, "", true);

This is required as the first thing converse does is perform all the roster and presence stuff that the later half of the login function does. My reasoning here is that the XMPP server will actually see two connections (one from SMACK and one from converse) and it's the one that sends the presence which will end up being target for XMPP messages - and we want that to be converse.

Edit: Longer code sample for this is in this other StackOverflow answer

这篇关于Java - 尝试使用 bosh 预绑定 converse.js 但无法获取 sid 并摆脱...使用 smack bosh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆