From f549d2c7904317ea5c120f1c18d572e1537b37c4 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Tue, 25 Jun 2024 10:09:15 +0200 Subject: [PATCH] Rethrow exception, rather than catching/logging it Openfire 4.8 introduces a new exception. This commit rethrows the exception, rather than catch/logging it. This is in line with the other exception handling. It also allows end-users to know that a REST request failed. --- .../UserServiceLegacyController.java | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceLegacyController.java b/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceLegacyController.java index c737eda72..ef4db1272 100644 --- a/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceLegacyController.java +++ b/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceLegacyController.java @@ -36,8 +36,6 @@ import org.jivesoftware.openfire.user.UserAlreadyExistsException; import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.xmpp.packet.JID; /** @@ -46,8 +44,7 @@ * @author Justin Hunt */ public class UserServiceLegacyController { - private static final Logger LOG = LoggerFactory.getLogger(UserServiceLegacyController.class); - + /** The Constant INSTANCE. */ public static final UserServiceLegacyController INSTANCE = new UserServiceLegacyController(); @@ -92,8 +89,9 @@ private UserServiceLegacyController() { * @throws GroupNotFoundException the group not found exception */ public void createUser(String username, String password, String name, String email, String groupNames) - throws UserAlreadyExistsException, GroupAlreadyExistsException, UserNotFoundException, - GroupNotFoundException { + throws UserAlreadyExistsException, GroupAlreadyExistsException, UserNotFoundException, + GroupNotFoundException, GroupNameInvalidException + { userManager.createUser(username, password, name, email); userManager.getUser(username); @@ -109,16 +107,10 @@ public void createUser(String username, String password, String name, String ema group = GroupManager.getInstance().getGroup(groupName); } catch (GroupNotFoundException e) { // Create this group ; - try { - group = GroupManager.getInstance().createGroup(groupName); - group.getProperties().put("sharedRoster.showInRoster", "nobody"); - group.getProperties().put("sharedRoster.displayName", groupName); - group.getProperties().put("sharedRoster.groupList", ""); - } catch (GroupAlreadyExistsException e1) { - LOG.error(e1.getMessage(), e1); - } catch (GroupNameInvalidException e1) { - LOG.error(e1.getMessage(), e1); - } + group = GroupManager.getInstance().createGroup(groupName); + group.getProperties().put("sharedRoster.showInRoster", "nobody"); + group.getProperties().put("sharedRoster.displayName", groupName); + group.getProperties().put("sharedRoster.groupList", ""); } groups.add(group); } @@ -176,7 +168,8 @@ public void enableUser(String username) throws UserNotFoundException { * @throws GroupAlreadyExistsException the group already exists exception */ public void updateUser(String username, String password, String name, String email, String groupNames) - throws UserNotFoundException, GroupAlreadyExistsException { + throws UserNotFoundException, GroupAlreadyExistsException, GroupNameInvalidException + { User user = getUser(username); if (password != null) user.setPassword(password); @@ -197,16 +190,10 @@ public void updateUser(String username, String password, String name, String ema group = GroupManager.getInstance().getGroup(groupName); } catch (GroupNotFoundException e) { // Create this group ; - try { - group = GroupManager.getInstance().createGroup(groupName); - group.getProperties().put("sharedRoster.showInRoster", "nobody"); - group.getProperties().put("sharedRoster.displayName", groupName); - group.getProperties().put("sharedRoster.groupList", ""); - } catch (GroupAlreadyExistsException e1) { - LOG.error(e1.getMessage(), e1); - } catch (GroupNameInvalidException e1) { - LOG.error(e1.getMessage(), e1); - } + group = GroupManager.getInstance().createGroup(groupName); + group.getProperties().put("sharedRoster.showInRoster", "nobody"); + group.getProperties().put("sharedRoster.displayName", groupName); + group.getProperties().put("sharedRoster.groupList", ""); } newGroups.add(group);