org.jivesoftware.smack.SmackException.NotConnectedException Java Examples

The following examples show how to use org.jivesoftware.smack.SmackException.NotConnectedException. 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: InBandBytestreamSession.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * This method is invoked if a request to close the In-Band Bytestream has been received.
 *
 * @param closeRequest the close request from the remote peer
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
protected void closeByPeer(Close closeRequest) throws NotConnectedException, InterruptedException {

    /*
     * close streams without flushing them, because stream is already considered closed on the
     * remote peers side
     */
    this.inputStream.closeInternal();
    this.inputStream.cleanup();
    this.outputStream.closeInternal(false);

    // acknowledge close request
    IQ confirmClose = IQ.createResultIQ(closeRequest);
    this.connection.sendStanza(confirmClose);

}
 
Example #2
Source File: AgentSession.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the AgentChatHistory associated with a particular agent jid.
 *
 * @param jid the jid of the agent.
 * @param maxSessions the max number of sessions to retrieve.
 * @param startDate point in time from which on history should get retrieved.
 * @return the chat history associated with a given jid.
 * @throws XMPPException if an error occurs while retrieving the AgentChatHistory.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public AgentChatHistory getAgentHistory(EntityBareJid jid, int maxSessions, Date startDate) throws XMPPException, NotConnectedException, InterruptedException {
    AgentChatHistory request;
    if (startDate != null) {
        request = new AgentChatHistory(jid, maxSessions, startDate);
    }
    else {
        request = new AgentChatHistory(jid, maxSessions);
    }

    request.setType(IQ.Type.get);
    request.setTo(workgroupJID);

    AgentChatHistory response = connection.createStanzaCollectorAndSend(
                    request).nextResult();

    return response;
}
 
Example #3
Source File: InitiationListener.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public IQ handleIQRequest(final IQ packet) {
    initiationListenerExecutor.execute(new Runnable() {

        @Override
        public void run() {
            try {
                processRequest(packet);
            }
            catch (InterruptedException | NotConnectedException e) {
                LOGGER.log(Level.WARNING, "proccessRequest", e);
            }
        }
    });
    return null;
}
 
Example #4
Source File: RosterEntry.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the name associated with this entry.
 *
 * @param name the name.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public synchronized void setName(String name) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException {
    // Do nothing if the name hasn't changed.
    if (name != null && name.equals(getName())) {
        return;
    }

    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.set);

    // Create a new roster item with the current RosterEntry and the *new* name. Note that we can't set the name of
    // RosterEntry right away, as otherwise the updated event wont get fired, because equalsDeep would return true.
    packet.addRosterItem(toRosterItem(this, name));
    connection().createStanzaCollectorAndSend(packet).nextResultOrThrow();

    // We have received a result response to the IQ set, the name was successfully changed
    item.setName(name);
}
 
Example #5
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 #6
Source File: OfflineMessageManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a List of Messages with all the offline <code>Messages</code> of the user. The returned offline
 * messages will not be deleted from the server. Use {@link #deleteMessages(java.util.List)}
 * to delete the messages.
 *
 * @return a List with all the offline <code>Messages</code> of the user.
 * @throws XMPPErrorException If the user is not allowed to make this request or the server does
 *                       not support offline message retrieval.
 * @throws NoResponseException 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 List<Message> getMessages() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    OfflineMessageRequest request = new OfflineMessageRequest();
    request.setFetch(true);

    StanzaCollector resultCollector = connection().createStanzaCollectorAndSend(request);
    StanzaCollector.Configuration messageCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(PACKET_FILTER).setCollectorToReset(resultCollector);

    List<Message> messages;
    try (StanzaCollector messageCollector = connection().createStanzaCollector(messageCollectorConfiguration)) {
        resultCollector.nextResultOrThrow();
        // Be extra safe, cancel the message collector right here so that it does not collector
        // other messages that eventually match (although I've no idea how this could happen in
        // case of XEP-13).
        messageCollector.cancel();
        messages = new ArrayList<>(messageCollector.getCollectedCount());
        Message message;
        while ((message = messageCollector.pollResult()) != null) {
            messages.add(message);
        }
    }
    return messages;
}
 
Example #7
Source File: MultiUserChat.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the completed configuration form to the server. The room will be configured
 * with the new settings defined in the form.
 *
 * @param form the form with the new settings.
 * @throws XMPPErrorException if an error occurs setting the new rooms' configuration.
 * @throws NoResponseException 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 sendConfigurationForm(FillableForm form) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final DataForm dataForm;
    if (form != null) {
        dataForm = form.getDataFormToSubmit();
    } else {
        // Instant room, cf. XEP-0045 ยง 10.1.2
        dataForm = DataForm.builder().build();
    }

    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    iq.addExtension(dataForm);

    connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
}
 
Example #8
Source File: BookmarkManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 *  Removes a url from the bookmarks.
 *
 * @param bookmarkURL the url of the bookmark to remove
 * @throws XMPPErrorException thrown if there is an error retriving or saving bookmarks from or to
 * the server.
 * @throws NoResponseException 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 removeBookmarkedURL(String bookmarkURL) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    retrieveBookmarks();
    Iterator<BookmarkedURL> it = bookmarks.getBookmarkedURLS().iterator();
    while (it.hasNext()) {
        BookmarkedURL bookmark = it.next();
        if (bookmark.getURL().equalsIgnoreCase(bookmarkURL)) {
            if (bookmark.isShared()) {
                throw new IllegalArgumentException("Cannot delete a shared bookmark.");
            }
            it.remove();
            privateDataManager.setPrivateData(bookmarks);
            return;
        }
    }
}
 
Example #9
Source File: IoTDiscoveryManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
public ThingState registerThing(Jid registry, Thing thing)
                throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, IoTClaimedException {
    final XMPPConnection connection = connection();
    IoTRegister iotRegister = new IoTRegister(thing.getMetaTags(), thing.getNodeInfo(), thing.isSelfOwened());
    iotRegister.setTo(registry);
    IQ result = connection.createStanzaCollectorAndSend(iotRegister).nextResultOrThrow();
    if (result instanceof IoTClaimed) {
        IoTClaimed iotClaimedResult = (IoTClaimed) result;
        throw new IoTClaimedException(iotClaimedResult);
    }

    ThingState state = getStateFor(thing.getNodeInfo());
    state.setRegistry(registry.asBareJid());

    interactWithRegistry(registry);

    IoTDataManager.getInstanceFor(connection).installThing(thing);
    IoTControlManager.getInstanceFor(connection).installThing(thing);

    return state;
}
 
Example #10
Source File: AbstractXMPPConnection.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
                throws NotConnectedException, InterruptedException {
    StanzaCollector.Configuration configuration = StanzaCollector.newConfiguration()
                    .setStanzaFilter(packetFilter)
                    .setRequest(packet);
    // Create the packet collector before sending the packet
    StanzaCollector packetCollector = createStanzaCollector(configuration);
    try {
        // Now we can send the packet as the collector has been created
        sendStanza(packet);
    }
    catch (InterruptedException | NotConnectedException | RuntimeException e) {
        packetCollector.cancel();
        throw e;
    }
    return packetCollector;
}
 
Example #11
Source File: IoTProvisioningManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * As the given provisioning server is the given JID is a friend.
 *
 * @param provisioningServer the provisioning server to ask.
 * @param friendInQuestion the JID to ask about.
 * @return <code>true</code> if the JID is a friend, <code>false</code> otherwise.
 * @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 boolean isFriend(Jid provisioningServer, BareJid friendInQuestion) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    LruCache<BareJid, Void> cache = negativeFriendshipRequestCache.lookup(provisioningServer);
    if (cache != null && cache.containsKey(friendInQuestion)) {
        // We hit a cached negative isFriend response for this provisioning server.
        return false;
    }

    IoTIsFriend iotIsFriend = new IoTIsFriend(friendInQuestion);
    iotIsFriend.setTo(provisioningServer);
    IoTIsFriendResponse response = connection().createStanzaCollectorAndSend(iotIsFriend).nextResultOrThrow();
    assert response.getJid().equals(friendInQuestion);
    boolean isFriend = response.getIsFriendResult();
    if (!isFriend) {
        // Cache the negative is friend response.
        if (cache == null) {
            cache = new LruCache<>(1024);
            negativeFriendshipRequestCache.put(provisioningServer, cache);
        }
        cache.put(friendInQuestion, null);
    }
    return isFriend;
}
 
Example #12
Source File: EntityTimeManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public Time getTime(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (!isTimeSupported(jid))
        return null;

    Time request = new Time();
    // TODO Add Time(Jid) constructor and use this constructor instead
    request.setTo(jid);
    return connection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
 
Example #13
Source File: PrivacyListManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Client declines the use of default lists.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void declineDefaultList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // The request of the list is an privacy message with an empty list
    Privacy request = new Privacy();
    request.setDeclineDefaultList(true);

    // Send the package to the server
    setRequest(request);
}
 
Example #14
Source File: MultiUserChatLightManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private MUCLightBlockingIQ getBlockingList(DomainBareJid mucLightService)
        throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
    MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, null);
    mucLightBlockingIQ.setType(Type.get);
    mucLightBlockingIQ.setTo(mucLightService);

    StanzaFilter responseFilter = new IQReplyFilter(mucLightBlockingIQ, connection());
    IQ responseIq = connection().createStanzaCollectorAndSend(responseFilter, mucLightBlockingIQ)
            .nextResultOrThrow();
    MUCLightBlockingIQ mucLightBlockingIQResult = (MUCLightBlockingIQ) responseIq;

    return mucLightBlockingIQResult;
}
 
Example #15
Source File: IoTProvisioningManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void sendFriendshipRequest(BareJid bareJid) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    Presence presence = connection.getStanzaFactory().buildPresenceStanza()
        .ofType(Presence.Type.subscribe)
        .to(bareJid)
        .build();

    friendshipRequestedCache.put(bareJid, null);

    connection().sendStanza(presence);
}
 
Example #16
Source File: PepManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public boolean isSupported()
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    BareJid localBareJid = connection.getUser().asBareJid();
    return serviceDiscoveryManager.supportsFeatures(localBareJid, REQUIRED_FEATURES);
}
 
Example #17
Source File: LolChat.java    From League-of-Legends-XMPP-Chat-Library with MIT License 5 votes vote down vote up
/**
 * Disconnects from chatserver and releases all resources.
 */
public void disconnect() {
	connection.getRoster().removeRosterListener(leagueRosterListener);
	try {
		connection.disconnect();
	} catch (final NotConnectedException e) {
		e.printStackTrace();
	}
	stop = true;
}
 
Example #18
Source File: TransportNegotiator.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Trigger a Transport session established event.
 *
 * @param local  TransportCandidate that has been agreed.
 * @param remote TransportCandidate that has been agreed.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
private void triggerTransportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException {
    List<JingleListener> listeners = getListenersList();
    for (JingleListener li : listeners) {
        if (li instanceof JingleTransportListener) {
            JingleTransportListener mli = (JingleTransportListener) li;
            LOGGER.fine("triggerTransportEstablished " + local.getLocalIp() + ":" + local.getPort() + " <-> "
                    + remote.getIp() + ":" + remote.getPort());
            mli.transportEstablished(local, remote);
        }
    }
}
 
Example #19
Source File: IBBTransferNegotiator.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public OutputStream createOutgoingStream(String streamID, Jid initiator,
                Jid target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    InBandBytestreamSession session = this.manager.establishSession(target, streamID);
    session.setCloseBothStreamsEnabled(true);
    return session.getOutputStream();
}
 
Example #20
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 #21
Source File: SASLAuthentication.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Performs SASL authentication of the specified user. If SASL authentication was successful
 * then resource binding and session establishment will be performed. This method will return
 * the full JID provided by the server while binding a resource to the connection.<p>
 *
 * The server may assign a full JID with a username or resource different than the requested
 * by this method.
 *
 * @param username the username that is authenticating with the server.
 * @param password the password to send to the server.
 * @param authzid the authorization identifier (typically null).
 * @param sslSession the optional SSL/TLS session (if one was established)
 * @return the used SASLMechanism.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws SASLErrorException if a SASL protocol error was returned.
 * @throws IOException if an I/O error occurred.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackSaslException if a SASL specific error occurred.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws NoResponseException if there was no response from the remote entity.
 */
SASLMechanism authenticate(String username, String password, EntityBareJid authzid, SSLSession sslSession)
                throws XMPPErrorException, SASLErrorException, IOException,
                InterruptedException, SmackSaslException, NotConnectedException, NoResponseException {
    final SASLMechanism mechanism = selectMechanism(authzid);
    final CallbackHandler callbackHandler = configuration.getCallbackHandler();
    final String host = connection.getHost();
    final DomainBareJid xmppServiceDomain = connection.getXMPPServiceDomain();

    synchronized (this) {
        currentMechanism = mechanism;

        if (callbackHandler != null) {
            currentMechanism.authenticate(host, xmppServiceDomain, callbackHandler, authzid, sslSession);
        }
        else {
            currentMechanism.authenticate(username, host, xmppServiceDomain, password, authzid, sslSession);
        }

        final long deadline = System.currentTimeMillis() + connection.getReplyTimeout();
        while (!mechanism.isFinished()) {
            final long now = System.currentTimeMillis();
            if (now >= deadline) break;
            // Wait until SASL negotiation finishes
            wait(deadline - now);
        }
    }

    mechanism.throwExceptionIfRequired();

    return mechanism;
}
 
Example #22
Source File: FileTransferNegotiator.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Send a request to another user to send them a file. The other user has
 * the option of, accepting, rejecting, or not responding to a received file
 * transfer request.
 * <p>
 * If they accept, the stanza will contain the other user's chosen stream
 * type to send the file across. The two choices this implementation
 * provides to the other user for file transfer are <a
 * href="http://www.xmpp.org/extensions/jep-0065.html">SOCKS5 Bytestreams</a>,
 * which is the preferred method of transfer, and <a
 * href="http://www.xmpp.org/extensions/jep-0047.html">In-Band Bytestreams</a>,
 * which is the fallback mechanism.
 * </p>
 * <p>
 * The other user may choose to decline the file request if they do not
 * desire the file, their client does not support XEP-0096, or if there are
 * no acceptable means to transfer the file.
 * </p>
 * Finally, if the other user does not respond this method will return null
 * after the specified timeout.
 *
 * @param userID          The userID of the user to whom the file will be sent.
 * @param streamID        The unique identifier for this file transfer.
 * @param fileName        The name of this file. Preferably it should include an
 *                        extension as it is used to determine what type of file it is.
 * @param size            The size, in bytes, of the file.
 * @param desc            A description of the file.
 * @param responseTimeout The amount of time, in milliseconds, to wait for the remote
 *                        user to respond. If they do not respond in time, this
 * @return Returns the stream negotiator selected by the peer.
 * @throws XMPPErrorException Thrown if there is an error negotiating the file transfer.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NoAcceptableTransferMechanisms if no acceptable transfer mechanisms are available
 * @throws InterruptedException if the calling thread was interrupted.
 */
public StreamNegotiator negotiateOutgoingTransfer(final Jid userID,
        final String streamID, final String fileName, final long size,
        final String desc, int responseTimeout) throws XMPPErrorException, NotConnectedException, NoResponseException, NoAcceptableTransferMechanisms, InterruptedException {
    StreamInitiation si = new StreamInitiation();
    si.setSessionID(streamID);
    si.setMimeType(URLConnection.guessContentTypeFromName(fileName));

    StreamInitiation.File siFile = new StreamInitiation.File(fileName, size);
    siFile.setDesc(desc);
    si.setFile(siFile);

    si.setFeatureNegotiationForm(createDefaultInitiationForm());

    si.setFrom(connection().getUser());
    si.setTo(userID);
    si.setType(IQ.Type.set);

    Stanza siResponse = connection().createStanzaCollectorAndSend(si).nextResultOrThrow(
                    responseTimeout);

    if (siResponse instanceof IQ) {
        IQ iqResponse = (IQ) siResponse;
        if (iqResponse.getType().equals(IQ.Type.result)) {
            StreamInitiation response = (StreamInitiation) siResponse;
            return getOutgoingNegotiator(getStreamMethodField(response
                    .getFeatureNegotiationForm()));

        }
        else {
            throw new XMPPErrorException(iqResponse, iqResponse.getError());
        }
    }
    else {
        return null;
    }
}
 
Example #23
Source File: XMPPTCPConnection.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
    if (packetWriter == null) {
        throw new NotConnectedException();
    }
    packetWriter.throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
}
 
Example #24
Source File: InBandBytestreamSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
private synchronized void flushBuffer() throws IOException {

            // do nothing if no data to send available
            if (bufferPointer == 0) {
                return;
            }

            // create data packet
            String enc = Base64.encodeToString(buffer, 0, bufferPointer);
            DataPacketExtension data = new DataPacketExtension(byteStreamRequest.getSessionID(),
                            this.seq, enc);

            // write to XMPP stream
            try {
                writeToXML(data);
            }
            catch (InterruptedException | NotConnectedException e) {
                IOException ioException = new IOException();
                ioException.initCause(e);
                throw ioException;
            }

            // reset buffer pointer
            bufferPointer = 0;

            // increment sequence, considering sequence overflow
            this.seq = this.seq + 1 == 65535 ? 0 : this.seq + 1;

        }
 
Example #25
Source File: ICETransportManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException {
    if (lc instanceof ICECandidate) {
        if (((ICECandidate) lc).getType().equals(Type.relay)) {
            RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc);
        }
    }
}
 
Example #26
Source File: MultiUserChatLight.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Leave the MUCLight.
 *
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 */
public void leave() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
    HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
    affiliations.put(connection.getUser(), MUCLightAffiliation.none);

    MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations);
    IQ responseIq = connection.createStanzaCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow();
    boolean roomLeft = responseIq.getType().equals(IQ.Type.result);

    if (roomLeft) {
        removeConnectionCallbacks();
    }
}
 
Example #27
Source File: PubSubManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instant node, if supported.
 *
 * @return The node that was created
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null);
    QName qname = new QName(PubSubNamespace.basic.getXmlns(), "create");
    NodeExtension elem = (NodeExtension) reply.getExtension(qname);

    LeafNode newNode = new LeafNode(this, elem.getNode());
    nodeMap.put(newNode.getId(), newNode);

    return newNode;
}
 
Example #28
Source File: MultiUserChatLight.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Destroy the MUC Light. Only will work if it is requested by the owner.
 *
 * @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 void destroy() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(room);
    IQ responseIq = connection.createStanzaCollectorAndSend(mucLightDestroyIQ).nextResultOrThrow();
    boolean roomDestroyed = responseIq.getType().equals(IQ.Type.result);

    if (roomDestroyed) {
        removeConnectionCallbacks();
    }
}
 
Example #29
Source File: PubSubIntegrationTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
public PubSubIntegrationTest(SmackIntegrationTestEnvironment environment)
                throws TestNotPossibleException, NoResponseException, XMPPErrorException,
                NotConnectedException, InterruptedException {
    super(environment);
    DomainBareJid pubSubService = PubSubManager.getPubSubService(conOne);
    if (pubSubService == null) {
        throw new TestNotPossibleException("No PubSub service found");
    }
    pubSubManagerOne = PubSubManager.getInstanceFor(conOne, pubSubService);
    if (!pubSubManagerOne.canCreateNodesAndPublishItems()) {
        throw new TestNotPossibleException("PubSub service does not allow node creation");
    }
}
 
Example #30
Source File: IoTDiscoveryManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private void interactWithRegistry(Jid registry) throws NotConnectedException, InterruptedException {
    boolean isNew = usedRegistries.add(registry);
    if (!isNew) {
        return;
    }
    IoTProvisioningManager iotProvisioningManager = IoTProvisioningManager.getInstanceFor(connection());
    iotProvisioningManager.sendFriendshipRequestIfRequired(registry.asBareJid());
}