Server unavailable response when sending custom IQ

I am trying to send custom information using IQ to asmack from Android.

So, I am using below code to send a custom IQ message.

public void onClick(View arg0) {

            CustomIQ req = new CustomIQ();
            req.myData="Hello world";
            req.setType(IQ.Type.GET);
            req.setTo(Activity_title+Constants.DOMAIN);
            MainActivity.connection.sendPacket(req);
            Log.d(Constants.TAG, "xml value :"+req.toXML());
        Log.d(Constants.TAG, "child element value :"+req.getChildElementXML());
            Log.d(Constants.TAG, " custom IQ req sent");

      

Below is my usual implementation of the IQ class:

import org.jivesoftware.smack.packet.IQ;

public class CustomIQ extends IQ {

    String myData;

    @Override
    public String getChildElementXML() {

        String request = "<query xmlns='myxmlns'>"
                        + "<myData>"+ myData + "</myData>"
                        + "</query>";

        return request;
    }

}


            }

      

But after submitting the custom IQ, I get the IQ listener as Service Unavailable and the error code as 503.

Below is the request to the server:

xml value :<iq id="BTn30-5" to="swathi@btp121374" type="get"><query xmlns='myxmlns'><myData>Hello world</myData></query></iq>
child element value :<query xmlns='myxmlns'><myData>Hello world</myData></query>

      

Below is the response from the server:

xml value :<iq id="BTn30-5" to="ganesh@btp121374/Smack" from="swathi@btp121374" type="error"><query xmlns='myxmlns'><myData>Hello world</myData></query><error code="503" type="CANCEL"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

      

So what is the reason why I am getting the response from the server as Service Unavailable.

Edit:

I have implemented IQProvider as shown below

public class customIQProvider implements IQProvider{

    @Override
    public IQ parseIQ(XmlPullParser parser) throws Exception {

        Log.d(Constants.TAG, "In custom IQ provider");
        CustomIQ myIQ_ref = new CustomIQ();


        int eventType = parser.next();

        while(eventType == XmlPullParser.START_TAG){

            switch(parser.getEventType()){
            case XmlPullParser.START_TAG:
            {
                if(parser.getName().equals("myData")){
                     myIQ_ref.myData=(parser.nextText());
                }
            }
            return myIQ_ref;
            }
        }

    return null;
    }

}

      

+3


source to share


2 answers


I believe you are breaking the iq routing rules in XMPP. If you send iq stanza to "swathi @ btp121374" you are not asking it to redirect to the client, you are asking the btp121374 server to handle it as swathi @ btp121374.

Given the submitting JID resource, I assume you want to submit "swathi @ btp121374 / Smack" or the like. Sending it to the full JID (JID including the resource) tells the server to redirect it to the client rather than handle it on its own.



(Note that the routing rules for presence, message and iq are different - the above only applies to iq)

+2


source


Obviously the server doesn't know how to handle the new namespace, unless you implement it on the server. What do you expect the server to do with your custom element?



Also, it is generally a bad idea to generate XML by concatenating strings. If myData

contains and <

or any other character to be escaped, your XML will be invalid. Smack certainly has better ways to generate your custom data.

0


source







All Articles