Search in sources :

Example 1 with ResourceBindingNotOfferedException

use of org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException in project Smack by igniterealtime.

the class AbstractXMPPConnection method bindResourceAndEstablishSession.

protected Resourcepart bindResourceAndEstablishSession(Resourcepart resource) throws SmackException, InterruptedException, XMPPException {
    // Wait until either:
    // - the servers last features stanza has been parsed
    // - the timeout occurs
    LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
    waitForConditionOrThrowConnectionException(() -> lastFeaturesReceived, "last stream features received from server");
    if (!hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
        // server implementations as per RFC6120 7.2
        throw new ResourceBindingNotOfferedException();
    }
    // Resource binding, see RFC6120 7.
    // Note that we can not use IQReplyFilter here, since the users full JID is not yet
    // available. It will become available right after the resource has been successfully bound.
    Bind bindResource = Bind.newSet(resource);
    StanzaCollector packetCollector = createStanzaCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
    Bind response = packetCollector.nextResultOrThrow();
    // Set the connections user to the result of resource binding. It is important that we don't infer the user
    // from the login() arguments and the configurations service name, as, for example, when SASL External is used,
    // the username is not given to login but taken from the 'external' certificate.
    user = response.getJid();
    xmppServiceDomain = user.asDomainBareJid();
    Session.Feature sessionFeature = getFeature(Session.Feature.class);
    // For more information see http://tools.ietf.org/html/draft-cridland-xmpp-session-01
    if (sessionFeature != null && !sessionFeature.isOptional()) {
        Session session = new Session();
        packetCollector = createStanzaCollectorAndSend(new StanzaIdFilter(session), session);
        packetCollector.nextResultOrThrow();
    }
    return response.getJid().getResourcepart();
}
Also used : Bind(org.jivesoftware.smack.packet.Bind) ResourceBindingNotOfferedException(org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException) StanzaIdFilter(org.jivesoftware.smack.filter.StanzaIdFilter) Session(org.jivesoftware.smack.packet.Session) SSLSession(javax.net.ssl.SSLSession)

Aggregations

SSLSession (javax.net.ssl.SSLSession)1 ResourceBindingNotOfferedException (org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException)1 StanzaIdFilter (org.jivesoftware.smack.filter.StanzaIdFilter)1 Bind (org.jivesoftware.smack.packet.Bind)1 Session (org.jivesoftware.smack.packet.Session)1