powered by Jive Software

PubSub GetItemsRequest maxItemsToReturn not implemented

In the class org.jivesoftware.smackx.pubsub.GetItemsRequest constructor GetItemsRequest(String nodeId, String subscriptionId, int maxItems) the local variable maxItems is never set to the argument. I fixed the code locally and reran, but it seems that maxItems is still ignored and the openfire server returns every message that has been published to a node as opposed to the last X (maxItems). Is this a known bug?

Thanks!

Charles Harvey

There are actually three bugs in the class GetItemsRequest:

  1. org.jivesoftware.smackx.pubsub.GetItemsRequest constructor GetItemsRequest(String nodeId, String subscriptionId, int maxItems) the local variable maxItems is never set to the argument maxItems.

  2. in toXml, in the block if (getSubscriptionId() != null) the xml should not be ended - builder.append("’/>"); should be builder.append("’ ");

  3. in toXml, in the block if (getMaxItems() > 0) the xml should not be ended - builder.append("’/>"); should be builder.append("’ ");

Cheers,

Charles

Logged as **SMACK-308. Thanks for reporting them.
**

Fixed

Thank you so very much. I have one more question, hopefully the last for a while. When I attempted to use LeafNode.getItems(Collection ids) openfire responded that it needed a subscription id… in order to make that happen, I had to add another couple of methods to LeafNode and a constructor to ItemsExtension - they could probably be overloads but I did not want to mess with the existing code until I knew if I was just missing something.

In any case, here is what I did to get LeafNode.getItems(Collection ids) to work with my openfire:

Class ItemsExtension

Add protected String subscriptionId;

Add following method:

public ItemsExtension(ItemsElementType itemsType, String nodeId, List<? extends PacketExtension> items, String subscriptionId)
{
super(itemsType.getNodeElement(), nodeId);
type = itemsType;
this.items = items;
this.subscriptionId = subscriptionId;
}

In method toXML() add block shown below after first instance of builder.append(getElementName()):

if (subscriptionId != null)
{
builder.append(" subid=’");
builder.append(subscriptionId);
builder.append("’ ");
}

Class LeafNode

Add following method:

public List getItems(Collection ids, String subscriptionId)
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, subscriptionId));

PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
return (List)itemsElem.getItems();
}

Thank you for your time,

Charles Harvey

Well, there are 2 potential issues here. One, is that I missed the case for the getItems(Collection ids, String subid), which you have added.

The other is if you only have 0 or 1 subscription. Then you are running into a bug (OF-5) which has already been fixed in OpenFire. You should only require a sub id when you have more than one subscription. Unfortunately, you won’t get the fix until a new version is released.

I will try adding the missing method tomorrow, since it should only take an hour or so.