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;
}
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);
}
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;
}
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;
}
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();
}
Aggregations