igniterealtime / Openfire-Chat

Chat API (REST) for Openfire
https://discourse.igniterealtime.org/t/openfire-chat-api/68792
15 stars 8 forks source link

join rest api 500 error #11

Closed samusa123 closed 5 years ago

samusa123 commented 5 years ago

I am using the latest build: 0.9.5-release3

First I try to create a chat room with api /rest/api/restapi/v1/chatrooms

it gets http 201 response.

second I call the login api: /rest/api/restapi/v1/chat/{userName}/rooms/{roomName}

it gets http 200 response with the streamId

third when I call the join api PUT /rest/api/restapi/v1/chat/{streamId}/rooms/{roomName}

it returns http 500 with the following error message in log: 2019.05.24 16:37:42 org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper - IllegalArgumentException: Exception with ressource Exception

Note this error occurs if I make the 3 api calls right after each one.

If I have a delay of 10 seconds between login and join api call, there is no exception.

deleolajide commented 5 years ago

I have struggled to reproduce this issue. Here is my script run from the browser dev console on my local openfire server. It logins, joins 2 chat rooms and logs off with no errors

var url =  "https://desktop-545pc5b:7443/rest/api/restapi/v1/chat/dele/login";
var options = {method: "POST", body: "USER_PASSWORD", headers: {"authorization": "dCByJwX1L8Kt6NM8", "accept": "text/plain"}};

fetch(url, options).then(function(response){return response.text()}).then(function(streamId) 
{
    console.log("login ok", streamId);

    url =  "https://desktop-545pc5b:7443/rest/api/restapi/v1/chat/" + streamId + "/rooms/lobby";
    options.method = "PUT";  

    fetch(url, options).then(function(response)
    {
        console.log("join room lobby");

        url =  "https://desktop-545pc5b:7443/rest/api/restapi/v1/chat/" + streamId + "/rooms/post";

        fetch(url, options).then(function(response)
        {
            console.log("join room post");

            url =  "https://desktop-545pc5b:7443/rest/api/restapi/v1/chat/" + streamId + "/logoff";
            options.method = "POST";            

            fetch(url, options).then(function(response)
            {
                console.log("logoff ok");

            }).catch(function (err) {
                console.error('access denied error', err);
            });              

        }).catch(function (err) {
            console.error('access denied error', err);
        });    

    }).catch(function (err) {
        console.error('access denied error', err);
    });    

}).catch(function (err) {
    console.error('access denied error', err);
});
samusa123 commented 5 years ago

Yes, this is no issue.