powered by Jive Software

IQ sent different from the IQ received :(

Hello,

i implemented an IQ in the webchat of fastpath and an IQHandler in my plugin in the server.

The problem that the result sent in HandleIQ from the server in IQHandler is different from the result received by the collector :

this is what i sent in the IQHandler :

C2S - RECV (17081603): ttttt.tttt@gmail.com

C2S - SENT (17081603):

404

and this is what i received in the IQ :

RECEIVED XML :

did i forget something ? Or there is another way to implement each of IQ and IQHandler.

thank you for reading !

this is the IQ :

package org.jivesoftware.webchat; import java.io.IOException;
import java.io.StringReader;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory; /** * * @author The Extremist */
public class IQUserAccess extends IQ {     private XMPPConnection connection;
    private String emailAddr;
    private boolean isAllowed = false;     public boolean isAllowed() {
        return isAllowed;
    }     public synchronized void SendQuery() throws XMPPException, XmlPullParserException, IOException {
        this.setType(IQ.Type.GET);
        this.setTo(connection.getServiceName());         PacketFilter filter = new AndFilter(new PacketIDFilter(this.getPacketID()),
                new PacketTypeFilter(IQ.class));
        PacketCollector collector = connection.createPacketCollector(filter);         connection.sendPacket(this);
        IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        // Stop queuing results
         collector.cancel();         if (result == null) {
            isAllowed = false;
            throw new XMPPException("No response from server.");
        } else if (result.getType() == IQ.Type.ERROR) {
            isAllowed = false;
            throw new XMPPException(result.getError());
        } else {             System.out.println("RECEIVED XML "+result.toXML());
//            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
//            factory.setNamespaceAware(false);
//            XmlPullParser xpp = factory.newPullParser();
//            xpp.setInput(new StringReader(result.toXML()));
//            int eventType = xpp.getEventType();
//            while (eventType != XmlPullParser.END_DOCUMENT) {
//                    System.out.println(xpp.getText());
//
//
//
//            }         }
    }     public IQUserAccess(String email) {         emailAddr = email;
        connection = ChatManager.getInstance().getGlobalConnection();
        try {
            SendQuery();
        } catch (Exception ex) {
            // Logger.getLogger(IQUserAccess.class.getName()).log(Level.SEVERE, null, ex);
        }     }     @Override
    public String getChildElementXML() {
        StringBuilder buf = new StringBuilder();
        buf.append("<email-exists xmlns=\"http://jabber.org/protocol/email-exists\">");
        buf.append(emailAddr);
        buf.append("</email-exists>");
        return buf.toString();     }
}

And this is my IQHandler :

import com.oceanys.utils.CheckIfEmailExists;
import org.dom4j.Element;
import org.jivesoftware.openfire.IQHandlerInfo;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.handler.IQHandler;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError.Condition; /** * * @author The Extremist */
public class IQHandlerReturningClient extends IQHandler {     private IQHandlerInfo info;
    private String serverName;     public IQHandlerReturningClient() {
        super("email-exists");
        info = new IQHandlerInfo("email-exists", "http://jabber.org/protocol/email-exists");
    }     public IQ handleIQ(IQ packet) throws UnauthorizedException {         IQ result = IQ.createResultIQ(packet);         Element iq = packet.getChildElement();         String emailAddr = null;
        if (iq.getName().equals("email-exists")) {
            emailAddr = (String) iq.getData();
        }
        if (emailAddr != null) {
            try {
                if (CheckIfEmailExists.exists(emailAddr)) {
                   result.setChildElement("emailexists","http://jabber.org/protocol/email-exists").setText("200");
                                   } else {
                   result.setChildElement("emailnotfound","http://jabber.org/protocol/email-exists").setText("404");
                }
            } catch (Exception ex) {
                result.setError(Condition.bad_request);
            }
        } else {
            result.setError(Condition.bad_request);
        }
               return result;
    }     public IQHandlerInfo getInfo() {
        return info;
    }     @Override
    public void initialize(XMPPServer server) {
        super.initialize(server);
        serverName = server.getServerInfo().getXMPPDomain();
    }
}