How do you override an IQ provider?

Hi all,

I’‘m using Smack in a non-instant messaging application and I am trying to write providers to handle the necessary packets. I need to override Smack’‘s in-band registration (<query xmlns=’‘jabber:iq:register’’/> ) IQ packet handeler with one that suppports data forms (See JEP-0077 Section 5: http://www.jabber.org/jeps/jep-0077.html). How can I go about doing this? Is there a way besides changing the source code?

PS Smack is a great piece of software-- very useful.

-Matt

Matt,

Not sure how you are using Smack in a non-IM application, however I’'ll try to answer your inquiry. The upcoming Smack release supports data forms and they are already integrated with in-band registration. You will need to download the latest daily build in order to get this new feature.

Follow this sample code to learn how to obtain and complete an in-band registration’'s data form:

// Retrieve the form to fill out from the registration
    Form formToRespond = Form.getFormFrom(registration);
    // Obtain the form to send with the replies
    Form completedForm = formToRespond.createAnswerForm();
    completedForm.setAnswer("first", "John");
    completedForm.setAnswer("last", "Doe");
    completedForm.setAnswer("email", "john@mycomp.com");
    completedForm.setAnswer("x-gender", "M");

Follow this sample code to learn how to send a registration with a completed data form:

Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getHost());
    reg.setUsername(username);
    reg.setPassword(password);
    reg.setAttributes(attributes);
    // Add the completed data form to the registration
    reg.addExtension(completedForm.getDataFormToSend())
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }

Regards,

– Gato

Thanks Gato,

That worked perfectly. All I had to do was to download the daily build. I didn’'t have to change any code because I already had a packet extension provider written to handle simular forms embeded into presence packets. I love it when things work this well.

In case your curious, I and my coworkers are using Jabber as the comunications back bone in a research project we are doing. Our goal is to create a reusable instrumentation interfacing and integrating software for my company’'s experimental setups. By using XML, Jabber and sticking to protocols defined in JEPs, we can save time and effort by using code thats already exists-- such as Jabber servers and Smack. Even though all this was designed for IM, Jabber is useful for general data routing as well.

Thanks again for your help, and good software.

-Matt