/** * Creates a node with default configuration. * * @param nodeId The id of the node, which must be unique within the * pubsub service * @return The node that was created * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return (LeafNode) createNode(nodeId, null); }
public static void cleanUpPubSub(OmemoManager omemoManager) { PubSubManager pm = PubSubManager.getInstance(omemoManager.getConnection(),omemoManager.getOwnJid()); try { omemoManager.requestDeviceListUpdateFor(omemoManager.getOwnJid()); pm.getLeafNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)).deleteAllItems(); } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException | pm.deleteNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)); } catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) { pm.getLeafNode(OmemoConstants.PEP_NODE_DEVICE_LIST).deleteAllItems(); } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException | pm.deleteNode(OmemoConstants.PEP_NODE_DEVICE_LIST); } catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
Node node; try { node = getNode(id); return getLeafNodeProsodyWorkaround(id);
private LeafNode getNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotALeafNodeException { return PubSubManager.getInstance(connection()).getOrCreateLeafNode(GeoLocation.NAMESPACE); }
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.getInstance(conOne, pubSubService); if (!pubSubManagerOne.canCreateNodesAndPublishItems()) { throw new TestNotPossibleException("PubSub service does not allow node creation"); } }
private LeafNode getOrCreateLeafNodeProsodyWorkaround(final String id) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotALeafNodeException { try { return createNode(id); } catch (XMPPErrorException e1) { if (e1.getStanzaError().getCondition() == Condition.conflict) { return getLeafNodeProsodyWorkaround(id); } throw e1; } }
protected PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return pubSubManager.sendPubsubPacket(packet); }
@SmackIntegrationTest public void simplePubSubNodeTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { final String nodename = "sinttest-simple-nodename-" + testRunId; final String itemId = "sintest-simple-itemid-" + testRunId; ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration(); ConfigureForm config = new ConfigureForm(defaultConfiguration.createAnswerForm()); // Configure the node as "Notification-Only Node", which in turn means that // items do not need payload, to prevent payload-required error responses when // publishing the item. config.setDeliverPayloads(false); config.setPersistentItems(true); Node node = pubSubManagerOne.createNode(nodename, config); try { LeafNode leafNode = (LeafNode) node; leafNode.publish(new Item(itemId)); List<Item> items = leafNode.getItems(); assertEquals(1, items.size()); Item item = items.get(0); assertEquals(itemId, item.getId()); } finally { pubSubManagerOne.deleteNode(nodename); } } }
throws NoResponseException, NotConnectedException, InterruptedException, XMPPErrorException, NotALeafNodeException { try { return getLeafNode(id); return createNode(id); return createNode(id); return getLeafNode(id); return getOrCreateLeafNodeProsodyWorkaround(id);
LeafNode leafNode = null; try { leafNode = createNode(); } finally { if (leafNode != null) { deleteNode(leafNode.getId());
/** * Retrieve the OMEMO device list of a contact. * * @param connection authenticated XMPP connection. * @param contact BareJid of the contact of which we want to retrieve the device list from. * @return * @throws InterruptedException * @throws PubSubException.NotALeafNodeException * @throws SmackException.NoResponseException * @throws SmackException.NotConnectedException * @throws XMPPException.XMPPErrorException * @throws PubSubException.NotAPubSubNodeException */ private static OmemoDeviceListElement fetchDeviceList(XMPPConnection connection, BareJid contact) throws InterruptedException, PubSubException.NotALeafNodeException, SmackException.NoResponseException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, PubSubException.NotAPubSubNodeException { PubSubManager pm = PubSubManager.getInstance(connection, contact); String nodeName = OmemoConstants.PEP_NODE_DEVICE_LIST; LeafNode node = pm.getLeafNode(nodeName); if (node == null) { return null; } List<PayloadItem<OmemoDeviceListElement>> items = node.getItems(); if (items.isEmpty()) { return null; } return items.get(items.size() - 1).getPayload(); }
throws XMPPException PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name)); boolean isLeafNode = true; sendPubsubPacket(con, to, Type.SET, request); Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name); newNode.setTo(to);
DiscoverItems dItems = manager.discoverNodes(null); Iterator<DiscoverItems.Item> iItems = dItems.getItems(); while(iItems.hasNext()) { if (it.getNode().equalsIgnoreCase(nodePath)) { return (LeafNode)manager.getNode(nodePath); form.setDeliverPayloads(true); form.setAccessModel(AccessModel.open); return (LeafNode)manager.createNode(nodePath, form); } catch (XMPPException e) { logger.error("Error creating XMPP pubsub node: " + e);
/** * Creates a new PEP exchange manager. * * @param connection an XMPPConnection which is used to send and receive messages. */ private PepManager(XMPPConnection connection) { super(connection); StanzaListener packetListener = new StanzaListener() { @Override public void processStanza(Stanza stanza) { final Message message = (Message) stanza; final EventElement event = EventElement.from(stanza); assert (event != null); final EntityBareJid from = message.getFrom().asEntityBareJidIfPossible(); assert (from != null); asyncButOrdered.performAsyncButOrdered(from, new Runnable() { @Override public void run() { for (PepListener listener : pepListeners) { listener.eventReceived(from, event, message); } } }); } }; // TODO Add filter to check if from supports PubSub as per xep163 2 2.4 connection.addSyncStanzaListener(packetListener, FROM_BARE_JID_WITH_EVENT_EXTENSION_FILTER); pepPubSubManager = PubSubManager.getInstance(connection, null); }
/** * Delete all nodes */ public synchronized void deleteAllNodes() { if ((xmppCon == null) || (!xmppCon.isConnected())) login(); try { DiscoverItems dItems = manager.discoverNodes(null); Iterator<DiscoverItems.Item> iItems = dItems.getItems(); while(iItems.hasNext()) { DiscoverItems.Item it = iItems.next(); logger.debug("Deleting node " + it.getNode()); try { Node n = manager.getNode(it.getNode()); if ((n != null) && (n instanceof LeafNode)){ LeafNode ln = (LeafNode)n; ln.deleteAllItems(); } else logger.info("Unable to delete items of node " + it.getNode()); manager.deleteNode(it.getNode()); } catch (XMPPException e) { logger.error("Error deleting node: " + e); } } } catch (XMPPException e) { logger.error("Error deleting nodes: " + e); } }
@Test(expected = SmackException.class) public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException { ThreadedDummyConnection con = new ThreadedDummyConnection(); PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); SmackConfiguration.setDefaultReplyTimeout(100); con.setTimeout(); node.getNodeConfiguration(); }
static PubSub createPubsubPacket(String to, Type type, PacketExtension ext) { return createPubsubPacket(to, type, ext, null); }
/** * Delete specified node * @param nodepath - path to node */ public synchronized void deleteNode(String nodepath) { if ((xmppCon == null) || (!xmppCon.isConnected())) login(); logger.info("Deleting node " + nodepath); try { Node n = manager.getNode(nodepath); if ((n != null) && (n instanceof LeafNode)){ LeafNode ln = (LeafNode)n; ln.deleteAllItems(); } else logger.info("Unable to delete items of node " + nodepath); manager.deleteNode(nodepath); } catch (XMPPException e) { logger.error("Error deleting node: " + e); } }
/** * * @param nodeName - node name * @param s - subscription */ public synchronized void unsubscribeFromNode(String nodeName, Subscription s) { try { LeafNode node = (LeafNode)manager.getNode(nodeName); node.unsubscribe(s.getJid(), s.getId()); } catch (XMPPException e) { logger.error("XMPP Error unsubscribing from XMPP pubsub node: " + e); } catch (Exception e) { logger.error("Error unsubscribing from XMPP pubsub node: " + e); } }
@Test public void deleteNodeTest() throws InterruptedException, SmackException, IOException, XMPPException { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con, DUMMY_PUBSUB_SERVICE); mgr.deleteNode("foo@bar.org"); PubSub pubSubDeleteRequest = con.getSentPacket(); assertEquals("http://jabber.org/protocol/pubsub#owner", pubSubDeleteRequest.getChildElementNamespace()); assertEquals("pubsub", pubSubDeleteRequest.getChildElementName()); } }