Project

General

Profile

Script always returns an empty response

Igor Khomenko
Added about 4 years ago

Hi there,

I have next script to modify the admin list of a room

import tigase.http.rest.Service
import tigase.server.Iq
import tigase.server.Packet
import tigase.xml.Element
import tigase.xmpp.StanzaType

class UpdateRoomOccupantsHandler extends tigase.http.rest.Handler {

    public UpdateRoomOccupantsHandler() {
        regex = /\/update_room_members/
        requiredRole = "admin"
        isAsync = false

        execPost = { Service service, callback, user, content ->

            def adminJid = content["admin_jid"]
            def roomJID = content["room_jid"]
            def usersJids = content["user_jids"]
            def commandType = content["type"]

            def iqElement = new Element("iq")
            iqElement.addAttribute("type", "set")
            def rand = Math.abs(new Random().nextInt() % 9999999) + 1
            iqElement.addAttribute("id", "" + rand)
            iqElement.addAttribute("from", adminJid)
            iqElement.addAttribute("to", roomJID)
            //
            def queryElement = new Element("query")
            queryElement.setXMLNS("http://jabber.org/protocol/muc#admin")
            // process users
            for (def userJid : usersJids) {
                def itemElement = new Element("item")
                itemElement.addAttribute("affiliation", commandType == "push" ? "admin" : "outcast")
                itemElement.addAttribute("jid", userJid)
                queryElement.addChild(itemElement)
            }
            //
            iqElement.addChild(queryElement)

            service.sendPacket(new Iq(iqElement), 10, {Packet result ->

                if (result == null || result.getType() == StanzaType.error) {
                    callback("422");
                    return;
                }

                callback("200");
            });
        }
    }
}

Something strange happens. It works, but almost all the time I receive Status 200 and an empty body

I don't receive "200" or "422" string

Is there something that we have to add?

thanks


Replies (1)

    (1-1/1)