IQ / Packet extensions

Dear Gato

Was busy the last few days fixing some other code. I have tried around but there is no other public server that is giving the same reply and I am trying this on a private server. There is no documentation or complete sources for this

The following is the reply :

testjabber:iq:conference< /item>

How could I read in this entire XML using Smack, considering that I am not able to make the Extensions work !

-Rajesh

Dear Gato

I have been doing some debugging today and find the following:

The parseIQ method inside the PacketReader class is being called, is this normal considering that I have a parse method inside my provider class.

Further I find that the parseIQ method inside PacketReader throws the following exception (if I wrap it in a try… catch)

java.net.SocketException: socket closed

Am I heading towards anything here, could there be anything wrong with the server result XML. I already have doubts on the extra tag on the result XML.

I am pasting the debug again on this post, you can see the the extra at the end just before the .

I have taken care of this on my Provider class other wise that would fail too

Demojabber:iq:conferencetestjabber:iq:conference

Should I do something on this.

-Rajesh

Is there really an extra ? It seems to nest like this, which looks well-formed to me:

<iq from="conferencing" id="Livd6-4" to="kcr@rajesh/Smack"
     type="result" xmlns="jabber:client">
   <item category="service" jid="conferencing" name="conferencing"
       type="conference" xmlns="jabber:iq:browse">
     <item category="conference" jid="demo@rajesh" memberCount="0"
         name="demo" type="public">
       Demo<ns>jabber:iq:conference</ns>
     </item>
     <item category="conference" jid="test@rajesh" memberCount="0"
         name="test" type="public">
       test<ns>jabber:iq:conference</ns>
     </item>
   </item> </iq>

Dear Kcounsell,

Yes it does look well formed, thanks for pointing it out !

I have been spending too much time poking around my Provider class and the PacketReader class.

Guess it is back to it now.

-Rajesh

Dear All

I have finally made my extension work, I feel that I have done something non standard but makes my code work but I would need to maintain my own version of PacketReader. The following code sinppet shows the change I have done on the org.jivesoftware.smack.PacketReader class:

// Otherwise, see if there is a registered provider for
       // this element name and namespace.
                else {
                    Object provider = ProviderManager.getIQProvider(elementName, namespace);
                    if (provider != null) {
                        if (provider instanceof IQProvider) {
                            iqPacket = ((IQProvider)provider).parseIQ(parser);
                            if(iqPacket instanceof RoomInfo) // My packet class
                            {
                               done = true;      // if this is left a     //java.net.SocketException:     //Socket operation on nonsocket:     //recv failed will be thrown                             }                              }
                        else if (provider instanceof Class) {
                            iqPacket = (IQ)parseWithIntrospection(elementName,
                                    (Class)provider, parser);
                        }
                    }
                }

Now my PacketCollector picks up the Packet, I get an Iterator of my packets and use the inner class to display them.

But is this something to be fixed elsewhere ? looking at the XML outline is the tag contained within the tag creating any issue ?

Is there some other response that follows with similar tag names ? This could be used as a test case.

FYI : This was done with the 5th Jan 2004 Build.

-Rajesh

Message was edited by: rajesh - too wide

Dear Gato

I guess you must be away, please let me know on how we could work on the above ? Do you want a copy of my current classes ?

-Rajesh

Rajesh,

As you guessed I was away on vacations. From your posts I see that you are having a “java.net.SocketException: socket closed”. My first question is who is closing the connection? Is it Smack or the server? I guess that this exception is being thrown by Smack while parsing the XML and therefore Smack closes the connection. If this is the case then you should pursue the original exception that is causing all this problem.

If you are still having problems after catching the original exception then you can send me all your classes and smack.provider configuration to my account at yahoo.

Regards,

– Gato

Dear Gato

Still at the problem , I am mailing the files to you, thanks.

-Rajesh

Rajesh,

I have good news for you. I just took a look at your code and found the problem. The problem is that your RoomInfoProvider is parsing the whole IQ packet.

An IQProvider should stop parsing when the IQ sub-document has finished. In your case the IQ sub-document finishes with the last . Going directly to the code, replace the following code in RoomInfoProvider

if (parser.getName().equals("iq")) {
        done = true;
    }

with this code (sample code)

else if (parser.getName().equals("item") && tagStart == false) {
        done = true;     }

Since you were parsing the whole IQ document the PacketReader never realized where the IQ ends and therefore your PacketCollector never got the packet.

Regards,

– Gato

Dear Gato

It works now

So the lesson here is that a IQProvider is passed only the IQ subdocument, is this always true ?

-Rajesh

Rajesh,

It works now

Great!

So the lesson here is that a IQProvider is passed

only the IQ subdocument, is this always true ?

Yep, this is always true. Below you will find the comment of the method IQProvider.parseIQ(XmlPullParser parser) that specifies this requirement.

/**
     * Parse the IQ sub-document and create an IQ instance. Each IQ must have a
     * single child element. At the beginning of the method call, the xml parser
     * will be positioned at the opening tag of the IQ child element. At the end
     * of the method call, the parser <b>must</b> be positioned on the closing tag
     * of the child element.
     *
     * @param parser an XML parser.
     * @return a new IQ instance.
     * @throws Exception if an error occurs parsing the XML.
     */
    public IQ parseIQ(XmlPullParser parser) throws Exception;

Regards,

– Gato