Question

I am trying to use Smack to publish an item with a payload to a pubsub node but I did not manage so far. I have created the node and set its configuration to deliver payload (setDeliverPayloads=true). I am using the send method to send the item with the payload.

 node.send(new PayloadItem(this.clientNodeName+"*" + System.currentTimeMillis(), new SimplePayload("my book", "books:pubsub:simple", "")));

Nevertheless the item is published without the payload. The constructed IQ does not also have the payload. As I can see from the smack's debug panel

This is what is constructed by smack and sent to the pubsub service (clearly there is no payload)

<iq id="1ha20-11" to="pubsub.127.0.0.1" type="set">
   <pubsub xmlns="http://jabber.org/protocol/pubsub">
   <publish node="autoIncrement">
       <item id="autoIncrement*1333380921970"/>
   </publish>
  </pubsub>
</iq>

I would appreciate any help to solve this issue. Of course I can still use native IQ messages but I will try to avoid this to utilize using the PubSubManager in the smack API as much as possible.

Was it helpful?

Solution

The code above does not have any problem. The only issue is that the example provided above does have an empty payload (SimplePayload("my book", "books:pubsub:simple", "")) therefore smack does not even show the item's payload at all.

Once the payload is specified then it will be included in the published item.

here is the code for publishing an item with a payload

  node.send(new PayloadItem(this.clientNodeName+"*" + System.currentTimeMillis(), new SimplePayload(load, "stage:pubsub:simple", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));

and this is the expected IQ sent to the Jabbered server

<iq id="OIqU4-12" to="pubsub.stage.127.0.0.1" type="set">
      <pubsub xmlns="http://jabber.org/protocol/pubsub">
        <publish node="autoIncrement">
          <item id="autoIncrement*1333438199718">
            <book xmlns="pubsub:test:book">
              <title>Lord of the Rings</title>
            </book>
          </item>
    </publish>
  </pubsub>
</iq>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top