Search in sources :

Example 1 with NotLoggedInException

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

the class DataListener method handleIQRequest.

@Override
public IQ handleIQRequest(IQ iqRequest) {
    Data data = (Data) iqRequest;
    InBandBytestreamSession ibbSession = this.manager.getSessions().get(data.getDataPacketExtension().getSessionID());
    try {
        if (ibbSession == null) {
            this.manager.replyItemNotFoundPacket(data);
        } else {
            ibbSession.processIQPacket(data);
        }
    } catch (NotConnectedException | InterruptedException | NotLoggedInException e) {
        return null;
    }
    return null;
}
Also used : NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException)

Example 2 with NotLoggedInException

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

the class Roster method reload.

/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * @throws NotLoggedInException If not logged in.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void reload() throws NotLoggedInException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    RosterPacket packet = new RosterPacket();
    if (rosterStore != null && isRosterVersioningSupported()) {
        packet.setVersion(rosterStore.getRosterVersion());
    }
    rosterState = RosterState.loading;
    SmackFuture<IQ, Exception> future = connection.sendIqRequestAsync(packet);
    future.onSuccess(new RosterResultListener()).onError(new ExceptionCallback<Exception>() {

        @Override
        public void processException(Exception exception) {
            rosterState = RosterState.uninitialized;
            Level logLevel = Level.SEVERE;
            if (exception instanceof NotConnectedException) {
                logLevel = Level.FINE;
            } else if (exception instanceof XMPPErrorException) {
                Condition condition = ((XMPPErrorException) exception).getStanzaError().getCondition();
                if (condition == Condition.feature_not_implemented || condition == Condition.service_unavailable) {
                    logLevel = Level.FINE;
                }
            }
            LOGGER.log(logLevel, "Exception reloading roster", exception);
            for (RosterLoadedListener listener : rosterLoadedListeners) {
                listener.onRosterLoadingFailed(exception);
            }
        }
    });
}
Also used : Condition(org.jivesoftware.smack.packet.StanzaError.Condition) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) IQ(org.jivesoftware.smack.packet.IQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection) SmackException(org.jivesoftware.smack.SmackException) FeatureNotSupportedException(org.jivesoftware.smack.SmackException.FeatureNotSupportedException) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) Level(java.util.logging.Level)

Example 3 with NotLoggedInException

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

the class XMPPTCPConnection method loginInternal.

@Override
protected synchronized void loginInternal(String username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException {
    // Authenticate using SASL
    SSLSession sslSession = secureSocket != null ? secureSocket.getSession() : null;
    streamFeaturesAfterAuthenticationReceived = false;
    authenticate(username, password, config.getAuthzid(), sslSession);
    // Wait for stream features after the authentication.
    // TODO: The name of this synchronization point "maybeCompressFeaturesReceived" is not perfect. It should be
    // renamed to "streamFeaturesAfterAuthenticationReceived".
    waitForConditionOrThrowConnectionException(() -> streamFeaturesAfterAuthenticationReceived, "compress features from server");
    // If compression is enabled then request the server to use stream compression. XEP-170
    // recommends to perform stream compression before resource binding.
    maybeEnableCompression();
    smResumedSyncPoint = SyncPointState.initial;
    smResumptionFailed = null;
    if (isSmResumptionPossible()) {
        smResumedSyncPoint = SyncPointState.request_sent;
        sendNonza(new Resume(clientHandledStanzasCount, smSessionId));
        waitForConditionOrConnectionException(() -> smResumedSyncPoint == SyncPointState.successful || smResumptionFailed != null, "resume previous stream");
        if (smResumedSyncPoint == SyncPointState.successful) {
            // We successfully resumed the stream, be done here
            afterSuccessfulLogin(true);
            return;
        }
        // normal resource binding can be tried.
        assert smResumptionFailed != null;
        LOGGER.fine("Stream resumption failed, continuing with normal stream establishment process: " + smResumptionFailed);
    }
    // We either failed to resume a previous stream management (SM) session, or we did not even try. In any case,
    // mark SM as not enabled. Most importantly, we do this prior calling bindResourceAndEstablishSession(), as the
    // bind IQ may trigger a SM ack request, which would be invalid in the pre resource bound state.
    smEnabledSyncPoint = false;
    List<Stanza> previouslyUnackedStanzas = new LinkedList<Stanza>();
    if (unacknowledgedStanzas != null) {
        // There was a previous connection with SM enabled but that was either not resumable or
        // failed to resume. Make sure that we (re-)send the unacknowledged stanzas.
        unacknowledgedStanzas.drainTo(previouslyUnackedStanzas);
        // Reset unacknowledged stanzas to 'null' to signal that we never send 'enable' in this
        // XMPP session (There maybe was an enabled in a previous XMPP session of this
        // connection instance though). This is used in writePackets to decide if stanzas should
        // be added to the unacknowledged stanzas queue, because they have to be added right
        // after the 'enable' stream element has been sent.
        dropSmState();
    }
    // Now bind the resource. It is important to do this *after* we dropped an eventually
    // existing Stream Management state. As otherwise <bind/> and <session/> may end up in
    // unacknowledgedStanzas and become duplicated on reconnect. See SMACK-706.
    bindResourceAndEstablishSession(resource);
    if (isSmAvailable() && useSm) {
        // Remove what is maybe left from previously stream managed sessions
        serverHandledStanzasCount = 0;
        sendNonza(new Enable(useSmResumption, smClientMaxResumptionTime));
        // XEP-198 3. Enabling Stream Management. If the server response to 'Enable' is 'Failed'
        // then this is a non recoverable error and we therefore throw an exception.
        waitForConditionOrThrowConnectionException(() -> smEnabledSyncPoint, "enabling stream mangement");
        synchronized (requestAckPredicates) {
            if (requestAckPredicates.isEmpty()) {
                // Assure that we have at lest one predicate set up that so that we request acks
                // for the server and eventually flush some stanzas from the unacknowledged
                // stanza queue
                requestAckPredicates.add(Predicate.forMessagesOrAfter5Stanzas());
            }
        }
    }
    // before it is informed about connection success
    if (!stanzaDroppedListeners.isEmpty()) {
        for (Stanza stanza : previouslyUnackedStanzas) {
            for (StanzaListener listener : stanzaDroppedListeners) {
                try {
                    listener.processStanza(stanza);
                } catch (InterruptedException | NotConnectedException | NotLoggedInException e) {
                    LOGGER.log(Level.FINER, "StanzaDroppedListener received exception", e);
                }
            }
        }
    } else {
        for (Stanza stanza : previouslyUnackedStanzas) {
            sendStanzaInternal(stanza);
        }
    }
    afterSuccessfulLogin(false);
}
Also used : NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Stanza(org.jivesoftware.smack.packet.Stanza) SSLSession(javax.net.ssl.SSLSession) Enable(org.jivesoftware.smack.sm.packet.StreamManagement.Enable) StanzaListener(org.jivesoftware.smack.StanzaListener) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) LinkedList(java.util.LinkedList) Resume(org.jivesoftware.smack.sm.packet.StreamManagement.Resume)

Aggregations

NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)3 NotLoggedInException (org.jivesoftware.smack.SmackException.NotLoggedInException)3 LinkedList (java.util.LinkedList)1 Level (java.util.logging.Level)1 SSLSession (javax.net.ssl.SSLSession)1 SmackException (org.jivesoftware.smack.SmackException)1 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)1 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 StanzaListener (org.jivesoftware.smack.StanzaListener)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 IQ (org.jivesoftware.smack.packet.IQ)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 Condition (org.jivesoftware.smack.packet.StanzaError.Condition)1 RosterPacket (org.jivesoftware.smack.roster.packet.RosterPacket)1 Enable (org.jivesoftware.smack.sm.packet.StreamManagement.Enable)1 Resume (org.jivesoftware.smack.sm.packet.StreamManagement.Resume)1 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)1