I am trying to send custom information with IQ in asmack from android.
So I am using below code to send the 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 custom IQ class implementation:
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 the sending the custom IQ, I am getting in the IQ listener as Service Unavailable and error code as 503.
Below are the request to 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 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 for I am getting response from server as Service Unavailable.
Edit:
I implemented the IQProvider as 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;
}
}