2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright the original author or authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.pubsub;
|
|
|
|
|
2014-07-09 12:57:51 +02:00
|
|
|
import java.util.Collections;
|
2015-05-12 17:56:06 +02:00
|
|
|
import java.util.HashMap;
|
2014-02-17 23:58:40 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2015-05-12 17:56:06 +02:00
|
|
|
import java.util.WeakHashMap;
|
2014-02-17 23:58:40 +01:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2015-05-12 17:56:06 +02:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2020-04-05 22:10:05 +02:00
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
import org.jivesoftware.smack.Manager;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2014-03-10 09:45:50 +01:00
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2015-01-01 15:11:21 +01:00
|
|
|
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2015-01-01 15:11:21 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ.Type;
|
2015-02-05 11:17:27 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2018-04-07 21:25:40 +02:00
|
|
|
import org.jivesoftware.smack.packet.StanzaError;
|
|
|
|
import org.jivesoftware.smack.packet.StanzaError.Condition;
|
2019-06-12 22:31:55 +02:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
|
|
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
|
|
|
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
2017-04-19 11:44:01 +02:00
|
|
|
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
|
2017-08-14 20:14:35 +02:00
|
|
|
import org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException;
|
2020-05-13 20:14:41 +02:00
|
|
|
import org.jivesoftware.smackx.pubsub.form.ConfigureForm;
|
|
|
|
import org.jivesoftware.smackx.pubsub.form.FillableConfigureForm;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
|
|
|
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
|
|
|
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
|
2020-05-13 20:14:41 +02:00
|
|
|
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-08-17 08:16:49 +02:00
|
|
|
import org.jxmpp.jid.BareJid;
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jxmpp.jid.DomainBareJid;
|
|
|
|
import org.jxmpp.jid.Jid;
|
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
|
|
|
import org.jxmpp.stringprep.XmppStringprepException;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the starting point for access to the pubsub service. It
|
|
|
|
* will provide access to general information about the service, as
|
2018-05-09 23:06:12 +02:00
|
|
|
* well as create or retrieve pubsub {@link LeafNode} instances. These
|
|
|
|
* instances provide the bulk of the functionality as defined in the
|
2014-02-17 23:58:40 +01:00
|
|
|
* pubsub specification <a href="http://xmpp.org/extensions/xep-0060.html">XEP-0060</a>.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* @author Robin Collier
|
|
|
|
*/
|
2015-05-12 17:56:06 +02:00
|
|
|
public final class PubSubManager extends Manager {
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2020-04-13 15:26:46 +02:00
|
|
|
public static final String PLUS_NOTIFY = "+notify";
|
|
|
|
|
2017-04-06 12:32:34 +02:00
|
|
|
public static final String AUTO_CREATE_FEATURE = "http://jabber.org/protocol/pubsub#auto-create";
|
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
private static final Logger LOGGER = Logger.getLogger(PubSubManager.class.getName());
|
2015-08-17 08:16:49 +02:00
|
|
|
private static final Map<XMPPConnection, Map<BareJid, PubSubManager>> INSTANCES = new WeakHashMap<>();
|
2015-05-12 17:56:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The JID of the PubSub service this manager manages.
|
|
|
|
*/
|
2015-08-17 08:16:49 +02:00
|
|
|
private final BareJid pubSubService;
|
2015-05-12 17:56:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A map of node IDs to Nodes, used to cache those Nodes. This does only cache the type of Node,
|
|
|
|
* i.e. {@link CollectionNode} or {@link LeafNode}.
|
|
|
|
*/
|
2017-12-13 23:10:11 +01:00
|
|
|
private final Map<String, Node> nodeMap = new ConcurrentHashMap<>();
|
2015-05-12 17:56:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a PubSub manager for the default PubSub service of the connection.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param connection TODO javadoc me please
|
2015-05-12 17:56:06 +02:00
|
|
|
* @return the default PubSub manager.
|
|
|
|
*/
|
2019-04-16 10:09:01 +02:00
|
|
|
// CHECKSTYLE:OFF:RegexpSingleline
|
|
|
|
public static PubSubManager getInstanceFor(XMPPConnection connection) {
|
|
|
|
// CHECKSTYLE:ON:RegexpSingleline
|
2015-05-12 17:56:06 +02:00
|
|
|
DomainBareJid pubSubService = null;
|
|
|
|
if (connection.isAuthenticated()) {
|
|
|
|
try {
|
|
|
|
pubSubService = getPubSubService(connection);
|
|
|
|
}
|
|
|
|
catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
|
|
|
|
LOGGER.log(Level.WARNING, "Could not determine PubSub service", e);
|
|
|
|
}
|
|
|
|
catch (InterruptedException e) {
|
2017-12-13 23:10:11 +01:00
|
|
|
LOGGER.log(Level.FINE, "Interrupted while trying to determine PubSub service", e);
|
2015-05-12 17:56:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pubSubService == null) {
|
|
|
|
try {
|
|
|
|
// Perform an educated guess about what the PubSub service's domain bare JID may be
|
2015-05-18 16:48:23 +02:00
|
|
|
pubSubService = JidCreate.domainBareFrom("pubsub." + connection.getXMPPServiceDomain());
|
2015-05-12 17:56:06 +02:00
|
|
|
}
|
|
|
|
catch (XmppStringprepException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2019-04-16 10:09:01 +02:00
|
|
|
return getInstanceFor(connection, pubSubService);
|
2015-05-12 17:56:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-15 18:07:42 +02:00
|
|
|
* Get the PubSub manager for the given connection and PubSub service. Use <code>null</code> as argument for
|
|
|
|
* pubSubService to retrieve a PubSubManager for the users PEP service.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-05-12 17:56:06 +02:00
|
|
|
* @param connection the XMPP connection.
|
2018-08-15 18:07:42 +02:00
|
|
|
* @param pubSubService the PubSub service, may be <code>null</code>.
|
2015-05-12 17:56:06 +02:00
|
|
|
* @return a PubSub manager for the connection and service.
|
|
|
|
*/
|
2019-04-16 10:09:01 +02:00
|
|
|
// CHECKSTYLE:OFF:RegexpSingleline
|
|
|
|
public static PubSubManager getInstanceFor(XMPPConnection connection, BareJid pubSubService) {
|
|
|
|
// CHECKSTYLE:ON:RegexpSingleline
|
2018-08-15 18:07:42 +02:00
|
|
|
if (pubSubService != null && connection.isAuthenticated() && connection.getUser().asBareJid().equals(pubSubService)) {
|
|
|
|
// PEP service.
|
|
|
|
pubSubService = null;
|
2015-05-12 17:56:06 +02:00
|
|
|
}
|
2018-08-15 18:07:42 +02:00
|
|
|
|
|
|
|
PubSubManager pubSubManager;
|
|
|
|
Map<BareJid, PubSubManager> managers;
|
|
|
|
synchronized (INSTANCES) {
|
|
|
|
managers = INSTANCES.get(connection);
|
|
|
|
if (managers == null) {
|
|
|
|
managers = new HashMap<>();
|
|
|
|
INSTANCES.put(connection, managers);
|
|
|
|
}
|
2015-05-12 17:56:06 +02:00
|
|
|
}
|
2018-08-15 18:07:42 +02:00
|
|
|
synchronized (managers) {
|
|
|
|
pubSubManager = managers.get(pubSubService);
|
|
|
|
if (pubSubManager == null) {
|
|
|
|
pubSubManager = new PubSubManager(connection, pubSubService);
|
|
|
|
managers.put(pubSubService, pubSubManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
return pubSubManager;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2019-04-16 10:09:01 +02:00
|
|
|
/**
|
|
|
|
* Deprecated.
|
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param connection the connection.
|
|
|
|
* @return the PubSub manager for the given connection.
|
2019-04-16 10:09:01 +02:00
|
|
|
* @deprecated use {@link #getInstanceFor(XMPPConnection)} instead.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
// TODO: Remove in Smack 4.5.
|
|
|
|
public static PubSubManager getInstance(XMPPConnection connection) {
|
|
|
|
return getInstanceFor(connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deprecated.
|
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param connection the connection.
|
|
|
|
* @param pubSubService the XMPP address of the PubSub service.
|
|
|
|
* @return the PubSub manager for the given connection.
|
2019-04-16 10:09:01 +02:00
|
|
|
* @deprecated use {@link #getInstanceFor(XMPPConnection, BareJid)} instead.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
// TODO: Remove in Smack 4.5.
|
|
|
|
public static PubSubManager getInstance(XMPPConnection connection, BareJid pubSubService) {
|
|
|
|
return getInstanceFor(connection, pubSubService);
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Create a pubsub manager associated to the specified connection where
|
|
|
|
* the pubsub requests require a specific to address for packets.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @param connection The XMPP connection
|
|
|
|
* @param toAddress The pubsub specific to address (required for some servers)
|
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
PubSubManager(XMPPConnection connection, BareJid toAddress) {
|
2017-02-07 22:02:40 +01:00
|
|
|
super(connection);
|
|
|
|
pubSubService = toAddress;
|
|
|
|
}
|
|
|
|
|
2019-08-28 22:50:58 +02:00
|
|
|
private void checkIfXmppErrorBecauseOfNotLeafNode(String nodeId, XMPPErrorException xmppErrorException)
|
|
|
|
throws XMPPErrorException, NotALeafNodeException {
|
|
|
|
Condition condition = xmppErrorException.getStanzaError().getCondition();
|
|
|
|
if (condition == Condition.feature_not_implemented) {
|
|
|
|
// XEP-0060 § 6.5.9.5: Item retrieval not supported, e.g. because node is a collection node
|
|
|
|
throw new PubSubException.NotALeafNodeException(nodeId, pubSubService);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw xmppErrorException;
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Creates an instant node, if supported.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return The node that was created
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null);
|
2020-04-05 22:10:05 +02:00
|
|
|
QName qname = new QName(PubSubNamespace.basic.getXmlns(), "create");
|
|
|
|
NodeExtension elem = (NodeExtension) reply.getExtension(qname);
|
2017-02-07 22:02:40 +01:00
|
|
|
|
|
|
|
LeafNode newNode = new LeafNode(this, elem.getNode());
|
|
|
|
nodeMap.put(newNode.getId(), newNode);
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a node with default configuration.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
|
|
|
* @param nodeId The id of the node, which must be unique within the
|
2017-02-07 22:02:40 +01:00
|
|
|
* pubsub service
|
|
|
|
* @return The node that was created
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
return (LeafNode) createNode(nodeId, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a node with specified configuration.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* Note: This is the only way to create a collection node.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
|
|
|
* @param nodeId The name of the node, which must be unique within the
|
2017-02-07 22:02:40 +01:00
|
|
|
* pubsub service
|
|
|
|
* @param config The configuration for the node
|
|
|
|
* @return The node that was created
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2020-05-13 20:14:41 +02:00
|
|
|
public Node createNode(String nodeId, FillableConfigureForm config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2018-04-19 11:05:43 +02:00
|
|
|
PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId));
|
2017-02-07 22:02:40 +01:00
|
|
|
boolean isLeafNode = true;
|
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
if (config != null) {
|
2020-05-13 20:14:41 +02:00
|
|
|
DataForm submitForm = config.getDataFormToSubmit();
|
|
|
|
request.addExtension(new FormNode(FormNodeType.CONFIGURE, submitForm));
|
|
|
|
NodeType nodeType = config.getNodeType();
|
|
|
|
// Note that some implementations do to have the pubsub#node_type field in their defauilt configuration,
|
|
|
|
// which I believe to be a bug. However, since PubSub specifies the default node type to be 'leaf' we assume
|
|
|
|
// leaf if the field does not exist.
|
|
|
|
isLeafNode = nodeType == null || nodeType == NodeType.leaf;
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Errors will cause exceptions in getReply, so it only returns
|
|
|
|
// on success.
|
|
|
|
sendPubsubPacket(request);
|
|
|
|
Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId);
|
|
|
|
nodeMap.put(newNode.getId(), newNode);
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* Retrieves the requested node, if it exists. It will throw an
|
2017-02-07 22:02:40 +01:00
|
|
|
* exception if it does not.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @param id - The unique id of the node
|
2017-12-23 20:21:19 +01:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return the node
|
|
|
|
* @throws XMPPErrorException The node does not exist
|
|
|
|
* @throws NoResponseException if there was no response from the server.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws NotConnectedException if the XMPP connection is not connected.
|
|
|
|
* @throws InterruptedException if the calling thread was interrupted.
|
|
|
|
* @throws NotAPubSubNodeException if a involved node is not a PubSub node.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-08-16 15:24:43 +02:00
|
|
|
public Node getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAPubSubNodeException {
|
2019-06-12 22:31:55 +02:00
|
|
|
StringUtils.requireNotNullNorEmpty(id, "The node ID can not be null or the empty string");
|
2017-02-07 22:02:40 +01:00
|
|
|
Node node = nodeMap.get(id);
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
if (node == null) {
|
2019-10-29 11:14:55 +01:00
|
|
|
XMPPConnection connection = connection();
|
|
|
|
DiscoverInfo info = DiscoverInfo.builder(connection)
|
|
|
|
.to(pubSubService)
|
|
|
|
.setNode(id)
|
|
|
|
.build();
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2019-10-29 11:14:55 +01:00
|
|
|
DiscoverInfo infoReply = connection.createStanzaCollectorAndSend(info).nextResultOrThrow();
|
2014-10-16 17:43:44 +02:00
|
|
|
|
|
|
|
if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) {
|
2015-05-12 17:56:06 +02:00
|
|
|
node = new LeafNode(this, id);
|
2014-10-16 17:43:44 +02:00
|
|
|
}
|
|
|
|
else if (infoReply.hasIdentity(PubSub.ELEMENT, "collection")) {
|
2015-05-12 17:56:06 +02:00
|
|
|
node = new CollectionNode(this, id);
|
2014-10-16 17:43:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-14 20:14:35 +02:00
|
|
|
throw new PubSubException.NotAPubSubNodeException(id, infoReply);
|
2014-10-16 17:43:44 +02:00
|
|
|
}
|
2017-02-07 22:02:40 +01:00
|
|
|
nodeMap.put(id, node);
|
|
|
|
}
|
2018-08-16 15:24:43 +02:00
|
|
|
return node;
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
|
|
|
|
2017-03-18 18:31:06 +01:00
|
|
|
/**
|
|
|
|
* Try to get a leaf node and create one if it does not already exist.
|
|
|
|
*
|
|
|
|
* @param id The unique ID of the node.
|
|
|
|
* @return the leaf node.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
|
|
|
* @throws XMPPErrorException if there was an XMPP error returned.
|
2017-04-19 11:44:01 +02:00
|
|
|
* @throws NotALeafNodeException in case the node already exists as collection node.
|
2017-03-18 18:31:06 +01:00
|
|
|
* @since 4.2.1
|
|
|
|
*/
|
|
|
|
public LeafNode getOrCreateLeafNode(final String id)
|
2017-04-19 11:44:01 +02:00
|
|
|
throws NoResponseException, NotConnectedException, InterruptedException, XMPPErrorException, NotALeafNodeException {
|
2017-03-18 18:31:06 +01:00
|
|
|
try {
|
2018-08-16 15:24:43 +02:00
|
|
|
return getLeafNode(id);
|
2017-03-18 18:31:06 +01:00
|
|
|
}
|
2017-08-14 20:14:35 +02:00
|
|
|
catch (NotAPubSubNodeException e) {
|
|
|
|
return createNode(id);
|
|
|
|
}
|
2017-03-18 18:31:06 +01:00
|
|
|
catch (XMPPErrorException e1) {
|
2018-06-20 15:55:48 +02:00
|
|
|
if (e1.getStanzaError().getCondition() == Condition.item_not_found) {
|
2017-03-18 18:31:06 +01:00
|
|
|
try {
|
|
|
|
return createNode(id);
|
|
|
|
}
|
|
|
|
catch (XMPPErrorException e2) {
|
2018-06-20 15:55:48 +02:00
|
|
|
if (e2.getStanzaError().getCondition() == Condition.conflict) {
|
2017-03-18 18:31:06 +01:00
|
|
|
// The node was created in the meantime, re-try getNode(). Note that this case should be rare.
|
2017-08-14 20:14:35 +02:00
|
|
|
try {
|
2018-08-16 15:24:43 +02:00
|
|
|
return getLeafNode(id);
|
2017-08-14 20:14:35 +02:00
|
|
|
}
|
|
|
|
catch (NotAPubSubNodeException e) {
|
|
|
|
// Should not happen
|
|
|
|
throw new IllegalStateException(e);
|
|
|
|
}
|
2017-03-18 18:31:06 +01:00
|
|
|
}
|
|
|
|
throw e2;
|
|
|
|
}
|
|
|
|
}
|
2018-06-20 15:55:48 +02:00
|
|
|
if (e1.getStanzaError().getCondition() == Condition.service_unavailable) {
|
2017-04-19 11:34:47 +02:00
|
|
|
// This could be caused by Prosody bug #805 (see https://prosody.im/issues/issue/805). Prosody does not
|
|
|
|
// answer to disco#info requests on the node ID, which makes it undecidable if a node is a leaf or
|
|
|
|
// collection node.
|
|
|
|
LOGGER.warning("The PubSub service " + pubSubService
|
|
|
|
+ " threw an DiscoInfoNodeAssertionError, trying workaround for Prosody bug #805 (https://prosody.im/issues/issue/805)");
|
|
|
|
return getOrCreateLeafNodeProsodyWorkaround(id);
|
|
|
|
}
|
2017-03-18 18:31:06 +01:00
|
|
|
throw e1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 11:44:01 +02:00
|
|
|
/**
|
|
|
|
* Try to get a leaf node with the given node ID.
|
|
|
|
*
|
|
|
|
* @param id the node ID.
|
|
|
|
* @return the requested leaf node.
|
|
|
|
* @throws NotALeafNodeException in case the node exists but is a collection node.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
|
|
|
* @throws XMPPErrorException if there was an XMPP error returned.
|
|
|
|
* @throws NotAPubSubNodeException if a involved node is not a PubSub node.
|
2017-04-19 11:44:01 +02:00
|
|
|
* @since 4.2.1
|
|
|
|
*/
|
|
|
|
public LeafNode getLeafNode(String id) throws NotALeafNodeException, NoResponseException, NotConnectedException,
|
2017-08-14 20:14:35 +02:00
|
|
|
InterruptedException, XMPPErrorException, NotAPubSubNodeException {
|
2017-04-19 11:44:01 +02:00
|
|
|
Node node;
|
|
|
|
try {
|
|
|
|
node = getNode(id);
|
|
|
|
}
|
|
|
|
catch (XMPPErrorException e) {
|
2018-06-20 15:55:48 +02:00
|
|
|
if (e.getStanzaError().getCondition() == Condition.service_unavailable) {
|
2017-04-19 11:50:01 +02:00
|
|
|
// This could be caused by Prosody bug #805 (see https://prosody.im/issues/issue/805). Prosody does not
|
|
|
|
// answer to disco#info requests on the node ID, which makes it undecidable if a node is a leaf or
|
|
|
|
// collection node.
|
2017-04-19 12:23:17 +02:00
|
|
|
return getLeafNodeProsodyWorkaround(id);
|
2017-04-19 11:44:01 +02:00
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node instanceof LeafNode) {
|
|
|
|
return (LeafNode) node;
|
2017-03-18 18:31:06 +01:00
|
|
|
}
|
2017-04-19 11:44:01 +02:00
|
|
|
|
|
|
|
throw new PubSubException.NotALeafNodeException(id, pubSubService);
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:23:17 +02:00
|
|
|
private LeafNode getLeafNodeProsodyWorkaround(final String id) throws NoResponseException, NotConnectedException,
|
|
|
|
InterruptedException, NotALeafNodeException, XMPPErrorException {
|
2017-04-19 11:44:01 +02:00
|
|
|
LeafNode leafNode = new LeafNode(this, id);
|
|
|
|
try {
|
|
|
|
// Try to ensure that this is not a collection node by asking for one item form the node.
|
|
|
|
leafNode.getItems(1);
|
|
|
|
} catch (XMPPErrorException e) {
|
2019-08-28 22:50:58 +02:00
|
|
|
checkIfXmppErrorBecauseOfNotLeafNode(id, e);
|
2017-04-19 11:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
nodeMap.put(id, leafNode);
|
|
|
|
|
|
|
|
return leafNode;
|
2017-03-18 18:31:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private LeafNode getOrCreateLeafNodeProsodyWorkaround(final String id)
|
2017-04-19 11:44:01 +02:00
|
|
|
throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotALeafNodeException {
|
2017-03-18 18:31:06 +01:00
|
|
|
try {
|
|
|
|
return createNode(id);
|
|
|
|
}
|
|
|
|
catch (XMPPErrorException e1) {
|
2018-06-20 15:55:48 +02:00
|
|
|
if (e1.getStanzaError().getCondition() == Condition.conflict) {
|
2017-04-19 12:23:17 +02:00
|
|
|
return getLeafNodeProsodyWorkaround(id);
|
2017-03-18 18:31:06 +01:00
|
|
|
}
|
|
|
|
throw e1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-06 10:14:27 +02:00
|
|
|
/**
|
|
|
|
* Try to publish an item and, if the node with the given ID does not exists, auto-create the node.
|
2017-04-06 12:32:34 +02:00
|
|
|
* <p>
|
|
|
|
* Not every PubSub service supports automatic node creation. You can discover if this service supports it by using
|
|
|
|
* {@link #supportsAutomaticNodeCreation()}.
|
|
|
|
* </p>
|
2017-04-06 10:14:27 +02:00
|
|
|
*
|
|
|
|
* @param id The unique id of the node.
|
|
|
|
* @param item The item to publish.
|
2017-12-23 20:21:19 +01:00
|
|
|
* @param <I> type of the item.
|
|
|
|
*
|
2017-04-06 10:14:27 +02:00
|
|
|
* @return the LeafNode on which the item was published.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
|
|
|
* @throws NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node.
|
2017-04-06 10:14:27 +02:00
|
|
|
* @since 4.2.1
|
|
|
|
*/
|
|
|
|
public <I extends Item> LeafNode tryToPublishAndPossibleAutoCreate(String id, I item)
|
2019-08-28 22:50:58 +02:00
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException,
|
|
|
|
NotALeafNodeException {
|
2017-04-06 10:14:27 +02:00
|
|
|
LeafNode leafNode = new LeafNode(this, id);
|
2019-08-28 22:50:58 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
leafNode.publish(item);
|
|
|
|
} catch (XMPPErrorException e) {
|
|
|
|
checkIfXmppErrorBecauseOfNotLeafNode(id, e);
|
|
|
|
}
|
2017-04-06 10:14:27 +02:00
|
|
|
|
2017-05-25 10:39:59 +02:00
|
|
|
// If LeafNode.publish() did not throw then we have successfully published an item and possible auto-created
|
2017-04-06 10:14:27 +02:00
|
|
|
// (XEP-0163 § 3., XEP-0060 § 7.1.4) the node. So we can put the node into the nodeMap.
|
|
|
|
nodeMap.put(id, leafNode);
|
|
|
|
|
|
|
|
return leafNode;
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Get all the nodes that currently exist as a child of the specified
|
|
|
|
* collection node. If the service does not support collection nodes
|
|
|
|
* then all nodes will be returned.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
|
|
|
* To retrieve contents of the root collection node (if it exists),
|
2017-02-07 22:02:40 +01:00
|
|
|
* or there is no root collection node, pass null as the nodeId.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
|
|
|
* @param nodeId - The id of the collection node for which the child
|
|
|
|
* nodes will be returned.
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return {@link DiscoverItems} representing the existing nodes
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws XMPPErrorException if there was an XMPP error returned.
|
2017-02-07 22:02:40 +01:00
|
|
|
* @throws NoResponseException if there was no response from the server.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws NotConnectedException if the XMPP connection is not connected.
|
|
|
|
* @throws InterruptedException if the calling thread was interrupted.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
DiscoverItems items = new DiscoverItems();
|
|
|
|
|
|
|
|
if (nodeId != null)
|
|
|
|
items.setNode(nodeId);
|
|
|
|
items.setTo(pubSubService);
|
|
|
|
DiscoverItems nodeItems = connection().createStanzaCollectorAndSend(items).nextResultOrThrow();
|
|
|
|
return nodeItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the subscriptions on the root node.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return List of exceptions
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
Stanza reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null);
|
2020-04-12 12:09:04 +02:00
|
|
|
SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtensionElement(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns());
|
2017-02-07 22:02:40 +01:00
|
|
|
return subElem.getSubscriptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the affiliations on the root node.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return List of affiliations
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
|
|
|
|
AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
|
|
|
|
return listElem.getAffiliations();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the specified node.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param nodeId TODO javadoc me please
|
|
|
|
* @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.
|
2018-08-15 17:48:54 +02:00
|
|
|
* @return <code>true</code> if this node existed and was deleted and <code>false</code> if this node did not exist.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-08-15 17:48:54 +02:00
|
|
|
public boolean deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
|
|
|
boolean res = true;
|
|
|
|
try {
|
|
|
|
sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.DELETE, nodeId), PubSubElementType.DELETE.getNamespace());
|
|
|
|
} catch (XMPPErrorException e) {
|
|
|
|
if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) {
|
|
|
|
res = false;
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2017-02-07 22:02:40 +01:00
|
|
|
nodeMap.remove(nodeId);
|
2018-08-15 17:48:54 +02:00
|
|
|
return res;
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the default settings for Node configuration.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return configuration form containing the default settings.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public ConfigureForm getDefaultConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
// Errors will cause exceptions in getReply, so it only returns
|
|
|
|
// on success.
|
|
|
|
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.DEFAULT), PubSubElementType.DEFAULT.getNamespace());
|
|
|
|
return NodeUtils.getFormFromPacket(reply, PubSubElementType.DEFAULT);
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
/**
|
|
|
|
* Get the JID of the PubSub service managed by this manager.
|
|
|
|
*
|
|
|
|
* @return the JID of the PubSub service.
|
|
|
|
*/
|
2015-08-17 08:16:49 +02:00
|
|
|
public BareJid getServiceJid() {
|
2015-05-12 17:56:06 +02:00
|
|
|
return pubSubService;
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Gets the supported features of the servers pubsub implementation
|
|
|
|
* as a standard {@link DiscoverInfo} instance.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return The supported features
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection());
|
|
|
|
return mgr.discoverInfo(pubSubService);
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-04-06 12:32:34 +02:00
|
|
|
/**
|
|
|
|
* Check if the PubSub service supports automatic node creation.
|
|
|
|
*
|
|
|
|
* @return true if the PubSub service supports automatic node creation.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2017-04-06 12:32:34 +02:00
|
|
|
* @since 4.2.1
|
|
|
|
* @see <a href="https://xmpp.org/extensions/xep-0060.html#publisher-publish-autocreate">XEP-0060 § 7.1.4 Automatic Node Creation</a>
|
|
|
|
*/
|
|
|
|
public boolean supportsAutomaticNodeCreation()
|
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
|
|
|
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
|
|
|
|
return sdm.supportsFeature(pubSubService, AUTO_CREATE_FEATURE);
|
|
|
|
}
|
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
/**
|
|
|
|
* Check if it is possible to create PubSub nodes on this service. It could be possible that the
|
|
|
|
* PubSub service allows only certain XMPP entities (clients) to create nodes and publish items
|
|
|
|
* to them.
|
|
|
|
* <p>
|
|
|
|
* Note that since XEP-60 does not provide an API to determine if an XMPP entity is allowed to
|
|
|
|
* create nodes, therefore this method creates an instant node calling {@link #createNode()} to
|
|
|
|
* determine if it is possible to create nodes.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @return <code>true</code> if it is possible to create nodes, <code>false</code> otherwise.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
|
|
|
* @throws XMPPErrorException if there was an XMPP error returned.
|
2015-05-12 17:56:06 +02:00
|
|
|
*/
|
|
|
|
public boolean canCreateNodesAndPublishItems() throws NoResponseException, NotConnectedException, InterruptedException, XMPPErrorException {
|
|
|
|
LeafNode leafNode = null;
|
|
|
|
try {
|
|
|
|
leafNode = createNode();
|
|
|
|
}
|
|
|
|
catch (XMPPErrorException e) {
|
2018-06-20 15:55:48 +02:00
|
|
|
if (e.getStanzaError().getCondition() == StanzaError.Condition.forbidden) {
|
2015-05-12 17:56:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
} finally {
|
|
|
|
if (leafNode != null) {
|
|
|
|
deleteNode(leafNode.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
private PubSub sendPubsubPacket(Type type, ExtensionElement ext, PubSubNamespace ns)
|
2015-02-14 09:43:44 +01:00
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2015-05-12 17:56:06 +02:00
|
|
|
return sendPubsubPacket(pubSubService, type, Collections.singletonList(ext), ns);
|
2014-07-09 12:57:51 +02:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
XMPPConnection getConnection() {
|
|
|
|
return connection();
|
|
|
|
}
|
|
|
|
|
|
|
|
PubSub sendPubsubPacket(Jid to, Type type, List<ExtensionElement> extList, PubSubNamespace ns)
|
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException,
|
|
|
|
InterruptedException {
|
2015-03-18 21:51:25 +01:00
|
|
|
// CHECKSTYLE:OFF
|
2017-02-07 22:02:40 +01:00
|
|
|
PubSub pubSub = new PubSub(to, type, ns);
|
|
|
|
for (ExtensionElement pe : extList) {
|
|
|
|
pubSub.addExtension(pe);
|
|
|
|
}
|
2015-03-18 21:51:25 +01:00
|
|
|
// CHECKSTYLE:ON
|
2015-05-12 17:56:06 +02:00
|
|
|
return sendPubsubPacket(pubSub);
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException,
|
|
|
|
NotConnectedException, InterruptedException {
|
2017-01-03 11:12:34 +01:00
|
|
|
IQ resultIQ = connection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
|
2015-01-01 15:11:21 +01:00
|
|
|
if (resultIQ instanceof EmptyResultIQ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (PubSub) resultIQ;
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-05-12 17:56:06 +02:00
|
|
|
/**
|
|
|
|
* Get the "default" PubSub service for a given XMPP connection. The default PubSub service is
|
|
|
|
* simply an arbitrary XMPP service with the PubSub feature and an identity of category "pubsub"
|
|
|
|
* and type "service".
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param connection TODO javadoc me please
|
2015-05-12 17:56:06 +02:00
|
|
|
* @return the default PubSub service or <code>null</code>.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @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.
|
2015-05-12 17:56:06 +02:00
|
|
|
* @see <a href="http://xmpp.org/extensions/xep-0060.html#entity-features">XEP-60 § 5.1 Discover
|
|
|
|
* Features</a>
|
|
|
|
*/
|
|
|
|
public static DomainBareJid getPubSubService(XMPPConnection connection)
|
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException,
|
|
|
|
InterruptedException {
|
|
|
|
return ServiceDiscoveryManager.getInstanceFor(connection).findService(PubSub.NAMESPACE,
|
|
|
|
true, "pubsub", "service");
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|