powered by Jive Software

Custom provider for subscribe authorization

I am trying to create a provider extension for following stanza as this feature is not available in smack yet. its a feature to handle incoming subscription permission.

PubSub subscriber request

Use the following form to approve or deny the subscription request.

                 <value>[http://jabber.org/protocol/pubsub#subscribe_authorization](http://jabber.org/protocol/pubsub#subscribe_authorization)</value>

9QojXw0GKibSGF6eu5xOzurK8m2iFMp9jJcO4llb

fdf72c24/loc

                 <value>88f37b90@example.com</value>

0

I have created custom PacketExtensionProvider and PacketExtension to handle above xml stanza but the issue is when i add Privoder as follows

pm.addExtensionProvider(

“x”,

“jabber:x:data”,

new com.bcl.provider.SubFormProvider());

this provider overlaps with the default DataFormProvider

pm.addExtensionProvider(

“x”,

“jabber:x:data”,

new org.jivesoftware.smackx.provider.DataFormProvider());

so is there a way to **differentiate between DataFormProvider and SubFormProvider ( custom provider) ** so that i can handle above xml stanza like the smack does.

Can anyone help me here ?

even if i prepare objects which contain above xml stanza how will i send the data to the server ?

You don’t want to do it that way. The form will already be read into a Form instance, and you cannot distinguish this one from any other as they all use the same namespace. This would be a bad thing and potentially break every other Form received.

There is no need to create your own provider here at all. It looks to me like you should simply create a packet listener with a filter that checks for

There are existing filters for from and extension, you could extend one of those and add the other two checks.

I have tried it as follows but the issues is when i get the DefaultPacketExtension it doesnt print anything.

i am using DefaultPacketExtension so that can set few values and send the packet back to the server

is am i doing anything wrong ?

PacketFilter filterx = new AndFilter(new PacketTypeFilter(org.jivesoftware.smack.packet.Message.class),

new FromContainsFilter(“pubsub.example.com”));

PacketListener myListener = new PacketListener(){

    @Override

public void processPacket(Packet packet) {

if(packet instanceof org.jivesoftware.smack.packet.Message){

org.jivesoftware.smack.packet.Message msg = (org.jivesoftware.smack.packet.Message) packet;

DefaultPacketExtension subExtension = (DefaultPacketExtension) msg.getExtension( “jabber:x:data”);

** //MY CODE DOESNT PRINT ANYTHING OVER HERE **

System.out.println(“ELEMENT” + subExtension.getElementName()+ “”);

}

}

};

cxmpp.addPacketListener(myListener, filterx);

even i tried to loop for all the extension and i can see the stanza but

Collection pk = msg.getExtensions();

         for(PacketExtension packetExtension:pk)

System.out.println("DATA " + " "+ packetExtension.toXML());

Message was edited by: nihar

@ @rcollier

Any help over this ?

Till now i tried to parse the packet manually using XmlPullParser , but that thing is quite tedious and as existing extension are avilable then packet parsring would not be the proper solution.

but when ever i try to cast existing extension from PacketExtension , it doesnt work i dont know why ,

moreover i have created one class which implements PacketExtension and override the default methods and later on i tried to cast it from PacketExtension using packet.getExtension() / msg.getExtension() but that didnt work too , it prints nothing

You shouldn’t be getting a DefaultPacketExtension, it should return a DataForm already. That is

DefaultPacketExtension subExtension =  (DefaultPacketExtension) msg.getExtension( "jabber:x:data");

Should throw a ClassCastException since that extension should be parsed into a DataForm. The fact that it isn’t indicates that you are not including the smack.providers file in your classpath.

Yeah , DataForm worked

how about modifying the xml stanza value and send it back to the server to the the afftermatite permission to the subscriber

i have seen one method in **ConfigForm **i.e. **createAnswerForm **which creates a xml frame for the config form and later one we can set the values accordinly and send it to the server.

so is there any way in a DataForm so that i can send the data to the server after setting few Values in it like

for pubsub#allow" i can set **1 **