Commit 9374ba71 authored by daryl herzmann's avatar daryl herzmann

Merge pull request #282 from Redor/master

Update the REST API plugin to 1.1.4
parents 4235cb26 68abcf32
......@@ -44,6 +44,11 @@
REST API Plugin Changelog
</h1>
<p><b>1.1.4</b> -- August 19th, 2015</p>
<ul>
<li>Added: get concurrent sessions (local or cluster wide)</li>
</ul>
<p><b>1.1.3</b> -- August 15th, 2015</p>
<ul>
<li>Added: get count of users unread messages</li>
......
......@@ -5,8 +5,8 @@
<name>REST API</name>
<description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author>
<version>1.1.3</version>
<date>08/15/2015</date>
<version>1.1.4</version>
<date>08/19/2015</date>
<minServerVersion>3.9.0</minServerVersion>
<adminconsole>
......
......@@ -1248,6 +1248,7 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li><a href="#chatroom">Chatroom</a></li>
<li><a href="#system-property">System Property</a></li>
<li><a href="#session">Session</a></li>
<li><a href="#sessions-count">Sessions count</a></li>
</ul>
</li>
</ul>
......@@ -1401,15 +1402,19 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li><a href="#examples-25">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-concurrent-sessions">Retrieve concurrent sessions</a><ul>
<li><a href="#examples-26">Examples</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#group-related-rest-endpoints">Group related REST Endpoints</a><ul>
<li><a href="#retrieve-all-groups">Retrieve all groups</a><ul>
<li><a href="#examples-26">Examples</a></li>
<li><a href="#examples-26-1">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-a-group">Retrieve a group</a><ul>
<li><a href="#possible-parameters-24">Possible parameters</a></li>
<li><a href="#possible-parameters-24-1">Possible parameters</a></li>
<li><a href="#examples-27">Examples</a></li>
</ul>
</li>
......@@ -1873,6 +1878,27 @@ If you want to create a resource with JSON data format, please add “<strong>Co
</tbody></table>
<h3 id="sessions-count">Sessions count</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>clusterSessions</td>
<td>No</td>
<td>Number of client sessions that are authenticated with the server. This includes anonymous and non-anoymous users from the whole cluster.</td>
</tr>
<tr>
<td>localSessions</td>
<td>No</td>
<td>Number of client sessions that are authenticated with the server. This includes anonymous and non-anoymous users.</td>
</tr>
</tbody></table>
<h1 id="user-related-rest-endpoints">User related REST Endpoints</h1>
......@@ -3539,6 +3565,23 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h2 id="retrieve-concurrent-sessions">Retrieve concurrent sessions</h2>
<p>Endpoint to get count of concurrent sessions</p>
<blockquote>
<p><strong>GET</strong> /system/statistics/sessions</p>
</blockquote>
<p><strong>Payload:</strong> none <br>
<strong>Return value:</strong> Sessions count</p>
<h3 id="examples-26">Examples</h3>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
<p><strong>GET</strong> <a href="http://example.org:9090/plugins/restapi/v1/system/statistics/sessions">http://example.org:9090/plugins/restapi/v1/system/statistics/sessions</a></p>
<h1 id="group-related-rest-endpoints">Group related REST Endpoints</h1>
......@@ -4327,6 +4370,57 @@ If the strings are encoded incorrectly, double byte characters will look garbele
......
package org.jivesoftware.openfire.plugin.rest.controller;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.jivesoftware.database.DbConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
/**
* The Class MsgArchiveController.
*/
public class MsgArchiveController {
private static final Logger Log = LoggerFactory.getLogger(MsgArchiveController.class);
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(MsgArchiveController.class);
/** The Constant INSTANCE. */
public static final MsgArchiveController INSTANCE = new MsgArchiveController();
/** The server. */
private XMPPServer server;
/** The Constant USER_MESSAGE_COUNT. */
private static final String USER_MESSAGE_COUNT = "select COUNT(1) from ofMessageArchive a " +
"join ofPresence p on (a.sentDate > p.offlineDate) " +
"WHERE a.toJID = ? AND p.username = ?";
......@@ -39,15 +36,15 @@ public class MsgArchiveController {
}
/**
* Instantiates a new user service controller.
* The Constructor.
*/
private MsgArchiveController() {
server = XMPPServer.getInstance();
}
/**
* Returns the total number of messages that haven't been delivered to the user.
*
* @param jid the jid
* @return the total number of user unread messages.
*/
public int getUnReadMessagesCount(JID jid) {
......@@ -65,7 +62,7 @@ public class MsgArchiveController {
messageCount = rs.getInt(1);
}
} catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
LOG.error(sqle.getMessage(), sqle);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
......
package org.jivesoftware.openfire.plugin.rest.controller;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.plugin.rest.entity.SessionsCount;
/**
* The Class StatisticsController.
*/
public class StatisticsController {
/** The Constant INSTANCE. */
public static final StatisticsController INSTANCE = new StatisticsController();
/**
* Gets the instance.
*
* @return the instance
*/
public static StatisticsController getInstance() {
return INSTANCE;
}
/**
* Gets the concurent sessions.
*
* @return the concurent sessions
*/
public SessionsCount getConcurentSessions() {
int userSessionsCountLocal = SessionManager.getInstance().getUserSessionsCount(true);
int userSessionsCountCluster = SessionManager.getInstance().getUserSessionsCount(false);
return new SessionsCount(userSessionsCountLocal, userSessionsCountCluster);
}
}
package org.jivesoftware.openfire.plugin.rest.entity;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* The Class SessionsCount.
*/
@XmlRootElement(name = "sessions")
public class SessionsCount {
/** The local sessions. */
private int localSessions;
/** The cluster sessions. */
private int clusterSessions;
/**
* The Constructor.
*/
public SessionsCount() {
}
/**
* The Constructor.
*
* @param localSessions the local sessions
* @param clusterSessions the cluster sessions
*/
public SessionsCount(int localSessions, int clusterSessions) {
this.localSessions = localSessions;
this.clusterSessions = clusterSessions;
}
/**
* Gets the local sessions.
*
* @return the local sessions
*/
@XmlElement()
public int getLocalSessions() {
return localSessions;
}
/**
* Sets the local sessions.
*
* @param localSessions the local sessions
*/
public void setLocalSessions(int localSessions) {
this.localSessions = localSessions;
}
/**
* Gets the cluster sessions.
*
* @return the cluster sessions
*/
@XmlElement()
public int getClusterSessions() {
return clusterSessions;
}
/**
* Sets the cluster sessions.
*
* @param clusterSessions the cluster sessions
*/
public void setClusterSessions(int clusterSessions) {
this.clusterSessions = clusterSessions;
}
}
......@@ -80,10 +80,10 @@ public class JerseyWrapper extends ServletContainer {
prc.getClasses().add(GroupService.class);
prc.getClasses().add(SessionService.class);
prc.getClasses().add(MsgArchiveService.class);
prc.getClasses().add(StatisticsService.class);
prc.getClasses().add(RESTExceptionMapper.class);
prc.getClasses().add(MsgArchiveService.class);
}
/**
......
package org.jivesoftware.openfire.plugin.rest.service;
import javax.annotation.PostConstruct;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jivesoftware.openfire.plugin.rest.controller.StatisticsController;
import org.jivesoftware.openfire.plugin.rest.entity.SessionsCount;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
@Path("restapi/v1/system/statistics")
public class StatisticsService {
private StatisticsController controller;
@PostConstruct
public void init() {
controller = StatisticsController.getInstance();
}
@GET
@Path("/sessions")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public SessionsCount getCCS() throws ServiceException {
return controller.getConcurentSessions();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment