Project

General

Profile

how to use strophe.js function attach(jid,sid,rid,callback) to connect tigase service

lin jiafu
Added over 1 year ago

i use jaxmpp3.1.5 jar and login to got sid and rid, then i put the sid and rid to the strophe.js function attach(jid,sid,rid,callback),but it return those code 8(ATTACHED),2(CONNFAIL),6(DISCONNECTED) all the time, any wrong with my way to got the sid and rid? my code is :

import tigase.jaxmpp.core.client.JaxmppCore.LoggedInHandler;

import tigase.jaxmpp.core.client.SessionObject;

import tigase.jaxmpp.core.client.exceptions.JaxmppException;

import tigase.jaxmpp.j2se.ConnectionConfiguration.ConnectionType;

import tigase.jaxmpp.j2se.Jaxmpp;

public class Test4 {

public static void main(String[] args) {

final Jaxmpp jaxmpp = new Jaxmpp();

jaxmpp.getConnectionConfiguration().setConnectionType(ConnectionType.bosh);

    jaxmpp.getConnectionConfiguration().setBoshService("http://192.168.18.45:5280");

    jaxmpp.getConnectionConfiguration().setDomain("hsl.com");

    jaxmpp.getConnectionConfiguration().setPort(5280);

    jaxmpp.getConnectionConfiguration().setUserJID("ljf@hsl.com");

    jaxmpp.getConnectionConfiguration().setUserPassword("ljf");

jaxmpp.getEventBus().addHandler(LoggedInHandler.LoggedInEvent.class, new LoggedInHandler() {

@Override

        public void onLoggedIn(SessionObject sessionObject) {

            System.out.println("SID:" + sessionObject.getProperty("BOSH#SID_KEY"));

            System.out.println("RID:" + sessionObject.getProperty("BOSH#RID_KEY"));

        }

});

try {

        System.out.println("Loging in...");

        jaxmpp.login(true);

} catch (final JaxmppException e) {

      e.printStackTrace();

    }

}

}

if it is wrong ,how to Moving authentication to server-side and Maintaining session between page changes, thanks!


Replies (6)

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 1 year ago

XMPP specification states how XMPP servers should behave and Tigase XMPP Server is following this specification in term of authentication. Due to that XMPP clients are required to authenticate each connection they made, so it is not possible to authenticate and maintain session on a server side as it is done in HTTP servers.

In Jaxmpp we created custom GWTSessionObject class which can be retrieved from Jaxmpp instance using getSessionObject() in GWT application. This class has 2 methods serialize() and restore(String) which can be used to store session credentials and data before page reload and restore them after. This with Stream Management - Resumption feature allows you to maintain session between page refreshes.

I do not know what you want to achieve by moving session from Jaxmpp to Strophe.

Added by lin jiafu over 1 year ago

thanks Andrzej Wójcik,i want to solve the problem like the page desrcibe:https://stackoverflow.com/questions/25412848/can-strophe-be-used-to-make-an-bosh-connection-with-bosh-manager-on-javajvm,would you have any suggestion? i foud this problem confuse many people, and it not solve yet. thanks angain.

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 1 year ago

I see that a solution of one problem is to use prebinding and this is supported by Tigase XMPP Server, see https://projects.tigase.org/projects/tigase-server/wiki/Bosh_(HTTP)_Pre-Binding.

As for reconnection of a stream on a page refresh, it is tricky for BOSH. We have support in our client library and in Tigase.IM web client to handle page refreshes but to do that we are using StreamManagement - Resumption for WebSocket-based connections and SessionStorage to pass credentials/authentication parameters between pages.

Added by lin jiafu over 1 year ago

thanks Andrzej Wójcik, i use that solution,but it retun like this

bosh@hsl.com

pre-bind-bosh-session

<item>

  <var>Script result</var>

  <type>text-multi</type>

  <value>Script finished with no errors but returned no results.</value>

</item>

all the time ,i change the account and try again, it does not return the right result, this is my param:

pre-bind-bosh-session

<item>

  <var>from</var>

  <value>ljf@hsl/resource</value>

</item>

<item>

  <var>hold</var>

  <value>1</value>

</item>

<item>

  <var>wait</var>

  <value>60</value>

</item>

is i lose any config in init.properties

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 1 year ago

This could be the result of an error on the server side. Please check your server log files.

Added by lin jiafu over 1 year ago

Really thanks for your patience.i found an error in the log:

java.lang.NullPointerException

at tigase.server.ConnectionManager.getServiceId(ConnectionManager.java:1253)

at tigase.server.ConnectionManager.getServiceId(ConnectionManager.java:1239)

at tigase.server.ConnectionManager.getXMPPIOService(ConnectionManager.java:1281)

at tigase.server.bosh.BoshConnectionManager.getSeeOtherHostForJID(BoshConnectionManager.java:531)

at tigase.server.bosh.BoshSession.init(BoshSession.java:338)

at tigase.server.bosh.BoshConnectionManager.preBindSession(BoshConnectionManager.java:261)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:230)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)

at tigase.admin.Script21.run(Script21.groovy:89)

at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:344)

at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:41)

at tigase.server.script.Script.runCommand(Script.java:159)

at tigase.server.BasicComponent.processScriptCommand(BasicComponent.java:1053)

at tigase.server.AbstractMessageReceiver$QueueListener.run(AbstractMessageReceiver.java:1559)

how can i solve this exception,i see an article, the address is https://projects.tigase.org/boards/4/topics/6586, but i don't konw how to solve this exception

    (1-6/6)