Commit a60eefe2 authored by Dele Olajide's avatar Dele Olajide

Merge pull request #48 from Redor/master

MUC Service Plugin. I adding this to complement the User Service plugin.
parents e97a1ff1 579e1996
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>MUC Service Plugin Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
padding-left : 1em;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>
MUC Service Plugin Changelog
</h1>
<p><b>0.1.0</b> -- 23.06.2014</p>
<ul>
<li>Initial setup of MUC Service Plugin</li>
</ul>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>org.jivesoftware.openfire.plugin.MUCServicePlugin</class>
<name>MUC Service</name>
<description>MUC administration over REST Interface</description>
<author>Roman Soldatow</author>
<version>0.1.0</version>
<date>23.06.2014</date>
<minServerVersion>3.9.1</minServerVersion>
</plugin>
This source diff could not be displayed because it is too large. You can view the blob instead.
package org.jivesoftware.openfire.entity;
public final class MUCChannelType {
public static final String PUBLIC = "public";
public static final String ALL = "all";
private MUCChannelType() {
}
}
package org.jivesoftware.openfire.entity;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "chatRooms")
public class MUCRoomEntities {
List<MUCRoomEntity> mucRooms;
public MUCRoomEntities() {
}
public MUCRoomEntities(List<MUCRoomEntity> mucRooms) {
this.mucRooms = mucRooms;
}
@XmlElement(name = "chatRoom")
public List<MUCRoomEntity> getMucRooms() {
return mucRooms;
}
public void setMucRooms(List<MUCRoomEntity> mucRooms) {
this.mucRooms = mucRooms;
}
}
package org.jivesoftware.openfire.entity;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "chatRoom")
public class MUCRoomEntity {
private String roomName;
private String description;
private String password;
private String subject;
private String naturalName;
private int maxUsers;
private Date creationDate;
private Date modificationDate;
private boolean persistent;
private boolean publicRoom;
private boolean registrationEnabled;
private boolean canAnyoneDiscoverJID;
private boolean canOccupantsChangeSubject;
private boolean canOccupantsInvite;
private boolean canChangeNickname;
private boolean logEnabled;
private boolean loginRestrictedToNickname;
private boolean membersOnly;
private boolean moderated;
private List<String> broadcastPresenceRoles;
public MUCRoomEntity() {
}
public MUCRoomEntity(String naturalName, String roomName, String description) {
this.naturalName = naturalName;
this.roomName = roomName;
this.description = description;
}
@XmlElement
public String getNaturalName() {
return naturalName;
}
public void setNaturalName(String naturalName) {
this.naturalName = naturalName;
}
@XmlElement
public String getRoomName() {
return roomName;
}
public void setRoomName(String roomName) {
this.roomName = roomName;
}
@XmlElement
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@XmlElement
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@XmlElement
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
@XmlElement
public int getMaxUsers() {
return maxUsers;
}
public void setMaxUsers(int maxUsers) {
this.maxUsers = maxUsers;
}
@XmlElement
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
@XmlElement
public Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(Date modificationDate) {
this.modificationDate = modificationDate;
}
@XmlElement
public boolean isPersistent() {
return persistent;
}
public void setPersistent(boolean persistent) {
this.persistent = persistent;
}
@XmlElement
public boolean isPublicRoom() {
return publicRoom;
}
public void setPublicRoom(boolean publicRoom) {
this.publicRoom = publicRoom;
}
@XmlElement
public boolean isRegistrationEnabled() {
return registrationEnabled;
}
public void setRegistrationEnabled(boolean registrationEnabled) {
this.registrationEnabled = registrationEnabled;
}
@XmlElement
public boolean isCanAnyoneDiscoverJID() {
return canAnyoneDiscoverJID;
}
public void setCanAnyoneDiscoverJID(boolean canAnyoneDiscoverJID) {
this.canAnyoneDiscoverJID = canAnyoneDiscoverJID;
}
@XmlElement
public boolean isCanOccupantsChangeSubject() {
return canOccupantsChangeSubject;
}
public void setCanOccupantsChangeSubject(boolean canOccupantsChangeSubject) {
this.canOccupantsChangeSubject = canOccupantsChangeSubject;
}
@XmlElement
public boolean isCanOccupantsInvite() {
return canOccupantsInvite;
}
public void setCanOccupantsInvite(boolean canOccupantsInvite) {
this.canOccupantsInvite = canOccupantsInvite;
}
@XmlElement(name = "broadcastPresenceRole")
@XmlElementWrapper(name = "broadcastPresenceRoles")
public List<String> getBroadcastPresenceRoles() {
return broadcastPresenceRoles;
}
public void setBroadcastPresenceRoles(List<String> broadcastPresenceRoles) {
this.broadcastPresenceRoles = broadcastPresenceRoles;
}
@XmlElement
public boolean isCanChangeNickname() {
return canChangeNickname;
}
public void setCanChangeNickname(boolean canChangeNickname) {
this.canChangeNickname = canChangeNickname;
}
@XmlElement
public boolean isLogEnabled() {
return logEnabled;
}
public void setLogEnabled(boolean logEnabled) {
this.logEnabled = logEnabled;
}
@XmlElement
public boolean isLoginRestrictedToNickname() {
return loginRestrictedToNickname;
}
public void setLoginRestrictedToNickname(boolean loginRestrictedToNickname) {
this.loginRestrictedToNickname = loginRestrictedToNickname;
}
@XmlElement
public boolean isMembersOnly() {
return membersOnly;
}
public void setMembersOnly(boolean membersOnly) {
this.membersOnly = membersOnly;
}
@XmlElement
public boolean isModerated() {
return moderated;
}
public void setModerated(boolean moderated) {
this.moderated = moderated;
}
}
\ No newline at end of file
package org.jivesoftware.openfire.exception;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "error")
public class ErrorResponse {
private String ressource;
private String message;
private String exception;
private String exceptionStack;
public String getRessource() {
return ressource;
}
public void setRessource(String ressource) {
this.ressource = ressource;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getException() {
return exception;
}
public void setException(String exception) {
this.exception = exception;
}
public String getExceptionStack() {
return exceptionStack;
}
public void setExceptionStack(String exceptionStack) {
this.exceptionStack = exceptionStack;
}
}
\ No newline at end of file
package org.jivesoftware.openfire.exception;
/**
* The Class MUCServiceException.
*/
public class MUCServiceException extends Exception {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 4351720088030656859L;
/** The ressource. */
private String ressource;
/** The exception. */
private String exception;
/**
* Instantiates a new mUC service exception.
*
* @param msg
* the msg
* @param ressource
* the ressource
* @param exception
* the exception
*/
public MUCServiceException(String msg, String ressource, String exception) {
super(msg);
this.ressource = ressource;
this.exception = exception;
}
/**
* Instantiates a new mUC service exception.
*
* @param msg
* the msg
* @param cause
* the cause
*/
public MUCServiceException(String msg, Throwable cause) {
super(msg, cause);
}
/**
* Gets the ressource.
*
* @return the ressource
*/
public String getRessource() {
return ressource;
}
/**
* Sets the ressource.
*
* @param ressource
* the new ressource
*/
public void setRessource(String ressource) {
this.ressource = ressource;
}
/**
* Gets the exception.
*
* @return the exception
*/
public String getException() {
return exception;
}
/**
* Sets the exception.
*
* @param exception
* the new exception
*/
public void setException(String exception) {
this.exception = exception;
}
}
\ No newline at end of file
package org.jivesoftware.openfire.plugin;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.entity.MUCChannelType;
import org.jivesoftware.openfire.entity.MUCRoomEntities;
import org.jivesoftware.openfire.entity.MUCRoomEntity;
import org.jivesoftware.openfire.exception.MUCServiceException;
import org.jivesoftware.openfire.muc.MUCRoom;
import org.jivesoftware.openfire.muc.NotAllowedException;
/**
* The Class MUCRoomController.
*/
public class MUCRoomController {
/** The Constant INSTANCE. */
public static final MUCRoomController INSTANCE = new MUCRoomController();
/**
* Gets the single instance of MUCRoomController.
*
* @return single instance of MUCRoomController
*/
public static MUCRoomController getInstance() {
return INSTANCE;
}
/**
* Gets the chat rooms.
*
* @param serviceName
* the service name
* @param channelType
* the channel type
* @param roomSearch
* the room search
* @return the chat rooms
*/
public MUCRoomEntities getChatRooms(String serviceName, String channelType, String roomSearch) {
List<MUCRoom> rooms = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRooms();
List<MUCRoomEntity> mucRoomEntities = new ArrayList<MUCRoomEntity>();
for (MUCRoom chatRoom : rooms) {
if (roomSearch != null) {
if (!chatRoom.getName().contains(roomSearch)) {
continue;
}
}
if (channelType.equals(MUCChannelType.ALL)) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom));
} else if (channelType.equals(MUCChannelType.PUBLIC) && chatRoom.isPublicRoom()) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom));
}
}
return new MUCRoomEntities(mucRoomEntities);
}
/**
* Gets the chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @return the chat room
* @throws MUCServiceException
* the mUC service exception
*/
public MUCRoomEntity getChatRoom(String roomName, String serviceName) throws MUCServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName);
if (chatRoom == null) {
throw new MUCServiceException("Could not fetch the channel", roomName, "Chat room could be not found");
}
MUCRoomEntity mucRoomEntity = convertToMUCRoomEntity(chatRoom);
return mucRoomEntity;
}
/**
* Delete chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @throws MUCServiceException
* the mUC service exception
*/
public void deleteChatRoom(String roomName, String serviceName) throws MUCServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName);
if (chatRoom != null) {
chatRoom.destroyRoom(null, null);
} else {
throw new MUCServiceException("Could not remove the channel", roomName, "Chat room could be not found");
}
}
/**
* Creates the chat room.
*
* @param serviceName
* the service name
* @param owner
* the owner
* @param mucRoomEntity
* the muc room entity
* @throws MUCServiceException
* the mUC service exception
*/
public void createChatRoom(String serviceName, String owner, MUCRoomEntity mucRoomEntity) throws MUCServiceException {
try {
createRoom(mucRoomEntity, serviceName, owner);
} catch (NotAllowedException e) {
throw new MUCServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
"NotAllowedException");
}
}
/**
* Update chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @param owner
* the owner
* @param mucRoomEntity
* the muc room entity
* @throws MUCServiceException
* the mUC service exception
*/
public void updateChatRoom(String roomName, String serviceName, String owner, MUCRoomEntity mucRoomEntity)
throws MUCServiceException {
try {
// If the roomname is different throw exception
if (!roomName.equals(mucRoomEntity.getRoomName())) {
throw new MUCServiceException("Could not update the channel", roomName,
"The roomname is different to the entity room name");
}
createRoom(mucRoomEntity, serviceName, owner);
} catch (NotAllowedException e) {
throw new MUCServiceException("Could not update the channel", roomName, "NotAllowedException");
}
}
/**
* Creates the room.
*
* @param mucRoomEntity
* the muc room entity
* @param serviceName
* the service name
* @param owner
* the owner
* @throws NotAllowedException
* the not allowed exception
*/
public void createRoom(MUCRoomEntity mucRoomEntity, String serviceName, String owner) throws NotAllowedException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(mucRoomEntity.getRoomName(), XMPPServer.getInstance().createJID(owner, null));
room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
room.setSubject(mucRoomEntity.getSubject());
room.setDescription(mucRoomEntity.getDescription());
room.setPassword(mucRoomEntity.getPassword());
room.setPersistent(mucRoomEntity.isPersistent());
room.setPublicRoom(mucRoomEntity.isPublicRoom());
room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
room.setCreationDate(mucRoomEntity.getCreationDate());
room.setModificationDate(mucRoomEntity.getModificationDate());
room.setLogEnabled(mucRoomEntity.isLogEnabled());
room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
room.setMaxUsers(mucRoomEntity.getMaxUsers());
room.setMembersOnly(mucRoomEntity.isMembersOnly());
room.setModerated(mucRoomEntity.isModerated());
room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
}
/**
* Convert to muc room entity.
*
* @param room
* the room
* @return the mUC room entity
*/
public MUCRoomEntity convertToMUCRoomEntity(MUCRoom room) {
MUCRoomEntity mucRoomEntity = new MUCRoomEntity(room.getNaturalLanguageName(), room.getName(),
room.getDescription());
mucRoomEntity.setCanAnyoneDiscoverJID(room.canAnyoneDiscoverJID());
mucRoomEntity.setCanChangeNickname(room.canChangeNickname());
mucRoomEntity.setCanOccupantsChangeSubject(room.canOccupantsChangeSubject());
mucRoomEntity.setCanOccupantsInvite(room.canOccupantsInvite());
mucRoomEntity.setPublicRoom(room.isPublicRoom());
mucRoomEntity.setPassword(room.getPassword());
mucRoomEntity.setPersistent(room.isPersistent());
mucRoomEntity.setRegistrationEnabled(room.isRegistrationEnabled());
mucRoomEntity.setLogEnabled(room.isLogEnabled());
mucRoomEntity.setLoginRestrictedToNickname(room.isLoginRestrictedToNickname());
mucRoomEntity.setMaxUsers(room.getMaxUsers());
mucRoomEntity.setMembersOnly(room.isMembersOnly());
mucRoomEntity.setModerated(room.isModerated());
mucRoomEntity.setCreationDate(room.getCreationDate());
mucRoomEntity.setModificationDate(room.getModificationDate());
mucRoomEntity.setBroadcastPresenceRoles(room.getRolesToBroadcastPresence());
return mucRoomEntity;
}
}
\ No newline at end of file
/**
* $Revision: 1722 $
* $Date: 2005-07-28 15:19:16 -0700 (Thu, 28 Jul 2005) $
*
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.plugin;
import java.io.File;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
/**
* The Class MUCServicePlugin.
*/
public class MUCServicePlugin implements Plugin {
/**
* Instantiates a new mUC service plugin.
*/
public MUCServicePlugin() {
}
/*
* (non-Javadoc)
*
* @see
* org.jivesoftware.openfire.container.Plugin#initializePlugin(org.jivesoftware
* .openfire.container.PluginManager, java.io.File)
*/
public void initializePlugin(PluginManager manager, File pluginDirectory) {
}
/*
* (non-Javadoc)
*
* @see org.jivesoftware.openfire.container.Plugin#destroyPlugin()
*/
public void destroyPlugin() {
}
}
\ No newline at end of file
package org.jivesoftware.openfire.plugin.servlet;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;
import org.jivesoftware.openfire.admin.AdminManager;
import org.jivesoftware.openfire.auth.AuthFactory;
import org.jivesoftware.openfire.auth.ConnectionException;
import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerRequestFilter;
/**
* Jersey HTTP Basic Auth filter
*
* @author Deisss (LGPLv3)
*/
public class AuthFilter implements ContainerRequestFilter {
/**
* Apply the filter : check input request, validate or not with user auth
*
* @param containerRequest
* The request from Tomcat server
*/
@Override
public ContainerRequest filter(ContainerRequest containerRequest) throws WebApplicationException {
// Get the authentification passed in HTTP headers parameters
String auth = containerRequest.getHeaderValue("authorization");
// If the user does not have the right (does not provide any HTTP Basic
// Auth)
if (auth == null) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
// lap : loginAndPassword
String[] lap = BasicAuth.decode(auth);
// If login or password fail
if (lap == null || lap.length != 2) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
boolean userAdmin = AdminManager.getInstance().isUserAdmin(lap[0], true);
if (!userAdmin) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
try {
AuthFactory.authenticate(lap[0], lap[1]);
} catch (UnauthorizedException e) {
throw new WebApplicationException(Status.UNAUTHORIZED);
} catch (ConnectionException e) {
throw new WebApplicationException(Status.UNAUTHORIZED);
} catch (InternalUnauthenticatedException e) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
return containerRequest;
}
}
\ No newline at end of file
package org.jivesoftware.openfire.plugin.servlet;
import javax.xml.bind.DatatypeConverter;
public class BasicAuth {
/**
* Decode the basic auth and convert it to array login/password
*
* @param auth
* The string encoded authentification
* @return The login (case 0), the password (case 1)
*/
public static String[] decode(String auth) {
// Replacing "Basic THE_BASE_64" to "THE_BASE_64" directly
auth = auth.replaceFirst("[B|b]asic ", "");
// Decode the Base64 into byte[]
byte[] decodedBytes = DatatypeConverter.parseBase64Binary(auth);
// If the decode fails in any case
if (decodedBytes == null || decodedBytes.length == 0) {
return null;
}
// Now we can convert the byte[] into a splitted array :
// - the first one is login,
// - the second one password
return new String(decodedBytes).split(":", 2);
}
}
package org.jivesoftware.openfire.plugin.servlet;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.jivesoftware.admin.AuthCheckFilter;
import org.jivesoftware.openfire.service.MUCRoomService;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.spi.container.servlet.ServletContainer;
/**
* The Class JerseyWrapper.
*/
public class JerseyWrapper extends ServletContainer {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The Constant SERVLET_URL. */
private static final String SERVLET_URL = "mucservice/*";
/** The Constant SCAN_PACKAGE_DEFAULT. */
private static final String SCAN_PACKAGE_DEFAULT = JerseyWrapper.class.getPackage().getName();
/** The Constant RESOURCE_CONFIG_CLASS_KEY. */
private static final String RESOURCE_CONFIG_CLASS_KEY = "com.sun.jersey.config.property.resourceConfigClass";
/** The Constant RESOURCE_CONFIG_CLASS. */
private static final String RESOURCE_CONFIG_CLASS = "com.sun.jersey.api.core.PackagesResourceConfig";
/** The config. */
private static Map<String, Object> config;
/** The prc. */
private static PackagesResourceConfig prc;
static {
config = new HashMap<String, Object>();
config.put(RESOURCE_CONFIG_CLASS_KEY, RESOURCE_CONFIG_CLASS);
prc = new PackagesResourceConfig(SCAN_PACKAGE_DEFAULT);
prc.setPropertiesAndFeatures(config);
prc.getProperties().put("com.sun.jersey.spi.container.ContainerRequestFilters",
"org.jivesoftware.openfire.plugin.servlet.AuthFilter");
prc.getClasses().add(MUCRoomService.class);
prc.getClasses().add(RESTExceptionMapper.class);
}
/**
* Instantiates a new jersey wrapper.
*/
public JerseyWrapper() {
super(prc);
}
/*
* (non-Javadoc)
*
* @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
*/
@Override
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
// Exclude this servlet from requering the user to login
AuthCheckFilter.addExclude(SERVLET_URL);
}
/*
* (non-Javadoc)
*
* @see com.sun.jersey.spi.container.servlet.ServletContainer#destroy()
*/
@Override
public void destroy() {
super.destroy();
// Release the excluded URL
AuthCheckFilter.removeExclude(SERVLET_URL);
}
}
package org.jivesoftware.openfire.plugin.servlet;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.jivesoftware.openfire.exception.ErrorResponse;
import org.jivesoftware.openfire.exception.MUCServiceException;
/**
* The Class RESTExceptionMapper.
*/
@Provider
public class RESTExceptionMapper implements ExceptionMapper<MUCServiceException> {
/**
* Instantiates a new rEST exception mapper.
*/
public RESTExceptionMapper() {
}
/*
* (non-Javadoc)
*
* @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
*/
public Response toResponse(MUCServiceException exception) {
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setRessource(exception.getRessource());
errorResponse.setMessage(exception.getMessage());
errorResponse.setException(exception.getException());
return Response.status(Response.Status.NOT_FOUND).entity(errorResponse).type(MediaType.APPLICATION_XML).build();
}
}
package org.jivesoftware.openfire.service;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jivesoftware.openfire.entity.MUCChannelType;
import org.jivesoftware.openfire.entity.MUCRoomEntities;
import org.jivesoftware.openfire.entity.MUCRoomEntity;
import org.jivesoftware.openfire.exception.MUCServiceException;
import org.jivesoftware.openfire.plugin.MUCRoomController;
@Path("mucservice")
public class MUCRoomService {
@GET
@Path("/chatrooms")
@Produces(MediaType.APPLICATION_XML)
public MUCRoomEntities getMUCRooms(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@DefaultValue(MUCChannelType.PUBLIC) @QueryParam("type") String channelType,
@QueryParam("search") String roomSearch) {
return MUCRoomController.getInstance().getChatRooms(serviceName, channelType, roomSearch);
}
@GET
@Path("/chatrooms/{roomName}")
@Produces(MediaType.APPLICATION_XML)
public MUCRoomEntity getMUCRoom(@PathParam("roomName") String roomName,
@DefaultValue("conference") @QueryParam("servicename") String serviceName) throws MUCServiceException {
return MUCRoomController.getInstance().getChatRoom(roomName, serviceName);
}
@DELETE
@Path("/chatrooms/{roomName}")
public void deleteMUCRoom(@PathParam("roomName") String roomName,
@DefaultValue("conference") @QueryParam("servicename") String serviceName) throws MUCServiceException {
MUCRoomController.getInstance().deleteChatRoom(roomName, serviceName);
}
@POST
@Path("/chatrooms")
public void createMUCRoom(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@DefaultValue("admin") @QueryParam("owner") String owner, MUCRoomEntity mucRoomEntity)
throws MUCServiceException {
MUCRoomController.getInstance().createChatRoom(serviceName, owner, mucRoomEntity);
}
@PUT
@Path("/chatrooms/{roomName}")
public void udpateMUCRoom(@PathParam("roomName") String roomName,
@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@DefaultValue("admin") @QueryParam("owner") String owner, MUCRoomEntity mucRoomEntity)
throws MUCServiceException {
MUCRoomController.getInstance().updateChatRoom(roomName, serviceName, owner, mucRoomEntity);
}
}
<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>JerseyWrapper</servlet-name>
<servlet-class>org.jivesoftware.openfire.plugin.servlet.JerseyWrapper</servlet-class>
</servlet>
<!-- Servlet mappings -->
<servlet-mapping>
<servlet-name>JerseyWrapper</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
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