powered by Jive Software

Send IQ Packet And Listen This Packet Result

Hi guys.Sorry for my english.I’m from Turkey.

I send iq packet openfire server.This code;

private void sendIQPacket(final XMPPConnection connection,PacketTypeFilter filter) { new Thread(new Runnable(){ @Override public void run() { JsonObject mainList_Json = new JsonObject(); mainList_Json .addProperty( "cname", "org.detaysoft.atomic.detayopenfireplugin.processor.externalprocessor.subprocessor.Business"); mainList_Json.addProperty("mname", "getMainList"); mainList_Json.addProperty("usid", "P0741"); mainList_Json.addProperty("clid", "100"); byte[] encode = Base64 .encodeBase64(mainList_Json.toString().getBytes()); final String Json_Base64 = new String(encode); IQ iqPacket = new IQ() { @Override public String getChildElementXML() { return "<pvcommand>" + "<sendClassName>TumKullanicilar</sendClassName>" + "<sendMethodName>mainList</sendMethodName>" + "<spvcommand>" + Json_Base64 + "</spvcommand></pvcommand>"; } }; iqPacket.setType(IQ.Type.GET); iqPacket.setPacketID("pvrequest"); connection.sendPacket(iqPacket); Log.d("info", "IQ Paketin gönderildi"); } }).start(); }

and i want listen this packet result.i use this method;

public class IQInterceptor implements PacketInterceptor {           @Override
          public void interceptPacket(Packet packet) {
                    if(packet.getPacketID().equals("pvrequest")){
                              Log.d("interceptor",packet.toXML());
                    }
            } }

but i take this output.(this send me)

<iq id="pvrequest" type="get"><pvcommand><sendClassName>TumKullanicilar</sendClassName><sendMethodName>mainList</sendMethodName><spvcommand>eyJjbmFtZSI6Im9yZy5kZXRheXNvZnQuYXRvbWljLmRldGF5b3BlbmZpcmVwbHVnaW4ucHJvY2Vzc29yLmV4dGVybmFscHJvY2Vzc29yLnN1YnByb2Nlc3Nvci5CdXNpbmVzcyIsIm1uYW1lIjoiZ2V0TWFpbkxpc3QiLCJ1c2lkIjoiUDA3NDEiLCJjbGlkIjoiMTAwIn0=</spvcommand></pvcommand></iq>

i want this output(server send i see openfire interface).

SENT: <iq type="result" id="pvrequest" to="100#p0741@sivasdetay.com/Smack" from="sivasdetay.com"><pvcommand xmlns="detayopenfireplugin:iq:customiq"><spvcommand>jdMxDsIwDAXQu3ju4CR2HLMhwcACRS0T4iSIu0OXklRV9DdHeorybef5psdResource : Smack
0OdGBRjYJNNA0H+ff
MS7l+X69LTXTZ1jhvgmNGVkS78MUW2ghglALCB2EzFXgVEH3TRhWENape1AdhE17+m+UPxQ0TA9q
cRC6YTBnGBYQOgitnnUfRhSCDW9G2IfojYKGUbQ9Cs7aMhqmoGFKRiG4PQYvRQZTN/96C19f</spvcommand><sendClassName>TumKullanicilar</sendClassName><sendMethodName>mainList</sendMethodName></pvcommand></iq>

please help me

I am doing it like below (because Smack does it this way, too).

I guess Interceptor intercepts outgoing IQ packets, not incoming.

If you want incoming packets, either use a PacketListener or a PacketCollector.

connection.sendPacket(iq);

PacketFilter filter = new PacketIDFilter(iq.getPacketID());

PacketCollector collector = this.connection.createPacketCollector(filter);

Packet packet = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

if (packet == null) {

throw new XMPPException(“No response”);

}

if (packet.getError() != null) {

throw new XMPPException(packet.getError());

}

You might want to look up SyncPacketSend for simple request/response scenarios like this one. It gets rid of the need for this boilerplate code.