org.jivesoftware.smack.SmackException.NotLoggedInException Java Examples

The following examples show how to use org.jivesoftware.smack.SmackException.NotLoggedInException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractXMPPConnection.java    From Smack with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
@Override
public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
    final StanzaListener packetListener = new StanzaListener() {
        @Override
        public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException {
            try {
                callback.processStanza(packet);
            } finally {
                removeSyncStanzaListener(this);
            }
        }
    };
    addSyncStanzaListener(packetListener, packetFilter);
    schedule(new Runnable() {
        @Override
        public void run() {
            removeSyncStanzaListener(packetListener);
        }
    }, getReplyTimeout(), TimeUnit.MILLISECONDS);
}
 
Example #2
Source File: BoBManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Request BoB data.
 *
 * @param to TODO javadoc me please
 * @param bobHash TODO javadoc me please
 * @return the BoB data
 * @throws NotLoggedInException if the XMPP connection is not authenticated.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public BoBData requestBoB(Jid to, BoBHash bobHash) throws NotLoggedInException, NoResponseException,
        XMPPErrorException, NotConnectedException, InterruptedException {
    BoBData bobData = BOB_CACHE.lookup(bobHash);
    if (bobData != null) {
        return bobData;
    }

    BoBIQ requestBoBIQ = new BoBIQ(bobHash);
    requestBoBIQ.setType(Type.get);
    requestBoBIQ.setTo(to);

    XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    BoBIQ responseBoBIQ = connection.createStanzaCollectorAndSend(requestBoBIQ).nextResultOrThrow();

    bobData = responseBoBIQ.getBoBData();
    BOB_CACHE.put(bobHash, bobData);

    return bobData;
}
 
Example #3
Source File: DataListener.java    From Smack with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: MamManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
private MamQueryPage queryArchivePage(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException,
                NotConnectedException, InterruptedException, NotLoggedInException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    MamFinIQ mamFinIQ;

    StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection));

    StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration()
            .setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector);

    StanzaCollector cancelledResultCollector;
    try (StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration)) {
        connection.sendStanza(mamQueryIq);
        mamFinIQ = mamFinIQCollector.nextResultOrThrow();
        cancelledResultCollector = resultCollector;
    }

    return new MamQueryPage(cancelledResultCollector, mamFinIQ);
}
 
Example #5
Source File: RosterUtil.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Pre-approve the subscription if it is required and possible.
 *
 * @param roster The roster which should be used for the pre-approval.
 * @param jid The XMPP address which should be pre-approved.
 * @throws NotLoggedInException if the XMPP connection is not authenticated.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @since 4.2.2
 */
public static void preApproveSubscriptionIfRequiredAndPossible(Roster roster, BareJid jid)
        throws NotLoggedInException, NotConnectedException, InterruptedException {
    if (!roster.isSubscriptionPreApprovalSupported()) {
        return;
    }

    RosterEntry entry = roster.getEntry(jid);
    if (entry == null || (!entry.canSeeMyPresence() && !entry.isApproved())) {
        try {
            roster.preApprove(jid);
        } catch (FeatureNotSupportedException e) {
            // Should never happen since we checked for the feature above.
            throw new AssertionError(e);
        }
    }
}
 
Example #6
Source File: Roster.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is a synchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPErrorException if an XMPP error occurs.
 * @throws NotLoggedInException if not logged in.
 * @throws NoResponseException SmackException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void removeEntry(RosterEntry entry) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();

    // Only remove the entry if it's in the entry list.
    // The actual removal logic takes place in RosterPacketListenerProcess>>Packet(Packet)
    if (!entries.containsKey(entry.getJid())) {
        return;
    }
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.set);
    RosterPacket.Item item = RosterEntry.toRosterItem(entry);
    // Set the item type as REMOVE so that the server will delete the entry
    item.setItemType(RosterPacket.ItemType.remove);
    packet.addRosterItem(item);
    connection.createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
 
Example #7
Source File: RosterUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static void askForSubscriptionIfRequired(Roster roster, BareJid jid)
        throws NotLoggedInException, NotConnectedException, InterruptedException {
    RosterEntry entry = roster.getEntry(jid);
    if (entry == null || !(entry.canSeeHisPresence() || entry.isSubscriptionPending())) {
        roster.sendSubscriptionRequest(jid);
    }
}
 
Example #8
Source File: Manager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Get the XMPPConnection of this Manager if it's authenticated, i.e. logged in. Otherwise throw a {@link NotLoggedInException}.
 *
 * @return the XMPPConnection of this Manager.
 * @throws NotLoggedInException if the connection is not authenticated.
 */
protected final XMPPConnection getAuthenticatedConnectionOrThrow() throws NotLoggedInException {
    XMPPConnection connection = connection();
    if (!connection.isAuthenticated()) {
        throw new NotLoggedInException();
    }
    return connection;
}
 
Example #9
Source File: Roster.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
            if (exception instanceof NotConnectedException) {
                logLevel = Level.FINE;
            } else {
                logLevel = Level.SEVERE;
            }
            LOGGER.log(logLevel, "Exception reloading roster", exception);
            for (RosterLoadedListener listener : rosterLoadedListeners) {
                listener.onRosterLoadingFailed(exception);
            }
        }

    });
}
 
Example #10
Source File: Roster.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Set the roster store, may cause a roster reload.
 *
 * @param rosterStore TODO javadoc me please
 * @return true if the roster reload was initiated, false otherwise.
 * @since 4.1
 */
public boolean setRosterStore(RosterStore rosterStore) {
    this.rosterStore = rosterStore;
    try {
        reload();
    }
    catch (InterruptedException | NotLoggedInException | NotConnectedException e) {
        LOGGER.log(Level.FINER, "Could not reload roster", e);
        return false;
    }
    return true;
}
 
Example #11
Source File: Roster.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Pre-approve user presence subscription.
 *
 * @param user the user. (e.g. [email protected])
 * @throws NotLoggedInException if not logged in.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws FeatureNotSupportedException if pre-approving is not supported.
 * @since 4.2
 */
public void preApprove(BareJid user) throws NotLoggedInException, NotConnectedException, InterruptedException, FeatureNotSupportedException {
    final XMPPConnection connection = connection();
    if (!isSubscriptionPreApprovalSupported()) {
        throw new FeatureNotSupportedException("Pre-approving");
    }

    Presence presencePacket = connection.getStanzaFactory().buildPresenceStanza()
        .ofType(Presence.Type.subscribed)
        .to(user)
        .build();
    connection.sendStanza(presencePacket);
}
 
Example #12
Source File: Roster.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void sendSubscriptionRequest(BareJid jid) throws NotLoggedInException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();

    // Create a presence subscription packet and send.
    Presence presencePacket = connection.getStanzaFactory().buildPresenceStanza()
            .ofType(Presence.Type.subscribe)
            .to(jid)
            .build();
    connection.sendStanza(presencePacket);
}
 
Example #13
Source File: MamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public MamQuery queryArchive(MamQueryArgs mamQueryArgs) throws NoResponseException, XMPPErrorException,
                NotConnectedException, NotLoggedInException, InterruptedException {
    String queryId = StringUtils.secureUniqueRandomString();
    String node = mamQueryArgs.node;
    DataForm dataForm = mamQueryArgs.getDataForm();

    MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, node, dataForm);
    mamQueryIQ.setType(IQ.Type.set);
    mamQueryIQ.setTo(archiveAddress);

    mamQueryArgs.maybeAddRsmSet(mamQueryIQ);

    return queryArchive(mamQueryIQ);
}
 
Example #14
Source File: RosterUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static void ensureSubscribedTo(final XMPPConnection connectionOne, final XMPPConnection connectionTwo,
                final Date deadline)
                throws NotLoggedInException, NotConnectedException, InterruptedException, TimeoutException {
    final Roster rosterOne = Roster.getInstanceFor(connectionOne);
    final BareJid jidTwo = connectionTwo.getUser().asBareJid();

    if (rosterOne.iAmSubscribedTo(jidTwo))
        return;

    final BareJid jidOne = connectionOne.getUser().asBareJid();
    final SubscribeListener subscribeListener = new SubscribeListener() {
        @Override
        public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
            if (from.equals(jidOne)) {
                return SubscribeAnswer.Approve;
            }
            return null;
        }
    };
    final Roster rosterTwo = Roster.getInstanceFor(connectionTwo);

    rosterTwo.addSubscribeListener(subscribeListener);
    try {
        rosterOne.sendSubscriptionRequest(jidTwo);
        waitUntilOtherEntityIsSubscribed(rosterTwo, jidOne, deadline);
    }
    finally {
        rosterTwo.removeSubscribeListener(subscribeListener);
    }
}
 
Example #15
Source File: UserTuneManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static synchronized UserTuneManager getInstanceFor(XMPPConnection connection) throws NotLoggedInException {
    UserTuneManager manager = INSTANCES.get(connection);
    if (manager == null) {
        manager = new UserTuneManager(connection);
        INSTANCES.put(connection, manager);
    }
    return manager;
}
 
Example #16
Source File: MamIntegrationTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
public MamIntegrationTest(SmackIntegrationTestEnvironment environment) throws NoResponseException,
        XMPPErrorException, NotConnectedException, InterruptedException, TestNotPossibleException, NotLoggedInException {
    super(environment);

    mamManagerConTwo = MamManager.getInstanceFor(conTwo);

    if (!mamManagerConTwo.isSupported()) {
        throw new TestNotPossibleException("Message Archive Management (XEP-0313) is not supported by the server.");
    }

    // Make sure MAM is archiving messages.
    mamManagerConTwo.enableMamForAllMessages();
}
 
Example #17
Source File: IntegrationTestRosterUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static void notInRoster(XMPPConnection c1, XMPPConnection c2) throws NotLoggedInException,
        NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Roster roster = Roster.getInstanceFor(c1);
    RosterEntry c2Entry = roster.getEntry(c2.getUser().asBareJid());
    if (c2Entry == null) {
        return;
    }
    roster.removeEntry(c2Entry);
}
 
Example #18
Source File: Friend.java    From League-of-Legends-XMPP-Chat-Library with MIT License 5 votes vote down vote up
/**
 * Deletes this friend.
 * 
 * @return true if succesful, otherwise false
 */
public boolean delete() {
	try {
		con.getRoster().removeEntry(get());
		return true;
	} catch (XMPPException | NotLoggedInException | NoResponseException
			| NotConnectedException e) {
		e.printStackTrace();
	}
	return false;
}
 
Example #19
Source File: MamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public MamQuery queryMostRecentPage(Jid jid, int max) throws NoResponseException, XMPPErrorException,
                NotConnectedException, NotLoggedInException, InterruptedException {
    MamQueryArgs mamQueryArgs = MamQueryArgs.builder()
                    // Produces an empty <before/> element for XEP-0059 ยง 2.5
                    .queryLastPage()
                    .limitResultsToJid(jid)
                    .setResultPageSize(max)
                    .build();
    return queryArchive(mamQueryArgs);
}
 
Example #20
Source File: MamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Get the form fields supported by the server.
 *
 * @param node The PubSub node name, can be null
 * @return the list of form fields.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NotLoggedInException if the XMPP connection is not authenticated.
 */
public List<FormField> retrieveFormFields(String node)
                throws NoResponseException, XMPPErrorException, NotConnectedException,
        InterruptedException, NotLoggedInException {
    String queryId = StringUtils.secureUniqueRandomString();
    MamQueryIQ mamQueryIq = new MamQueryIQ(queryId, node, null);
    mamQueryIq.setTo(archiveAddress);

    MamQueryIQ mamResponseQueryIq = connection().createStanzaCollectorAndSend(mamQueryIq).nextResultOrThrow();

    return mamResponseQueryIq.getDataForm().getFields();
}
 
Example #21
Source File: MamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Lookup the archive's message ID of the latest message in the archive. Returns {@code null} if the archive is
 * empty.
 *
 * @return the ID of the lastest message or {@code null}.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws NotLoggedInException if the XMPP connection is not authenticated.
 * @throws InterruptedException if the calling thread was interrupted.
 * @since 4.3.0
 */
public String getMessageUidOfLatestMessage() throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException {
    MamQueryArgs mamQueryArgs = MamQueryArgs.builder()
            .setResultPageSize(1)
            .queryLastPage()
            .build();

    MamQuery mamQuery = queryArchive(mamQueryArgs);
    if (mamQuery.getMessages().isEmpty()) {
        return null;
    }

    return mamQuery.getMamResultExtensions().get(0).getId();
}
 
Example #22
Source File: MamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private List<Message> page(RSMSet requestRsmSet) throws NoResponseException, XMPPErrorException,
                NotConnectedException, NotLoggedInException, InterruptedException {
    String queryId = StringUtils.secureUniqueRandomString();
    MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, node, form);
    mamQueryIQ.setType(IQ.Type.set);
    mamQueryIQ.setTo(archiveAddress);
    mamQueryIQ.addExtension(requestRsmSet);

    mamQueryPage = queryArchivePage(mamQueryIQ);

    return mamQueryPage.messages;
}
 
Example #23
Source File: MamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private MamPrefsResult queryMamPrefs(MamPrefsIQ mamPrefsIQ) throws NoResponseException, XMPPErrorException,
        NotConnectedException, InterruptedException, NotLoggedInException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();

    MamPrefsIQ mamPrefsResultIQ = connection.createStanzaCollectorAndSend(mamPrefsIQ).nextResultOrThrow();

    return new MamPrefsResult(mamPrefsResultIQ, DataForm.from(mamPrefsIQ));
}
 
Example #24
Source File: RosterUtil.java    From Smack with Apache License 2.0 4 votes vote down vote up
public static void ensureSubscribed(XMPPConnection connectionOne, XMPPConnection connectionTwo, long timeout)
                throws NotLoggedInException, NotConnectedException, InterruptedException, TimeoutException {
    ensureSubscribedTo(connectionOne, connectionTwo, timeout);
    ensureSubscribedTo(connectionTwo, connectionOne, timeout);
}
 
Example #25
Source File: IntegrationTestRosterUtil.java    From Smack with Apache License 2.0 4 votes vote down vote up
public static void ensureBothAccountsAreNotInEachOthersRoster(XMPPConnection conOne, XMPPConnection conTwo)
        throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException,
        InterruptedException {
    notInRoster(conOne, conTwo);
    notInRoster(conTwo, conOne);
}
 
Example #26
Source File: UserTuneIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@AfterClass
public void unsubscribe()
        throws SmackException.NotLoggedInException, XMPPException.XMPPErrorException,
        SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
    IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
}
 
Example #27
Source File: UserTuneIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
public UserTuneIntegrationTest(SmackIntegrationTestEnvironment environment) throws NotLoggedInException {
    super(environment);
    utm1 = UserTuneManager.getInstanceFor(conOne);
    utm2 = UserTuneManager.getInstanceFor(conTwo);
}
 
Example #28
Source File: EntityCapsTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void setUp() throws NotLoggedInException, NotConnectedException, InterruptedException, TimeoutException {
    RosterUtil.ensureSubscribed(conOne, conTwo, timeout);
}
 
Example #29
Source File: GeolocationIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@AfterClass
public void unsubscribe() throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
}
 
Example #30
Source File: UserTuneManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
public void publishUserTune(UserTuneElement userTuneElement) throws NotLoggedInException, NotALeafNodeException, NoResponseException, NotConnectedException, XMPPErrorException, InterruptedException {
    // TODO: To prevent a large number of updates when a user is skipping through tracks, an implementation SHOULD wait several seconds before publishing new tune information.
    pepManager.publish(USERTUNE_NODE, new PayloadItem<>(userTuneElement));
}