I'm using smack-experimental-4.1.0-beta2-SNAPSHOT. On Subscribing side, how get JsonPacketExtension from ConfigurationEvent?
To contrast, on the Publishing side, constructing a PayloadItem with JsonPacktExtension to send using LeafNode is easy:
JsonPacketExtension jasonPacketExtension = new JsonPacketExtension(myJsonObject.toString());
PayloadItem(itemId, node, jasonPacketExtension); //...now use LeafNode's send method.
//Subscriber side code is based on PubSub example provided with Smack download
PubSubManager mgr = new PubSubManager(connection);
LeafNode node = mgr.getNode("testNode");
NodeConfigCoordinator nodeConfigCoordinator = new NodeConfigCoordinator();
node.addConfigurationListener(nodeConfigCoordinator);
node.subscribe(subscriberJID);
ConfigureForm form = new ConfigureForm(DataForm.Type.submit);
form.setAccessModel(AccessModel.open);
form.setDeliverPayloads(true); //Want payload
form.setNotifyRetract(true);
form.setPersistentItems(true);
form.setPublishModel(PublishModel.open);
node.sendConfigurationForm(form);
/**
* .....Nested class in a continuously running service that waits for subscription payloads
*/
class NodeConfigCoordinator implements NodeConfigListener {
@Override
public void handleNodeConfiguration(ConfigurationEvent configurationEvent) {
List<PacketExtension> packetExtensions = (List<PacketExtension>) configurationEvent.getExtensions();
for (PacketExtension packetExtension : packetExtensions) {
JsonPacketExtension jpe =JsonPacketExtension.from(packetExtension); //<<<<< Compiler NOT happy. How extract the JSON from PacketExention?
//... Need to use jsonString contained in JaspnPackExtension
}
}
Error:(87, 61) java: method from in class org.jivesoftware.smackx.json.packet.JsonPacketExtension cannot be applied to given types;
required: org.jivesoftware.smack.packet.Packet
found: org.jivesoftware.smack.packet.PacketExtension
reason: actual argument org.jivesoftware.smack.packet.PacketExtension cannot be converted to org.jivesoftware.smack.packet.Packet by method invocation conversion