Search in sources :

Example 1 with XMPPErrorException

use of org.jivesoftware.smack.XMPPException.XMPPErrorException 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(recieveRequest);
    setStatus(Status.negotiating_stream);
    FutureTask<InputStream> streamNegotiatorTask = new FutureTask<InputStream>(new Callable<InputStream>() {

        @Override
        public InputStream call() throws Exception {
            return streamNegotiator.createIncomingStream(recieveRequest.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("Error in execution", e);
    } catch (TimeoutException e) {
        throw new SmackException("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 2 with XMPPErrorException

use of org.jivesoftware.smack.XMPPException.XMPPErrorException in project Smack by igniterealtime.

the class ServiceDiscoveryManager method findServicesDiscoverInfo.

/**
     * Find all services under the users service that provide a given feature.
     * 
     * @param feature the feature to search for
     * @param stopOnFirst if true, stop searching after the first service was found
     * @param useCache if true, query a cache first to avoid network I/O
     * @return a possible empty list of services providing the given feature
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException 
     */
public List<DiscoverInfo> findServicesDiscoverInfo(String feature, boolean stopOnFirst, boolean useCache) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<DiscoverInfo> serviceDiscoInfo = null;
    DomainBareJid serviceName = connection().getXMPPServiceDomain();
    if (useCache) {
        serviceDiscoInfo = services.lookup(feature);
        if (serviceDiscoInfo != null) {
            return serviceDiscoInfo;
        }
    }
    serviceDiscoInfo = new LinkedList<>();
    // Send the disco packet to the server itself
    DiscoverInfo info;
    try {
        info = discoverInfo(serviceName);
    } catch (XMPPErrorException e) {
        // Be extra robust here: Return the empty linked list and log this situation
        LOGGER.log(Level.WARNING, "Could not discover information about service", e);
        return serviceDiscoInfo;
    }
    // Check if the server supports the feature
    if (info.containsFeature(feature)) {
        serviceDiscoInfo.add(info);
        if (stopOnFirst) {
            if (useCache) {
                // Cache the discovered information
                services.put(feature, serviceDiscoInfo);
            }
            return serviceDiscoInfo;
        }
    }
    DiscoverItems items;
    try {
        // Get the disco items and send the disco packet to each server item
        items = discoverItems(serviceName);
    } catch (XMPPErrorException e) {
        LOGGER.log(Level.WARNING, "Could not discover items about service", e);
        return serviceDiscoInfo;
    }
    for (DiscoverItems.Item item : items.getItems()) {
        try {
            // TODO is it OK here in all cases to query without the node attribute?
            // MultipleRecipientManager queried initially also with the node attribute, but this
            // could be simply a fault instead of intentional.
            info = discoverInfo(item.getEntityID());
        } catch (XMPPErrorException | NoResponseException e) {
            // Don't throw this exceptions if one of the server's items fail
            LOGGER.log(Level.WARNING, "Exception while discovering info for feature " + feature + " of " + item.getEntityID() + " node: " + item.getNode(), e);
            continue;
        }
        if (info.containsFeature(feature)) {
            serviceDiscoInfo.add(info);
            //serviceAddresses.add(item.getEntityID().asDomainBareJid());
            if (stopOnFirst) {
                break;
            }
        }
    }
    if (useCache) {
        // Cache the discovered information
        services.put(feature, serviceDiscoInfo);
    }
    return serviceDiscoInfo;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 3 with XMPPErrorException

use of org.jivesoftware.smack.XMPPException.XMPPErrorException 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 4 with XMPPErrorException

use of org.jivesoftware.smack.XMPPException.XMPPErrorException 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
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws InterruptedException
     * @throws NotAMucServiceException 
     * @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();
    if (!KNOWN_MUC_SERVICES.containsKey(mucService)) {
        if (multiUserChatManager.providesMucService(mucService)) {
            KNOWN_MUC_SERVICES.put(mucService, null);
        } else {
            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.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
    connection.addSyncStanzaListener(presenceListener, new AndFilter(fromRoomFilter, StanzaTypeFilter.PRESENCE));
    connection.addSyncStanzaListener(subjectListener, new AndFilter(fromRoomFilter, MessageWithSubjectFilter.INSTANCE, new NotFilter(MessageTypeFilter.ERROR)));
    connection.addSyncStanzaListener(declinesListener, DECLINE_FILTER);
    connection.addPacketInterceptor(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
    Presence presence;
    try {
        presence = connection.createStanzaCollectorAndSend(responseFilter, joinPresence).nextResultOrThrow(conf.getTimeout());
    } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
        // Ensure that all callbacks are removed if there is an exception
        removeConnectionCallbacks();
        throw e;
    }
    // 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
    this.nickname = presence.getFrom().asEntityFullJidIfPossible().getResourcepart();
    joined = true;
    // Update the list of joined rooms
    multiUserChatManager.addJoinedRoom(room);
    return presence;
}
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) 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) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 5 with XMPPErrorException

use of org.jivesoftware.smack.XMPPException.XMPPErrorException in project Smack by igniterealtime.

the class MultiUserChatLight method create.

/**
     * Create new MUCLight.
     * 
     * @param roomName
     * @param subject
     * @param customConfigs
     * @param occupants
     * @throws Exception
     */
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.createStanzaCollectorAndSend(createMUCLightIQ).nextResultOrThrow();
    } 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)

Aggregations

XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)27 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)10 IQ (org.jivesoftware.smack.packet.IQ)9 Test (org.junit.Test)9 IOException (java.io.IOException)7 SmackException (org.jivesoftware.smack.SmackException)7 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)7 Stanza (org.jivesoftware.smack.packet.Stanza)6 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)6 XMPPError (org.jivesoftware.smack.packet.XMPPError)5 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)5 InputStream (java.io.InputStream)4 XMPPException (org.jivesoftware.smack.XMPPException)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)3 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 TimeoutException (java.util.concurrent.TimeoutException)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)2