通过 Ajax 在 apache openmeetings API 中添加新用户不起作用

Add new user in apache openmeetings API via Ajax does not work

我正在使用 apache api openmeetings。当我尝试添加新用户时,我在 openmeetings 日志中收到 HTTP 响应错误 500 和以下错误:

ERROR 09-06 11:18:00.938 22023 230 o.a.o.w.UserWebService [0.0-5080-exec-2] - addNewUser
java.lang.NullPointerException: null
        at org.apache.openmeetings.webservice.UserWebService.add(UserWebService.java:171)

这是我的代码:

function create_user() {

  $.ajax({
    method: "POST",
    url: "http://localhost:5080/openmeetings/services/user?sid=28647b3d-ffe2-4c1b-9835-9856b6c3d11b",
    data: {
      user: JSON.stringify({
        address: {
          country: "IT",
          deleted: false,
          email: "test@test.com",
          id: "2"
        },
        externalId: "1",
        externalType: "myCMS",
        firstname: "Test",
        id: "2",
        languageId: "5",
        lastname: "Prova",
        login: "Test",
        password: "Prova1*",
        rights: null,
        timeZoneId: "Europe/Rome",
        type: "user"
      }),
      confirm: false
    },
    dataType: "json",
    success: function(data) {
      consol.log(data);
    }
  });
}

好的,这在 OM 3.3.1 中显然是糟糕的设计:(

userconfirm参数都被注释为@QueryParam(应该是@FormParam

所以你必须这样调用它:

$.ajax({
method: "POST",
url: "http://localhost:5080/openmeetings/services/user?sid=28647b3d-ffe2-4c1b-9835-9856b6c3d11b&user=" + escape(JSON.stringify({
    address: {
      country: "IT",
      email: "test@test.com"
    },
    externalId: "1",
    externalType: "myCMS",
    firstname: "Test",
    languageId: "5",
    lastname: "Prova",
    login: "testX879",
    password: "ACDfium1*",
    timeZoneId: "Europe/Rome",
    type: "user"
  })) + '&confirm=false',
data: {},
dataType: "json",
success: function(data) {
  consol.log(data);
}
});

这很丑陋,肯定会在 3.3.2+ 中修复

这是 JIRA:https://issues.apache.org/jira/browse/OPENMEETINGS-1693