Project

General

Profile

Register account with Jaxmpp2

Greg Latcovich
Added over 5 years ago

I’m having a problem registering new users with Jaxmpp2/Tigase. I’m essentially having this exact problem: http://www.tigase.org/taxonomy/term/676/0

I have tried the following:

Registering without logging in – Not Connected error.

jaxmpp2.getConnector().start() – 401 auth error

Logging in as an admin user and then registering – 401 auth error on register, not login

I previously used the Smack library to do this and registering without logging in was the solution. Is it possible to connect to Tigase with Jaxmpp2 without actually logging in?

Thanks!


Replies (4)

(1)
Avatar?id=6098&size=32x32

Added by Bartosz Małkowski TigaseTeam over 5 years ago

Creating new account is bit tricky and will be improved in next version.

For now, you have to force IN_BAND_REGISTRATION_MODE.

To register user "johndoe" on XMPP server "xmpp.gov" with password "secretpassword" you have to do:

Jaxmpp jaxmpp = new Jaxmpp();
jaxmpp.getProperties().setUserProperty(InBandRegistrationModule.IN_BAND_REGISTRATION_MODE_KEY, Boolean.TRUE);
jaxmpp.getProperties().setUserProperty(SessionObject.DOMAIN_NAME, "xmpp.gov");

final InBandRegistrationModule reg = jaxmpp.getModule(InBandRegistrationModule.class);

reg.addListener(new Listener<RegistrationEvent>() {

    @Override
    public void handleEvent(RegistrationEvent be) throws JaxmppException {
        if (be.getType() == InBandRegistrationModule.NotSupportedError) {
        } else if (be.getType() == InBandRegistrationModule.ReceivedError) {
        } else if (be.getType() == InBandRegistrationModule.ReceivedTimeout) {
        }
    }
});
reg.addListener(InBandRegistrationModule.ReceivedRequestedFields,
        new Listener<InBandRegistrationModule.RegistrationEvent>() {

            @Override
            public void handleEvent(RegistrationEvent be) throws JaxmppException {
                reg.register("johndoe", "secretpassword", "johndoe@unknown.com", new AsyncCallback() {

                    @Override
                    public void onError(Stanza responseStanza, ErrorCondition error) throws JaxmppException {
                        System.out.println("error");
                    }

                    @Override
                    public void onSuccess(Stanza responseStanza) throws JaxmppException {
                        System.out.println("registered");
                    }

                    @Override
                    public void onTimeout() throws JaxmppException {
                        // TODO Auto-generated method stub

                    }
                });
            }
        });

jaxmpp.login(true);

Sorry for inconvenience.

(1)

Added by Greg Latcovich over 5 years ago

Thank you for the help, that worked! However, there is a full 2 minutes between when "registered" is logged and jaxmpp.login(true) returns. Is there anything I can do to make that return faster?

Avatar?id=6098&size=32x32

Added by Bartosz Małkowski TigaseTeam over 5 years ago

Weird. I will check it.

But, of course, you can use async mode (jaxmpp.login(false);) but you have to keep application running until "registered" or "error".

(1)

Added by Greg Latcovich over 5 years ago

Thanks, again. Using sync mode and disconnecting in the handler worked.

    (1-4/4)