AnsweredAssumed Answered

Exception while calling createNode

Question asked by Aejaz on Oct 22, 2015
Latest reply on Dec 22, 2016 by nagibator2005

Hi,

 

I am using Smack 4.1.4 & followed this & this link to write a very

simple publisher class which creates a Node but am getting an

exception as follows. On server side I am using Tigase7.0.1 with

pubsub enabled.

 

Exception in thread "main" java.lang.ClassCastException: org.jivesoftware.smack.packet.UnparsedIQ cannot be cast to org.jivesoftware.smackx.pubsub.packet.PubSub

    at org.jivesoftware.smackx.pubsub.PubSubManager.sendPubsubPacket(PubSubManager.jav a:322)

    at org.jivesoftware.smackx.pubsub.PubSubManager.createNode(PubSubManager.java:146)

    at Publisher.createAndConfigureNode(Publisher.java:59)

    at Publisher.main(Publisher.java:31)

 

Following are the sent & received raw packets. It seems that server created the node successfully but

possibly I am doing something wrong in my code before the call to createNode().

 

Sent:

<stream:stream xmlns='jabber:client' to='dev2' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>ADcwMDc4NDMzOABvbmNvLmFua2l0</auth>

<stream:stream xmlns='jabber:client' to='dev2' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' id='b885af55-19e2-466b-92b1-b24ad182e676' xml:lang='en'>

<iq id='sbd2k-3' type='set'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>Smack</resource></bind></iq>

<iq id='sbd2k-5' type='set'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>

<iq id='sbd2k-7' type='get'><query xmlns='jabber:iq:roster'></query></iq>

<presence id='sbd2k-8'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='NfJ3flI83zSdUDzCEICtbypursw='/></presence>

<iq to='pubsub.dev2' id='sbd2k-11' type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub'><create node='testNode1'/><configure><x xmlns='jabber:x:data' type='submit'><field var='pubsub#access_model' type='list-single'><value>open</value></field><field var='pubsub#deliver_payloads' type='boolean'><value>1</value></field><field var='pubsub#notify_retract' type='boolean'><value>1</value></field><field var='pubsub#persist_items' type='boolean'><value>1</value></field><field var='pubsub#publish_model' type='list-single'><value>open</value></field></x></configure></pubsub></iq>

<iq to='dev2' id='tigase-ping' type='result'></iq>

<iq to='dev2' id='tigase-ping' type='result'></iq>

<iq to='dev2' id='tigase-ping' type='result'></iq>

 

Received:

<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='dev2' id='b885af55-19e2-466b-92b1-b24ad182e676' version='1.0' xml:lang='en'>

<stream:features><sm xmlns="urn:xmpp:sm:3"/><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism >ANONYMOUS</mechanism></mechanisms><ver xmlns="urn:xmpp:features:rosterver"/><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/></stream:features>

<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>

<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='dev2' id='b885af55-19e2-466b-92b1-b24ad182e676' version='1.0' xml:lang='en'>

<stream:features><sm xmlns="urn:xmpp:sm:3"/><register xmlns="http://jabber.org/features/iq-register"/><ver xmlns="urn:xmpp:features:rosterver"/><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>

<iq to="700784338@dev2/Smack" xmlns="jabber:client" type="result" id="sbd2k-3"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>700784338@dev2/Smack</jid></bind> </iq>

<iq to="700784338@dev2/Smack" xmlns="jabber:client" type="result" id="sbd2k-5"/>

<iq to="700784338@dev2/Smack" xmlns="jabber:client" type="result" id="sbd2k-7"><query xmlns="jabber:iq:roster"/></iq>

<presence from="700784338@dev2/Smack" xmlns="jabber:client" id="sbd2k-8" to="700784338@dev2"><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.igniterealtime.org/projects/smack" ver="NfJ3flI83zSdUDzCEICtbypursw="/></presence>

<iq to="700784338@dev2/Smack" from="pubsub.dev2" xmlns="jabber:client" type="result" id="sbd2k-11"><text>Created in 92 ms</text></iq>

 

 

Here is my code which configures & creates the node,

 

private static Node createAndConfigureNode(XMPPTCPConnection con){

        Node leaf=null;

        // Create a pubsub manager using an existing XMPPConnection

        PubSubManager mgr = new PubSubManager(con, "pubsub.dev2.xyz.com");

 

        // Create the node

        ConfigureForm form = new ConfigureForm(DataForm.Type.submit);

        form.setAccessModel(AccessModel.open);

        form.setDeliverPayloads(true);

        form.setNotifyRetract(true);

        form.setPersistentItems(false);

        form.setPublishModel(PublishModel.open);

        try {

             leaf = mgr.createNode("testNode2", form);

        } catch (NoResponseException | XMPPErrorException

                | NotConnectedException e) {

            e.printStackTrace();

        }

        return leaf;

    }

 

Can someone please take a look & let me know what am I doing wrong.

Outcomes