Project

General

Profile

Error starting server when default-config.groovy is invoked.

kodjo baah
Added almost 5 years ago

Hi,

I modified default-config.groovy i.e AS:Component: muc so that I could invoke the component:

Below is the code I used to invoke the component:

      import com.whatamidoing.services.xmpp.AddVhostAdHocCommand
          val jid ="muc@my"
          val node = "default-room-config"
          val setCommand = new AddVhostAdHocCommand(conn,node,jid)

          import org.jivesoftware.smackx.FormField
          import org.jivesoftware.smackx.Form
          import org.jivesoftware.smackx.packet.DataForm
          import org.jivesoftware.smackx.Form

         val submitDataForm = new DataForm(Form.TYPE_SUBMIT)

         val rn = new FormField("muc#roomconfig_roomname")
             rn.setType(FormField.TYPE_TEXT_SINGLE)
         rn.addValue("room9")
         rn.setLabel("Natural-Language Room Name")
         submitDataForm.addField(rn)

         val rd = new FormField("muc#roomconfig_roomdesc")
         rd.setLabel("Short Description of Room")
         rd.setType(FormField.TYPE_TEXT_SINGLE)
         rd.addValue("room description")
         submitDataForm.addField(rd)

         val persistRoom = new FormField("muc#roomconfig_persistentroom")
         persistRoom.addValue("1")
         persistRoom.setLabel("Make Room Persistent?")
         persistRoom.setType(FormField.TYPE_BOOLEAN)
         submitDataForm.addField(persistRoom)

         val pr = new FormField("muc#roomconfig_publicroom")
         pr.addValue("0")
         pr.setLabel("Make Room Publicly Searchable?")  
         pr.setType(FormField.TYPE_BOOLEAN)
         submitDataForm.addField(pr)

         val mr = new FormField("muc#roomconfig_moderatedroom")
             mr.addValue("0")
         mr.setLabel("Make Room Moderated?")
         mr.setType(FormField.TYPE_BOOLEAN)
         submitDataForm.addField(mr)

         val mo = new FormField("muc#roomconfig_membersonly")
         mo.addValue("0")
         mo.setLabel("Make Room Members Only?")
         mo.setType(FormField.TYPE_BOOLEAN)
         submitDataForm.addField(mo)

         val ppr = new FormField("muc#roomconfig_passwordprotectedroom")
         ppr.addValue("0")
         ppr.setLabel("Password Required to Enter?")
         ppr.setType(FormField.TYPE_BOOLEAN)
         submitDataForm.addField(ppr)

         val rs = new FormField("muc#roomconfig_roomsecret")
         rs.addValue("caldronburn")
         rs.setLabel("Password")
         rs.setType(FormField.TYPE_TEXT_SINGLE)
         submitDataForm.addField(rs)

         val anonymity = new FormField("muc#roomconfig_anonymity")
         anonymity.setLabel("Room anonymity level:")
         anonymity.addValue("fullanonymous")
         anonymity.setType(FormField.TYPE_TEXT_SINGLE)

         val cs = new FormField("muc#roomconfig_changesubject")
         cs.addValue("0")
         cs.setLabel("Allow Occupants to Change Subject?")
         cs.setType(FormField.TYPE_BOOLEAN)
         submitDataForm.addField(cs)

         val el = new FormField("muc#roomconfig_enablelogging")
         el.setLabel("Enable Public Logging?")
         el.setType(FormField.TYPE_BOOLEAN)
         el.addValue("0")
         submitDataForm.addField(el)

         val lf = new FormField("logging_format")
         lf.setType(FormField.TYPE_TEXT_SINGLE)
         lf.setLabel("Logging format")
         lf.addValue("html")

         val mu = new FormField("muc#roomconfig_maxusers")
         mu.addValue("0")
         submitDataForm.addField(mu)

         val hf = new FormField("muc#maxhistoryfetch")
         hf.setLabel("Maximum Number of History Messages Returned by Room")
         hf.setType(FormField.TYPE_TEXT_SINGLE)
         hf.addValue("50")
         submitDataForm.addField(hf)

         val whois = new FormField("muc#roomconfig_whois")
         whois.addValue("moderators")
         submitDataForm.addField(whois)

         val radmins = new FormField("muc#roomconfig_roomadmins")
         hf.addValue("admin@my")
         submitDataForm.addField(radmins)

             val submitForm: Form =  new Form(submitDataForm)

             setCommand.execute()
             import org.jivesoftware.smackx.Form
             var answer: Form = setCommand.getForm()
             var its = answer.getFields
             while(its.hasNext()) {
                val it = its.next()
                System.out.println("answer["+it.toXML()+"]")
             }
             setCommand.complete(submitForm)
      }

When I restarted the server..I got the error below:

java.lang.RuntimeException: Cannot match type java.lang.String[] to field type text_single
    at tigase.muc.RoomConfig.setValue(RoomConfig.java:400)
    at tigase.muc.RoomConfig.setValues(RoomConfig.java:412)
    at tigase.muc.RoomConfig.read(RoomConfig.java:368)
    at tigase.muc.repository.inmemory.InMemoryMucRepository.getDefaultRoomConfig(InMemoryMucRepository.java:182)

So I modified setValues, setValue, read in RoomConfig to print out the values being returned. Below is the output:

--key:muc#roomconfig_roomname
setValues:var=[muc#roomconfig_roomname] data=[1]
data[0]=room9
---form:muc#roomconfig_roomname = [] :class-of-data:class java.lang.String
--key:muc#roomconfig_roomdesc
setValues:var=[muc#roomconfig_roomdesc] data=[1]
data[0]=room description
---form:muc#roomconfig_roomdesc = [] :class-of-data:class java.lang.String
--key:muc#roomconfig_persistentroom
setValues:var=[muc#roomconfig_persistentroom] data=[1]
data[0]=1
---form:muc#roomconfig_persistentroom = [0] :class-of-data:class java.lang.String
--key:muc#roomconfig_publicroom
setValues:var=[muc#roomconfig_publicroom] data=[1]
data[0]=0
---form:muc#roomconfig_publicroom = [1] :class-of-data:class java.lang.String
--key:muc#roomconfig_moderatedroom
setValues:var=[muc#roomconfig_moderatedroom] data=[1]
data[0]=0
---form:muc#roomconfig_moderatedroom = [0] :class-of-data:class java.lang.String
--key:muc#roomconfig_membersonly
setValues:var=[muc#roomconfig_membersonly] data=[1]
data[0]=0
---form:muc#roomconfig_membersonly = [0] :class-of-data:class java.lang.String
--key:muc#roomconfig_passwordprotectedroom
setValues:var=[muc#roomconfig_passwordprotectedroom] data=[1]
data[0]=0
---form:muc#roomconfig_passwordprotectedroom = [0] :class-of-data:class java.lang.String
--key:muc#roomconfig_roomsecret
setValues:var=[muc#roomconfig_roomsecret] data=[1]
data[0]=caldronburn
---form:muc#roomconfig_roomsecret = [] :class-of-data:class java.lang.String
--key:muc#roomconfig_anonymity
setValues:var=[muc#roomconfig_anonymity] data=[1]
data[0]=semianonymous
---form:muc#roomconfig_anonymity = [semianonymous] :class-of-data:class java.lang.String
--key:muc#roomconfig_enablelogging
setValues:var=[muc#roomconfig_enablelogging] data=[1]
data[0]=0
---form:muc#roomconfig_enablelogging = [0] :class-of-data:class java.lang.String
--key:logging_format
setValues:var=[logging_format] data=[1]
data[0]=html
---form:logging_format = [html] :class-of-data:class java.lang.String
--key:muc#roomconfig_changesubject
setValues:var=[muc#roomconfig_changesubject] data=[1]
data[0]=0
---form:muc#roomconfig_changesubject = [0] :class-of-data:class java.lang.String
--key:muc#maxhistoryfetch
setValues:var=[muc#maxhistoryfetch] data=[2]
data[0]=50
data[1]=admin@my
---form:muc#maxhistoryfetch = [50] :class-of-data:class [Ljava.lang.String;
java.lang.RuntimeException: Cannot match type java.lang.String[] to field type text_single

You will notice the even though maxhistoryfetch was defined as text_single when it was invoked via the add hoc command it got populated

with two values.

Had to make the following modification to the setValues to get the server to start.

else if (data instanceof String[] && (f.getType() == FieldType.text_single)) {
            String[] d = (String[]) data;
            f.setValues(new String[] { d[0]});
}

I then went about creating my own add hoc script to create a new room...see attached..

Everthing seems to work well..but I can not find information in the database about the new room created.

When I called the default-config script it populated the tig_node and tig_pairs with the values. I was expecting

the same.


Replies (5)

(1)

Added by kodjo baah almost 5 years ago

There a few errors in the example above, I was not getting the right jid for the room..so modified the addhoc script to add the roomjid in the list of fields that are sent back to the server:

         val rmJid = new FormField("room-jid")
             rmJid.setType(FormField.TYPE_TEXT_SINGLE)
         rmJid.addValue(roomJid)
         rmJid.setLabel("Room Jid")
         submitDataForm.addField(rmJid)

Then in the add-room.groovy I added the following:

      def jidForRoom = Command.getFieldValue(p,"room-jid");
    def frm = new Form(x);
    tigase.xmpp.BareJID roomJid = BareJID.bareJIDInstance(jidForRoom);

It appears that create just over rights the previous values created by default-config.groovy. I was expecting to see a new entry for each room..with some unique prefix as the determinant: ie. the roomjid...as an example pkey value would like roomJid:muc#roomconfig_roomname instead you just have muc#roomconfig_roomname.

I am also getting the following WARNINGS:

[in_0-muc]         Form.copyValuesFrom()              WARNING:  Field muc#roomconfig_maxusers is not declared in form 'null'!
[in_0-muc]         Form.copyValuesFrom()              WARNING:  Field muc#roomconfig_whois is not declared in form 'null'!

These values are not defined in RoomConfig

(1)

Added by kodjo baah almost 5 years ago

It appears there were errors within the script that are only detected if you use a tool like psi. When the scripts are invoked using a client like smack the errors are not reported.

Below is the fix for the add-room.

/*
 Adds a new room
 AS:Description: Add a new room
 AS:CommandId: ad-new-room
 AS:Component: muc
*/

package muc.admin;

import tigase.form.Form;
import tigase.form.Field;
import tigase.xml.Element;
import tigase.muc.MUCComponent;
import tigase.muc.repository.IMucRepository;
import tigase.muc.RoomConfig;
import tigase.muc.Room;
import tigase.server.Command;
import tigase.server.Iq;
import tigase.server.Packet;
import tigase.xmpp.BareJID;
import tigase.xmpp.JID;

def SUBMIT = "submit";

def mucRepositoryModule = (IMucRepository)mucRepository;
def Iq p = (Iq)packet;
def admins = (Set)adminsSet

def roomName = Command.getFieldValue(p,RoomConfig.MUC_ROOMCONFIG_ROOMNAME_KEY)

def stanzaFromBare = p.getStanzaFrom().getBareJID()
def isServiceAdmin = admins.contains(stanzaFromBare)
if (!isServiceAdmin) {
    def result = p.commandResult(Command.DataType.result)
    Command.addTextField(result, "Error", "You do not have enough permissions to access this data.");
    return result
}

def xform = Command.getData(p, "x", "jabber:x:data");
def submit = xform==null?false:xform.getAttributeStaticStr("type")==SUBMIT;

if (submit) {
    def command = p.getElement().getChild("command", "http://jabber.org/protocol/commands");

    def x = command.getChild("x", "jabber:x:data");

        def jidForRoom = Command.getFieldValue(p,"room-jid");
    def frm = new Form(x);
    tigase.xmpp.BareJID roomJid = BareJID.bareJIDInstance(jidForRoom);

    System.out.println("---kodjoRoomJid--"+roomJid.toString());

        def ownerJid = Command.getFieldValue(p,"owner-jid");
    def creatorJid = BareJID.bareJIDInstance(ownerJid);
    System.out.println("---kodjoRoomJidCreator--"+creatorJid.toString());

    def jid = JID.jidInstance(creatorJid,"Muc");
    def room = mucRepositoryModule.createNewRoom(roomJid,jid);
    def roomConfig = room.getConfig();
    roomConfig.copyFrom(frm);

    return "Created a new room";

} else if (!submit) {
    def res = (Iq)p.commandResult(Command.DataType.form)
    def command = res.getElement().getChild("command", "http://jabber.org/protocol/commands");
    def x = command.getChild("x", "jabber:x:data");
    command.removeChild(x);

    def df = mucRepositoryModule.getDefaultRoomConfig().form;

    def frm = new Form(x);

    def el = new Element("field");
    el.addAttribute("var","room-jid")
    el.addAttribute("type",Field.FieldType.text_single.toString());
    el.addAttribute("label","Room Jid");
    el.addAttribute("desc","The JID for the room");
    def ff = new Field(el);
    frm.addField(ff);

    def elForOwner = new Element("field");
    elForOwner.addAttribute("var","owner-jid")
    elForOwner.addAttribute("type",Field.FieldType.text_single.toString());
    elForOwner.addAttribute("label","Owner Jid");
    elForOwner.addAttribute("desc","The JID of the owner of the room");
    def ffOwner = new Field(elForOwner);
    frm.addField(ffOwner);

    for (fld in df.getAllFields()) {
        frm.addField(fld);
    }


    frm.copyValuesFrom(df);

    command.addChild(frm.getElement());

    return res;
}

When this is invoked in psi it creates an entry in tig_node using the jid for the room and also creates the room configuration data in tig_pairs. The pkey values are exactly the same as those created when the default-config was called.

Unfortunately I can not log in to the room.

(1)

Added by kodjo baah almost 5 years ago

The command id should be changed to.

(1)

Added by Wojciech Kapcia TigaseTeam almost 5 years ago

About first issue with double values. There is an error in your script:

         val hf = new FormField("muc#maxhistoryfetch")
         hf.setLabel("Maximum Number of History Messages Returned by Room")
         hf.setType(FormField.TYPE_TEXT_SINGLE)
         hf.addValue("50")
         submitDataForm.addField(hf)

         val whois = new FormField("muc#roomconfig_whois")
         whois.addValue("moderators")
         submitDataForm.addField(whois)

         val radmins = new FormField("muc#roomconfig_roomadmins")
         hf.addValue("admin@my")
         submitDataForm.addField(radmins)

Please note the last-but-one line (12) - you basically add second value (@hf.addValue("admin@my")@ to the maxhistory fields which causes issues and there is no need to fix MUC component code!

kodjo baah wrote:

Unfortunately I can not log in to the room.

How so? Any errors in the logs or error returned from the server?

(1)

Added by kodjo baah almost 5 years ago

All is working...I am able to enter the room.

    (1-5/5)