/** * Publishes an event to the node. This can be either a simple item * with no payload, or one with it. This is determined by the Node * configuration. * * If the node has <b>deliver_payload=false</b>, the Item must not * have a payload. * * If the id is null, an empty item (one without an id) will be sent. * Please note that this is not the same as {@link #send()}, which * publishes an event with NO item. * * @param item - The item being sent * @param <T> type of the items. * * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException * */ @SuppressWarnings("unchecked") public <T extends Item> void publish(T item) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Collection<T> items = new ArrayList<>(1); items.add((item == null ? (T) new Item() : item)); publish(items); }
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * @param <T> type of the items. * * @return The list of {@link Item} with payload * @throws XMPPErrorException * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { List<Item> itemList = new ArrayList<>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.get, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); return getItems(request); }
/** * Delete the items with the specified id's from the node. * * @param itemIds The list of id's of items to delete * @throws XMPPErrorException * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException */ public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { List<Item> items = new ArrayList<>(itemIds.size()); for (String id : itemIds) { items.add(new Item(id)); } PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); } }
@Override public Item parse(XmlPullParser parser, int initialDepth) throws Exception { String id = parser.getAttributeValue(null, "id"); String node = parser.getAttributeValue(null, "node"); String xmlns = parser.getNamespace(); ItemNamespace itemNamespace = ItemNamespace.fromXmlns(xmlns); int tag = parser.next(); if (tag == XmlPullParser.END_TAG) { return new Item(itemNamespace, id, node); } else { String payloadElemName = parser.getName(); String payloadNS = parser.getNamespace(); final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS); if (extensionProvider == null) { // TODO: Should we use StandardExtensionElement in this case? And probably remove SimplePayload all together. CharSequence payloadText = PacketParserUtils.parseElement(parser, true); return new PayloadItem<>(itemNamespace, id, node, new SimplePayload(payloadText.toString())); } else { return new PayloadItem<>(itemNamespace, id, node, extensionProvider.parse(parser)); } } }
@Test public void verifyBasicItem() throws Exception { Item simpleItem = new Item(); String simpleCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' />"; assertXMLEqual(simpleCtrl, simpleItem.toXML(null).toString()); Item idItem = new Item("uniqueid"); String idCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' id='uniqueid'/>"; assertXMLEqual(idCtrl, idItem.toXML(null).toString()); Item itemWithNodeId = new Item("testId", "testNode"); String nodeIdCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' id='testId' node='testNode' />"; assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML(null).toString()); }
@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); } } }
/** * Publishes an event to the node. This is a simple item * with no payload. * * If the id is null, an empty item (one without an id) will be sent. * Please note that this is not the same as {@link #send()}, which * publishes an event with NO item. * * This is an asynchronous call which returns as soon as the * packet has been sent. * * For synchronous calls use {@link #send(Item) send(Item))}. * * @param item - The item being sent */ public <T extends Item> void publish(T item) { Collection<T> items = new ArrayList<T>(1); items.add((T)(item == null ? new Item() : item)); publish(items); }
/** * Publishes an event to the node. This is a simple item * with no payload. * * If the id is null, an empty item (one without an id) will be sent. * Please note that this is not the same as {@link #send()}, which * publishes an event with NO item. * * This is an asynchronous call which returns as soon as the * packet has been sent. * * For synchronous calls use {@link #send(Item) send(Item))}. * * @param item - The item being sent */ public <T extends Item> void publish(T item) { Collection<T> items = new ArrayList<T>(1); items.add((T)(item == null ? new Item() : item)); publish(items); }
/** * Publishes an event to the node. This is a simple item * with no payload. * * If the id is null, an empty item (one without an id) will be sent. * Please note that this is not the same as {@link #send()}, which * publishes an event with NO item. * * This is an asynchronous call which returns as soon as the * packet has been sent. * * For synchronous calls use {@link #send(Item) send(Item))}. * * @param item - The item being sent */ public <T extends Item> void publish(T item) { Collection<T> items = new ArrayList<T>(1); items.add((T)(item == null ? new Item() : item)); publish(items); }
/** * Publishes an event to the node. This can be either a simple item * with no payload, or one with it. This is determined by the Node * configuration. * * If the node has <b>deliver_payload=false</b>, the Item must not * have a payload. * * If the id is null, an empty item (one without an id) will be sent. * Please note that this is not the same as {@link #send()}, which * publishes an event with NO item. * * This is a synchronous call which will throw an exception * on failure. * * For asynchronous calls, use {@link #publish(Item) publish(Item)}. * * @param item - The item being sent * * @throws XMPPException */ public <T extends Item> void send(T item) throws XMPPException { Collection<T> items = new ArrayList<T>(1); items.add((item == null ? (T)new Item() : item)); send(items); }
/** * Publishes an event to the node. This can be either a simple item * with no payload, or one with it. This is determined by the Node * configuration. * * If the node has <b>deliver_payload=false</b>, the Item must not * have a payload. * * If the id is null, an empty item (one without an id) will be sent. * Please note that this is not the same as {@link #send()}, which * publishes an event with NO item. * * This is a synchronous call which will throw an exception * on failure. * * For asynchronous calls, use {@link #publish(Item) publish(Item)}. * * @param item - The item being sent * * @throws XMPPException */ public <T extends Item> void send(T item) throws XMPPException { Collection<T> items = new ArrayList<T>(1); items.add((item == null ? (T)new Item() : item)); send(items); }
/** * Publishes an event to the node. This can be either a simple item * with no payload, or one with it. This is determined by the Node * configuration. * * If the node has <b>deliver_payload=false</b>, the Item must not * have a payload. * * If the id is null, an empty item (one without an id) will be sent. * Please note that this is not the same as {@link #send()}, which * publishes an event with NO item. * * This is a synchronous call which will throw an exception * on failure. * * For asynchronous calls, use {@link #publish(Item) publish(Item)}. * * @param item - The item being sent * * @throws XMPPException */ public <T extends Item> void send(T item) throws XMPPException { Collection<T> items = new ArrayList<T>(1); items.add((item == null ? (T)new Item() : item)); send(items); }
/** * Delete the items with the specified id's from the node. * * @param itemIds The list of id's of items to delete * * @throws XMPPException */ public void deleteItem(Collection<String> itemIds) throws XMPPException { List<Item> items = new ArrayList<Item>(itemIds.size()); for (String id : itemIds) { items.add(new Item(id)); } PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); SyncPacketSend.getReply(con, request); } }
/** * Delete the items with the specified id's from the node. * * @param itemIds The list of id's of items to delete * * @throws XMPPException */ public void deleteItem(Collection<String> itemIds) throws XMPPException { List<Item> items = new ArrayList<Item>(itemIds.size()); for (String id : itemIds) { items.add(new Item(id)); } PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); SyncPacketSend.getReply(con, request); } }
/** * Delete the items with the specified id's from the node. * * @param itemIds The list of id's of items to delete * * @throws XMPPException */ public void deleteItem(Collection<String> itemIds) throws XMPPException { List<Item> items = new ArrayList<Item>(itemIds.size()); for (String id : itemIds) { items.add(new Item(id)); } PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); SyncPacketSend.getReply(con, request); } }
return new Item(id, node);
return new Item(id, node);
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }