Search in sources :

Example 21 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class ServiceDiscoveryManager method discoverInfo.

/**
 * Returns the discovered information of a given XMPP entity addressed by its JID and
 * note attribute. Use this message only when trying to query information which is not
 * directly addressable.
 *
 * @see <a href="http://xmpp.org/extensions/xep-0030.html#info-basic">XEP-30 Basic Protocol</a>
 * @see <a href="http://xmpp.org/extensions/xep-0030.html#info-nodes">XEP-30 Info Nodes</a>
 *
 * @param entityID the address of the XMPP entity.
 * @param node the optional attribute that supplements the 'jid' attribute.
 * @return the discovered information.
 * @throws XMPPErrorException if the operation failed for some reason.
 * @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 DiscoverInfo discoverInfo(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    // Discover the entity's info
    DiscoverInfo discoInfoRequest = DiscoverInfo.builder(connection).to(entityID).setNode(node).build();
    Stanza result = connection.sendIqRequestAndWaitForResponse(discoInfoRequest);
    return (DiscoverInfo) result;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Stanza(org.jivesoftware.smack.packet.Stanza) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 22 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class IBBTransferNegotiator method createIncomingStream.

@Override
public InputStream createIncomingStream(StreamInitiation initiation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    /*
         * In-Band Bytestream initiation listener must ignore next in-band bytestream request with
         * given session ID
         */
    this.manager.ignoreBytestreamRequestOnce(initiation.getSessionID());
    Stanza streamInitiation = initiateIncomingStream(connection(), initiation);
    return negotiateIncomingStream(streamInitiation);
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza)

Example 23 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class OfflineMessageManager method getMessages.

/**
 * Returns a List of the offline <code>Messages</code> whose stamp matches the specified
 * request. The request will include the list of stamps that uniquely identifies
 * the offline messages to retrieve. The returned offline messages will not be deleted
 * from the server. Use {@link #deleteMessages(java.util.List)} to delete the messages.
 *
 * @param nodes the list of stamps that uniquely identifies offline message.
 * @return a List with the offline <code>Messages</code> that were received as part of
 *         this request.
 * @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(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<Message> messages = new ArrayList<>(nodes.size());
    OfflineMessageRequest request = new OfflineMessageRequest();
    for (String node : nodes) {
        OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
        item.setAction("view");
        request.addItem(item);
    }
    // Filter offline messages that were requested by this request
    StanzaFilter messageFilter = new AndFilter(PACKET_FILTER, new StanzaFilter() {

        @Override
        public boolean accept(Stanza packet) {
            OfflineMessageInfo info = packet.getExtension(OfflineMessageInfo.class);
            return nodes.contains(info.getNode());
        }
    });
    int pendingNodes = nodes.size();
    try (StanzaCollector messageCollector = connection().createStanzaCollector(messageFilter)) {
        connection().sendIqRequestAndWaitForResponse(request);
        // Collect the received offline messages
        Message message;
        do {
            message = messageCollector.nextResult();
            if (message != null) {
                messages.add(message);
                pendingNodes--;
            } else if (message == null && pendingNodes > 0) {
                LOGGER.log(Level.WARNING, "Did not receive all expected offline messages. " + pendingNodes + " are missing.");
            }
        } while (message != null && pendingNodes > 0);
    }
    return messages;
}
Also used : StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) Message(org.jivesoftware.smack.packet.Message) OfflineMessageInfo(org.jivesoftware.smackx.offline.packet.OfflineMessageInfo) Stanza(org.jivesoftware.smack.packet.Stanza) ArrayList(java.util.ArrayList) AndFilter(org.jivesoftware.smack.filter.AndFilter) OfflineMessageRequest(org.jivesoftware.smackx.offline.packet.OfflineMessageRequest) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 24 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class PingManager method pingAsync.

public SmackFuture<Boolean, Exception> pingAsync(final Jid jid, long pongTimeout) {
    final InternalProcessStanzaSmackFuture<Boolean, Exception> future = new InternalProcessStanzaSmackFuture<Boolean, Exception>() {

        @Override
        public void handleStanza(Stanza packet) {
            setResult(true);
        }

        @Override
        public boolean isNonFatalException(Exception exception) {
            if (exception instanceof XMPPErrorException) {
                XMPPErrorException xmppErrorException = (XMPPErrorException) exception;
                if (isValidErrorPong(jid, xmppErrorException)) {
                    setResult(true);
                    return true;
                }
            }
            return false;
        }
    };
    XMPPConnection connection = connection();
    Ping ping = new Ping(connection, jid);
    connection.sendIqRequestAsync(ping, pongTimeout).onSuccess(new SuccessCallback<IQ>() {

        @Override
        public void onSuccess(IQ result) {
            future.processStanza(result);
        }
    }).onError(new ExceptionCallback<Exception>() {

        @Override
        public void processException(Exception exception) {
            future.processException(exception);
        }
    });
    return future;
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) SuccessCallback(org.jivesoftware.smack.util.SuccessCallback) InternalProcessStanzaSmackFuture(org.jivesoftware.smack.SmackFuture.InternalProcessStanzaSmackFuture) Stanza(org.jivesoftware.smack.packet.Stanza) Ping(org.jivesoftware.smackx.ping.packet.Ping) IQ(org.jivesoftware.smack.packet.IQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException)

Example 25 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class PubSubManager method getSubscriptions.

/**
 * Gets the subscriptions on the root node.
 *
 * @return List of exceptions
 * @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 List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Stanza reply = sendPubsubPacket(IQ.Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null);
    SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtensionElement(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns());
    return subElem.getSubscriptions();
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza)

Aggregations

Stanza (org.jivesoftware.smack.packet.Stanza)101 StanzaListener (org.jivesoftware.smack.StanzaListener)24 Test (org.junit.Test)22 IQ (org.jivesoftware.smack.packet.IQ)20 Test (org.junit.jupiter.api.Test)18 XMPPConnection (org.jivesoftware.smack.XMPPConnection)14 Message (org.jivesoftware.smack.packet.Message)14 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 Jid (org.jxmpp.jid.Jid)11 IOException (java.io.IOException)9 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)8 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)8 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)7 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)7 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)6 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)6 Protocol (org.jivesoftware.util.Protocol)6 EntityFullJid (org.jxmpp.jid.EntityFullJid)6 LinkedList (java.util.LinkedList)5