Commit ed012548 authored by Redor's avatar Redor

Update the REST API plugin to 1.1.5

- Added: Send broadcast message to all online users
parent 68abcf32
......@@ -44,6 +44,11 @@
REST API Plugin Changelog
</h1>
<p><b>1.1.5</b> -- September 1st, 2015</p>
<ul>
<li>Added: Send broadcast message to all online users</li>
</ul>
<p><b>1.1.4</b> -- August 19th, 2015</p>
<ul>
<li>Added: get concurrent sessions (local or cluster wide)</li>
......
......@@ -5,8 +5,8 @@
<name>REST API</name>
<description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author>
<version>1.1.4</version>
<date>08/19/2015</date>
<version>1.1.5</version>
<date>09/01/2015</date>
<minServerVersion>3.9.0</minServerVersion>
<adminconsole>
......
......@@ -1410,43 +1410,50 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
</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-1">Examples</a></li>
<li><a href="#examples-27">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-a-group">Retrieve a group</a><ul>
<li><a href="#possible-parameters-24-1">Possible parameters</a></li>
<li><a href="#examples-27">Examples</a></li>
<li><a href="#possible-parameters-24">Possible parameters</a></li>
<li><a href="#examples-28">Examples</a></li>
</ul>
</li>
<li><a href="#create-a-group">Create a group</a><ul>
<li><a href="#examples-28">Examples</a></li>
<li><a href="#examples-29">Examples</a></li>
</ul>
</li>
<li><a href="#delete-a-group">Delete a group</a><ul>
<li><a href="#possible-parameters-25">Possible parameters</a></li>
<li><a href="#examples-29">Examples</a></li>
<li><a href="#examples-30">Examples</a></li>
</ul>
</li>
<li><a href="#update-a-group">Update a group</a><ul>
<li><a href="#possible-parameters-26">Possible parameters</a></li>
<li><a href="#examples-30">Examples</a></li>
<li><a href="#examples-31">Examples</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#session-related-rest-endpoints">Session related REST Endpoints</a><ul>
<li><a href="#retrieve-all-user-session">Retrieve all user session</a><ul>
<li><a href="#examples-31">Examples</a></li>
<li><a href="#examples-32">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-the-user-sessions">Retrieve the user sessions</a><ul>
<li><a href="#possible-parameters-27">Possible parameters</a></li>
<li><a href="#examples-32">Examples</a></li>
<li><a href="#examples-33">Examples</a></li>
</ul>
</li>
<li><a href="#close-all-user-sessions">Close all user sessions</a><ul>
<li><a href="#possible-parameters-28">Possible parameters</a></li>
<li><a href="#examples-33">Examples</a></li>
<li><a href="#examples-34">Examples</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#message-related-rest-endpoints">Message related REST Endpoints</a><ul>
<li><a href="#send-a-broadcast-message">Send a broadcast message</a><ul>
<li><a href="#examples-35">Examples</a></li>
</ul>
</li>
</ul>
......@@ -1475,10 +1482,9 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li>Get overview over all or specific system properties and to create, update or delete system property</li>
<li>Get overview over all or specific chat room and to create, update or delete a chat room</li>
<li>Get overview over all or specific user sessions</li>
<li>Send broadcast message to all online users</li>
</ul>
<h2 id="available-rest-api-clients">Available REST API clients</h2>
<p>REST API clients are implementations of the REST API in a specific programming language.</p>
......@@ -1878,6 +1884,8 @@ 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>
......@@ -1901,6 +1909,8 @@ If you want to create a resource with JSON data format, please add “<strong>Co
</tbody></table>
<h1 id="user-related-rest-endpoints">User related REST Endpoints</h1>
......@@ -3576,12 +3586,16 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<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>
......@@ -3599,7 +3613,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-26">Examples</h3>
<h3 id="examples-27">Examples</h3>
<blockquote>
<p><strong>Header</strong>: Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -3644,7 +3658,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-27">Examples</h3>
<h3 id="examples-28">Examples</h3>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -3665,7 +3679,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-28">Examples</h3>
<h3 id="examples-29">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU= <br>
......@@ -3721,7 +3735,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-29">Examples</h3>
<h3 id="examples-30">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -3766,7 +3780,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-30">Examples</h3>
<h3 id="examples-31">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU= <br>
......@@ -3804,7 +3818,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-31">Examples</h3>
<h3 id="examples-32">Examples</h3>
<blockquote>
<p><strong>Header</strong>: Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -3849,7 +3863,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-32">Examples</h3>
<h3 id="examples-33">Examples</h3>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -3892,7 +3906,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="examples-33">Examples</h3>
<h3 id="examples-34">Examples</h3>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -3900,6 +3914,36 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h1 id="message-related-rest-endpoints">Message related REST Endpoints</h1>
<h2 id="send-a-broadcast-message">Send a broadcast message</h2>
<p>Endpoint to send a broadcast/server message to all online users</p>
<blockquote>
<p><strong>POST</strong> /messages/users</p>
</blockquote>
<p><strong>Payload:</strong> Message <br>
<strong>Return value:</strong> HTTP status 201 (Created)</p>
<h3 id="examples-35">Examples</h3>
<blockquote>
<p><strong>Header</strong>: Authorization: Basic YWRtaW46MTIzNDU=</p>
<p><strong>POST</strong> <a href="http://example.org:9090/plugins/restapi/v1/messages/users">http://example.org:9090/plugins/restapi/v1/messages/users</a></p>
</blockquote>
<p><strong>Payload:</strong></p>
<pre class="prettyprint"><code class=" hljs xml"><span class="hljs-pi">&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">message</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span>Your message<span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">message</span>&gt;</span></code></pre>
<h1 id="deprecated-user-service-plugin-readme">(Deprecated) User Service Plugin Readme</h1>
......@@ -4427,6 +4471,20 @@ If the strings are encoded incorrectly, double byte characters will look garbele
......
......@@ -11,6 +11,7 @@ import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.AuthFactory;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.lockout.LockOutManager;
import org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
import org.jivesoftware.openfire.roster.Roster;
......@@ -130,6 +131,7 @@ public class JustMarriedController {
*/
private static void deleteUser(User oldUser) {
UserManager.getInstance().deleteUser(oldUser);
LockOutManager.getInstance().enableAccount(oldUser.getUsername());
final StreamError error = new StreamError(StreamError.Condition.not_authorized);
for (ClientSession sess : SessionManager.getInstance().getSessions(oldUser.getUsername())) {
sess.deliverRawText(error.toXML());
......
package org.jivesoftware.openfire.plugin.rest.controller;
import javax.ws.rs.core.Response;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.plugin.rest.entity.MessageEntity;
import org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
/**
* The Class MessageController.
*/
public class MessageController {
/** The Constant INSTANCE. */
public static final MessageController INSTANCE = new MessageController();
/**
* Gets the single instance of MessageController.
*
* @return single instance of MessageController
*/
public static MessageController getInstance() {
return INSTANCE;
}
/**
* Send broadcast message.
*
* @param messageEntity
* the message entity
* @throws ServiceException
* the service exception
*/
public void sendBroadcastMessage(MessageEntity messageEntity) throws ServiceException {
if (messageEntity.getBody() != null && !messageEntity.getBody().isEmpty()) {
SessionManager.getInstance().sendServerMessage(null, messageEntity.getBody());
} else {
throw new ServiceException("Message content/body is null or empty", "",
ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION,
Response.Status.BAD_REQUEST);
}
}
}
\ No newline at end of file
package org.jivesoftware.openfire.plugin.rest.entity;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* The Class MessageEntity.
*/
@XmlRootElement(name = "message")
public class MessageEntity {
/** The body. */
private String body;
/**
* Instantiates a new message entity.
*/
public MessageEntity() {
}
/**
* Gets the body.
*
* @return the body
*/
@XmlElement
public String getBody() {
return body;
}
/**
* Sets the body.
*
* @param body
* the new body
*/
public void setBody(String body) {
this.body = body;
}
}
......@@ -21,7 +21,7 @@ public class JerseyWrapper extends ServletContainer {
/** The Constant AUTHFILTER. */
private static final String AUTHFILTER = "org.jivesoftware.openfire.plugin.rest.AuthFilter";
/** The Constant CORSFILTER. */
private static final String CORSFILTER = "org.jivesoftware.openfire.plugin.rest.CORSFilter";
......@@ -51,12 +51,12 @@ public class JerseyWrapper extends ServletContainer {
/** The prc. */
private static PackagesResourceConfig prc;
/** The Constant JERSEY_LOGGER. */
private final static Logger JERSEY_LOGGER = Logger.getLogger("com.sun.jersey");
static {
JERSEY_LOGGER.setLevel(Level.SEVERE);
JERSEY_LOGGER.setLevel(Level.SEVERE);
config = new HashMap<String, Object>();
config.put(RESOURCE_CONFIG_CLASS_KEY, RESOURCE_CONFIG_CLASS);
prc = new PackagesResourceConfig(SCAN_PACKAGE_DEFAULT);
......@@ -65,13 +65,13 @@ public class JerseyWrapper extends ServletContainer {
prc.getProperties().put(CONTAINER_RESPONSE_FILTERS, CORSFILTER);
prc.getClasses().add(RestAPIService.class);
prc.getClasses().add(MUCRoomService.class);
prc.getClasses().add(MUCRoomOwnersService.class);
prc.getClasses().add(MUCRoomAdminsService.class);
prc.getClasses().add(MUCRoomMembersService.class);
prc.getClasses().add(MUCRoomOutcastsService.class);
prc.getClasses().add(UserServiceLegacy.class);
prc.getClasses().add(UserService.class);
prc.getClasses().add(UserRosterService.class);
......@@ -82,6 +82,7 @@ public class JerseyWrapper extends ServletContainer {
prc.getClasses().add(SessionService.class);
prc.getClasses().add(MsgArchiveService.class);
prc.getClasses().add(StatisticsService.class);
prc.getClasses().add(MessageService.class);
prc.getClasses().add(RESTExceptionMapper.class);
}
......
package org.jivesoftware.openfire.plugin.rest.service;
import javax.annotation.PostConstruct;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.jivesoftware.openfire.plugin.rest.controller.MessageController;
import org.jivesoftware.openfire.plugin.rest.entity.MessageEntity;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
@Path("restapi/v1/messages")
public class MessageService {
private MessageController messageController;
@PostConstruct
public void init() {
messageController = MessageController.getInstance();
}
@POST
@Path("/users")
public Response sendBroadcastMessage(MessageEntity messageEntity) throws ServiceException {
messageController.sendBroadcastMessage(messageEntity);
return Response.status(Response.Status.CREATED).build();
}
}
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