Skip to content

Commit f549d2c

Browse files
committed
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.
1 parent d4adf29 commit f549d2c

1 file changed

Lines changed: 14 additions & 27 deletions

File tree

src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceLegacyController.java

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import org.jivesoftware.openfire.user.UserAlreadyExistsException;
3737
import org.jivesoftware.openfire.user.UserManager;
3838
import org.jivesoftware.openfire.user.UserNotFoundException;
39-
import org.slf4j.Logger;
40-
import org.slf4j.LoggerFactory;
4139
import org.xmpp.packet.JID;
4240

4341
/**
@@ -46,8 +44,7 @@
4644
* @author Justin Hunt
4745
*/
4846
public class UserServiceLegacyController {
49-
private static final Logger LOG = LoggerFactory.getLogger(UserServiceLegacyController.class);
50-
47+
5148
/** The Constant INSTANCE. */
5249
public static final UserServiceLegacyController INSTANCE = new UserServiceLegacyController();
5350

@@ -92,8 +89,9 @@ private UserServiceLegacyController() {
9289
* @throws GroupNotFoundException the group not found exception
9390
*/
9491
public void createUser(String username, String password, String name, String email, String groupNames)
95-
throws UserAlreadyExistsException, GroupAlreadyExistsException, UserNotFoundException,
96-
GroupNotFoundException {
92+
throws UserAlreadyExistsException, GroupAlreadyExistsException, UserNotFoundException,
93+
GroupNotFoundException, GroupNameInvalidException
94+
{
9795
userManager.createUser(username, password, name, email);
9896
userManager.getUser(username);
9997

@@ -109,16 +107,10 @@ public void createUser(String username, String password, String name, String ema
109107
group = GroupManager.getInstance().getGroup(groupName);
110108
} catch (GroupNotFoundException e) {
111109
// Create this group ;
112-
try {
113-
group = GroupManager.getInstance().createGroup(groupName);
114-
group.getProperties().put("sharedRoster.showInRoster", "nobody");
115-
group.getProperties().put("sharedRoster.displayName", groupName);
116-
group.getProperties().put("sharedRoster.groupList", "");
117-
} catch (GroupAlreadyExistsException e1) {
118-
LOG.error(e1.getMessage(), e1);
119-
} catch (GroupNameInvalidException e1) {
120-
LOG.error(e1.getMessage(), e1);
121-
}
110+
group = GroupManager.getInstance().createGroup(groupName);
111+
group.getProperties().put("sharedRoster.showInRoster", "nobody");
112+
group.getProperties().put("sharedRoster.displayName", groupName);
113+
group.getProperties().put("sharedRoster.groupList", "");
122114
}
123115
groups.add(group);
124116
}
@@ -176,7 +168,8 @@ public void enableUser(String username) throws UserNotFoundException {
176168
* @throws GroupAlreadyExistsException the group already exists exception
177169
*/
178170
public void updateUser(String username, String password, String name, String email, String groupNames)
179-
throws UserNotFoundException, GroupAlreadyExistsException {
171+
throws UserNotFoundException, GroupAlreadyExistsException, GroupNameInvalidException
172+
{
180173
User user = getUser(username);
181174
if (password != null)
182175
user.setPassword(password);
@@ -197,16 +190,10 @@ public void updateUser(String username, String password, String name, String ema
197190
group = GroupManager.getInstance().getGroup(groupName);
198191
} catch (GroupNotFoundException e) {
199192
// Create this group ;
200-
try {
201-
group = GroupManager.getInstance().createGroup(groupName);
202-
group.getProperties().put("sharedRoster.showInRoster", "nobody");
203-
group.getProperties().put("sharedRoster.displayName", groupName);
204-
group.getProperties().put("sharedRoster.groupList", "");
205-
} catch (GroupAlreadyExistsException e1) {
206-
LOG.error(e1.getMessage(), e1);
207-
} catch (GroupNameInvalidException e1) {
208-
LOG.error(e1.getMessage(), e1);
209-
}
193+
group = GroupManager.getInstance().createGroup(groupName);
194+
group.getProperties().put("sharedRoster.showInRoster", "nobody");
195+
group.getProperties().put("sharedRoster.displayName", groupName);
196+
group.getProperties().put("sharedRoster.groupList", "");
210197
}
211198

212199
newGroups.add(group);

0 commit comments

Comments
 (0)