Skip to content

Commit

Permalink
Rethrow exception, rather than catching/logging it
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guusdk committed Jun 25, 2024
1 parent d4adf29 commit f549d2c
Showing 1 changed file with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();

Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f549d2c

Please sign in to comment.