0
votes

I am new to Openfire and smack, therefore I have questions regarding pubsub feature. Actually, I have created a node with setAccessModel as authorize, shown below.

PubSubManager mgr = new PubSubManager(xmpp.getConnection());
try {
    LeafNode leaf = mgr.createNode("testNode");
    ConfigureForm form = new ConfigureForm(DataForm.Type.submit);
    form.setAccessModel(AccessModel.authorize);
    form.setDeliverPayloads(true);
    form.setNotifyRetract(true);
    form.setPersistentItems(true);
    form.setPublishModel(PublishModel.open);
    leaf.sendConfigurationForm(form);
} catch (SmackException.NoResponseException e) {
        e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
        e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
        e.printStackTrace();
}

My question is that when somebody wants to subscribe to above node, how the owner of this node can handle the subscription request? Subscription part is as follows:

PubSubManager mgr = new PubSubManager(xmpp.getConnection());

// Get the node
LeafNode node = null;
try {
     node = mgr.getNode("testNode");
     node.addItemEventListener(new ItemEventCoordinator());
     node.subscribe(senderUser+"@desi.loc");
    } catch (SmackException.NoResponseException e) {
        e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
        e.printStackTrace();
    } catch (SmackException.NotConnectedException e) {
        e.printStackTrace();
    }

class ItemEventCoordinator  implements ItemEventListener {
    @Override
    public void handlePublishedItems(ItemPublishEvent items) {
        final ItemPublishEvent itemstemp=items;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //stuff that updates ui
                    dspySub.setText("Item: " + itemstemp.getItems());
            }
        });
    }
}

When I set form.setAccessModel(AccessModel.open) every thing works fine. Users can publish and subscribe easily but when its AccessModel is authorize, owner don't listen, or might be I don't know how to handle subscription request at owner side with above piece of code. Kindly guide me.

1

1 Answers

0
votes

Jawad, I've just replied another guy' question about listening subscription requests. Please take a look:

How can i listen incoming subscription request in smack openfire android

I really hope that it can help you.

Good luck!

PS.: Sorry, but I haven't enough reputation to do a comment :(