发送自定义IQ时来自服务器的服务不可用响应 [英] service unavailable response from server while sending custom IQ

查看:123
本文介绍了发送自定义IQ时来自服务器的服务不可用响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过android在asmack中发送具有IQ的自定义信息.

I am trying to send custom information with IQ in asmack from android.

因此,我正在使用以下代码发送自定义IQ消息.

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");

以下是我的自定义IQ类实现:

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;
    }

}


            }

但是在发送自定义IQ之后,我进入IQ侦听器,显示为Service Unavailable,错误代码为503.

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.

我实现了如下的IQProvider

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;
    }

}

推荐答案

我相信您对XMPP中的iq路由规则不满意.如果将iq节发送到"swathi @ btp121374",则不是要将其路由到客户端,而是要btp121374服务器代表swathi @ btp121374处理它.

I believe you're falling foul of the iq routing rules in XMPP. If you send an iq stanza to "swathi@btp121374", you're not asking it to be routed to a client, you're asking the btp121374 server to handle it on behalf of swathi@btp121374.

鉴于发送JID的资源,我想您想发送到"swathi @ btp121374/Smack"或类似的文件.将其发送到完整的JID(包括资源的JID)会告诉服务器将其路由到客户端,而不是自己处理.

Given the resource of the sending JID, I imagine you want to send to "swathi@btp121374/Smack" or similar. Sending it to the full JID (JID including resource) tells the server to route it to the client instead of handling it itself.

(请注意,状态,消息和iq的路由规则不同-以上仅适用于iq)

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

这篇关于发送自定义IQ时来自服务器的服务不可用响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆