mardi 14 juin 2016

How to send and recieve Custom IQ packets smack android

Resume:

I'm trying to send and recieve Custom IQ packets in android app, usig smack.

Scenario:

I have to send a iq packet (IQP) to the server to tell it I need information. Then the server, when receives this IQP , sends another IQP containing a xml with that information.

Client:

<iq type="get" to="" id="8E6fp-X">
    <query xmlns="custom:iq:jira">
    </query>
</iq>

Server

<iq type="result" id="8E6fp-X" to="user@hostname/resource">
    <query xmlns="custom:iq:jira">
        {"projects":[
            {
            "id":"10000",
            "issues":[
                {
                "summary":"prueba",
                "id":"10000",
                "resporterDisplayName":"admin",
                "reporterName":"admin",
                "timespent":79200,
                "key":"TEST-1"
            }],
            "name":"test",
            "key":"TEST"}]}
    </query>
</iq>

After recover that information and show it to user, the user complete some information, and is sended to server again with IQP:

Client

<iq type="set" to="" id="9E6fd-P">
    <query xmlns="custom:iq:jira">
        {"issueKey":"TEST-1","comment":"TEST-1","started":"2016-05-02T16:49:01","timeSpentJiraString":"1h 30m"}
    </query>
</iq>

Server

<iq type="result" id="vMxdk-X" to="user@hostname/resource">
    <query xmlns="custom:iq:jira">
        201
    </query>
</iq>

Problem:

With all this informatio I searched how to implement this type of custom IQ , and found some links. But I'm bit confused, and blocked.

First of all I cretead a class extending from IQ:

public class CustomIQ extends IQ {

    private String id;
    private String ownXmlns = "custom:iq:jira";

    @Override
    public String getChildElementXML() {

        String request = "<query xmlns = 'custom:iq:jira'> </query>";
        return request;
    }
}

In the class I will use :

        ...
        // IQ PACKETS
        jiraIQ = new CustomIQ();
        jiraIQ.setType(IQ.Type.GET);
        jiraIQ.setTo("");

        if(mConnection != null){
            mConnection.sendPacket(jiraIQ);
            Toast.makeText(this, "IQ Sendend with id: "+ jiraIQ.getPacketID() + "--", Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(this, "Connection off", Toast.LENGTH_LONG).show();
        }

At this point I get lost. Is supossed I have to have some kid of listener to capture the IQP from the server, but I don't how to continue from these point.

I'll apreciate some kind of help, cause I'm really lost now

Aucun commentaire:

Enregistrer un commentaire