Search in sources :

Example 6 with NoResponseException

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

the class MultiUserChatLight method create.

/**
 * Create new MUCLight.
 *
 * @param roomName TODO javadoc me please
 * @param subject TODO javadoc me please
 * @param customConfigs TODO javadoc me please
 * @param occupants TODO javadoc me please
 * @throws Exception TODO javadoc me please
 */
public void create(String roomName, String subject, HashMap<String, String> customConfigs, List<Jid> occupants) throws Exception {
    MUCLightCreateIQ createMUCLightIQ = new MUCLightCreateIQ(room, roomName, occupants);
    messageCollector = connection.createStanzaCollector(fromRoomGroupChatFilter);
    try {
        connection.sendIqRequestAndWaitForResponse(createMUCLightIQ);
    } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
        removeConnectionCallbacks();
        throw e;
    }
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) MUCLightCreateIQ(org.jivesoftware.smackx.muclight.element.MUCLightCreateIQ)

Example 7 with NoResponseException

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

the class IncomingFileTransfer method negotiateStream.

private InputStream negotiateStream() throws SmackException, XMPPErrorException, InterruptedException {
    setStatus(Status.negotiating_transfer);
    final StreamNegotiator streamNegotiator = negotiator.selectStreamNegotiator(receiveRequest);
    setStatus(Status.negotiating_stream);
    FutureTask<InputStream> streamNegotiatorTask = new FutureTask<>(new Callable<InputStream>() {

        @Override
        public InputStream call() throws Exception {
            return streamNegotiator.createIncomingStream(receiveRequest.getStreamInitiation());
        }
    });
    streamNegotiatorTask.run();
    InputStream inputStream;
    try {
        inputStream = streamNegotiatorTask.get(15, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof XMPPErrorException) {
            throw (XMPPErrorException) cause;
        }
        if (cause instanceof InterruptedException) {
            throw (InterruptedException) cause;
        }
        if (cause instanceof NoResponseException) {
            throw (NoResponseException) cause;
        }
        if (cause instanceof SmackException) {
            throw (SmackException) cause;
        }
        throw new SmackException.SmackWrappedException("Error in execution", e);
    } catch (TimeoutException e) {
        throw new SmackException.SmackWrappedException("Request timed out", e);
    } finally {
        streamNegotiatorTask.cancel(true);
    }
    setStatus(Status.negotiated);
    return inputStream;
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) InputStream(java.io.InputStream) SmackException(org.jivesoftware.smack.SmackException) SmackException(org.jivesoftware.smack.SmackException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) FutureTask(java.util.concurrent.FutureTask) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with NoResponseException

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

the class MultiUserChat method enter.

/**
 * Enter a room, as described in XEP-45 7.2.
 *
 * @param conf the configuration used to enter the room.
 * @return the returned presence by the service after the client send the initial presence in order to enter the room.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NotAMucServiceException if the entity is not a MUC serivce.
 * @see <a href="http://xmpp.org/extensions/xep-0045.html#enter">XEP-45 7.2 Entering a Room</a>
 */
private Presence enter(MucEnterConfiguration conf) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException, NotAMucServiceException {
    final DomainBareJid mucService = room.asDomainBareJid();
    mucServiceDiscoInfo = multiUserChatManager.getMucServiceDiscoInfo(mucService);
    if (mucServiceDiscoInfo == null) {
        throw new NotAMucServiceException(this);
    }
    // We enter a room by sending a presence packet where the "to"
    // field is in the form "roomName@service/nickname"
    Presence joinPresence = conf.getJoinPresence(this);
    // Setup the messageListeners and presenceListeners *before* the join presence is send.
    connection.addStanzaListener(messageListener, fromRoomGroupchatFilter);
    StanzaFilter presenceFromRoomFilter = new AndFilter(fromRoomFilter, StanzaTypeFilter.PRESENCE, PossibleFromTypeFilter.ENTITY_FULL_JID);
    connection.addStanzaListener(presenceListener, presenceFromRoomFilter);
    // @formatter:off
    connection.addStanzaListener(subjectListener, new AndFilter(fromRoomFilter, MessageWithSubjectFilter.INSTANCE, new NotFilter(MessageTypeFilter.ERROR), // legitimate message, but it SHALL NOT be interpreted as a subject change."
    new NotFilter(MessageWithBodiesFilter.INSTANCE), new NotFilter(MessageWithThreadFilter.INSTANCE)));
    // @formatter:on
    connection.addStanzaListener(declinesListener, new AndFilter(fromRoomFilter, DECLINE_FILTER));
    connection.addStanzaSendingListener(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room), StanzaTypeFilter.PRESENCE));
    messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
    // Wait for a presence packet back from the server.
    // @formatter:off
    StanzaFilter responseFilter = new AndFilter(StanzaTypeFilter.PRESENCE, new OrFilter(// We use a bare JID filter for positive responses, since the MUC service/room may rewrite the nickname.
    new AndFilter(FromMatchesFilter.createBare(getRoom()), MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF), // JID we send the join presence to.
    new AndFilter(FromMatchesFilter.createFull(joinPresence.getTo()), new StanzaIdFilter(joinPresence), PresenceTypeFilter.ERROR)));
    // @formatter:on
    processedReflectedSelfPresence = false;
    StanzaCollector presenceStanzaCollector = null;
    final Presence reflectedSelfPresence;
    try {
        // This stanza collector will collect the final self presence from the MUC, which also signals that we have successful entered the MUC.
        StanzaCollector selfPresenceCollector = connection.createStanzaCollectorAndSend(responseFilter, joinPresence);
        StanzaCollector.Configuration presenceStanzaCollectorConfguration = StanzaCollector.newConfiguration().setCollectorToReset(selfPresenceCollector).setStanzaFilter(presenceFromRoomFilter);
        // This stanza collector is used to reset the timeout of the selfPresenceCollector.
        presenceStanzaCollector = connection.createStanzaCollector(presenceStanzaCollectorConfguration);
        reflectedSelfPresence = selfPresenceCollector.nextResultOrThrow(conf.getTimeout());
    } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
        // Ensure that all callbacks are removed if there is an exception
        removeConnectionCallbacks();
        throw e;
    } finally {
        if (presenceStanzaCollector != null) {
            presenceStanzaCollector.cancel();
        }
    }
    synchronized (presenceListener) {
        // processing is done.
        while (!processedReflectedSelfPresence) {
            presenceListener.wait();
        }
    }
    // This presence must be send from a full JID. We use the resourcepart of this JID as nick, since the room may
    // performed roomnick rewriting
    Resourcepart receivedNickname = reflectedSelfPresence.getFrom().getResourceOrThrow();
    setNickname(receivedNickname);
    // Update the list of joined rooms
    multiUserChatManager.addJoinedRoom(room);
    return reflectedSelfPresence;
}
Also used : StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) OrFilter(org.jivesoftware.smack.filter.OrFilter) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaIdFilter(org.jivesoftware.smack.filter.StanzaIdFilter) NotFilter(org.jivesoftware.smack.filter.NotFilter) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) StanzaCollector(org.jivesoftware.smack.StanzaCollector) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 9 with NoResponseException

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

the class MucBookmarkAutojoinManager method autojoinBookmarkedConferences.

public void autojoinBookmarkedConferences() {
    List<BookmarkedConference> bookmarkedConferences;
    try {
        bookmarkedConferences = bookmarkManager.getBookmarkedConferences();
    } catch (NotConnectedException | InterruptedException e) {
        LOGGER.log(Level.FINER, "Could not get MUC bookmarks", e);
        return;
    } catch (NoResponseException | XMPPErrorException e) {
        LOGGER.log(Level.WARNING, "Could not get MUC bookmarks", e);
        return;
    }
    final XMPPConnection connection = connection();
    Resourcepart defaultNick = connection.getUser().getResourcepart();
    for (BookmarkedConference bookmarkedConference : bookmarkedConferences) {
        if (!bookmarkedConference.isAutoJoin()) {
            continue;
        }
        Resourcepart nick = bookmarkedConference.getNickname();
        if (nick == null) {
            nick = defaultNick;
        }
        String password = bookmarkedConference.getPassword();
        MultiUserChat muc = multiUserChatManager.getMultiUserChat(bookmarkedConference.getJid());
        try {
            MucCreateConfigFormHandle handle = muc.createOrJoinIfNecessary(nick, password);
            if (handle != null) {
                handle.makeInstant();
            }
        } catch (NotConnectedException | InterruptedException e) {
            LOGGER.log(Level.FINER, "Could not autojoin bookmarked MUC", e);
            // abort here
            break;
        } catch (NotAMucServiceException | NoResponseException | XMPPErrorException e) {
            // Do no abort, just log,
            LOGGER.log(Level.WARNING, "Could not autojoin bookmarked MUC", e);
        }
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)

Example 10 with NoResponseException

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

the class FileTransferNegotiatorTest method verifyForm.

@Test
public void verifyForm() throws Exception {
    FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
    try {
        fileNeg.negotiateOutgoingTransfer(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, "streamid", "file", 1024, null, 10);
    } catch (NoResponseException e) {
    // We do not expect an answer. This unit test only checks the request sent.
    }
    Stanza packet = connection.getSentPacket();
    String xml = packet.toXML().toString();
    assertTrue(xml.indexOf("var='stream-method' type='list-single'") != -1);
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) Test(org.junit.jupiter.api.Test)

Aggregations

NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)21 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)15 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)14 SmackException (org.jivesoftware.smack.SmackException)7 XMPPException (org.jivesoftware.smack.XMPPException)7 IOException (java.io.IOException)6 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)3 AccountManager (org.jivesoftware.smackx.iqregister.AccountManager)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 InputStream (java.io.InputStream)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 AlreadyConnectedException (org.jivesoftware.smack.SmackException.AlreadyConnectedException)2 AlreadyLoggedInException (org.jivesoftware.smack.SmackException.AlreadyLoggedInException)2 ConnectionException (org.jivesoftware.smack.SmackException.ConnectionException)2