Skip to content

Commit 8fbbc76

Browse files
committed
api: minor fixes in ApiServlet
- Reusing local variable for string splitting/processing - Fix comments - Fix indentations Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
1 parent c8923c9 commit 8fbbc76

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

‎server/src/com/cloud/api/ApiServlet.java‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ private void utf8Fixup(HttpServletRequest req, Map<String, Object[]> params) {
8686
for (String param : paramsInQueryString) {
8787
String[] paramTokens = param.split("=");
8888
if (paramTokens != null && paramTokens.length == 2) {
89-
String name = param.split("=")[0];
90-
String value = param.split("=")[1];
89+
String name = paramTokens[0];
90+
String value = paramTokens[1];
9191

9292
try {
9393
name = URLDecoder.decode(name, "UTF-8");
@@ -99,7 +99,7 @@ private void utf8Fixup(HttpServletRequest req, Map<String, Object[]> params) {
9999
}
100100
params.put(name, new String[] { value });
101101
} else {
102-
s_logger.debug("Invalid paramemter in URL found. param: " + param);
102+
s_logger.debug("Invalid parameter in URL found. param: " + param);
103103
}
104104
}
105105
}
@@ -115,13 +115,10 @@ private void processRequest(HttpServletRequest req, HttpServletResponse resp) {
115115
Map<String, Object[]> params = new HashMap<String, Object[]>();
116116
params.putAll(req.getParameterMap());
117117

118-
//
119118
// For HTTP GET requests, it seems that HttpServletRequest.getParameterMap() actually tries
120119
// to unwrap URL encoded content from ISO-9959-1.
121-
//
122-
// After failed in using setCharacterEncoding() to control it, end up with following hacking : for all GET requests,
123-
// we will override it with our-own way of UTF-8 based URL decoding.
124-
//
120+
// After failed in using setCharacterEncoding() to control it, end up with following hacking:
121+
// for all GET requests, we will override it with our-own way of UTF-8 based URL decoding.
125122
utf8Fixup(req, params);
126123

127124
// logging the request start and end in management log for easy debugging
@@ -265,7 +262,8 @@ private void processRequest(HttpServletRequest req, HttpServletResponse resp) {
265262
}
266263

267264
// Do a sanity check here to make sure the user hasn't already been deleted
268-
if ((userId != null) && (account != null) && (accountObj != null) && _apiServer.verifyUser(userId)) {
265+
if ((userId != null) && (account != null)
266+
&& (accountObj != null) && _apiServer.verifyUser(userId)) {
269267
String[] command = (String[]) params.get("command");
270268
if (command == null) {
271269
s_logger.info("missing command, ignoring request...");
@@ -276,9 +274,8 @@ private void processRequest(HttpServletRequest req, HttpServletResponse resp) {
276274
}
277275
UserContext.updateContext(userId, (Account) accountObj, session.getId());
278276
} else {
279-
// Invalidate the session to ensure we won't allow a request across management server restarts if the userId
280-
// was serialized to the
281-
// stored session
277+
// Invalidate the session to ensure we won't allow a request across management server
278+
// restarts if the userId was serialized to the stored session
282279
try {
283280
session.invalidate();
284281
} catch (IllegalStateException ise) {
@@ -389,12 +386,11 @@ private String getLoginSuccessResponse(HttpSession session, String responseType)
389386
StringBuffer sb = new StringBuffer();
390387
int inactiveInterval = session.getMaxInactiveInterval();
391388

392-
String user_UUID = (String)session.getAttribute("user_UUID");
393-
session.removeAttribute("user_UUID");
389+
String user_UUID = (String)session.getAttribute("user_UUID");
390+
session.removeAttribute("user_UUID");
394391

395-
String domain_UUID = (String)session.getAttribute("domain_UUID");
396-
session.removeAttribute("domain_UUID");
397-
392+
String domain_UUID = (String)session.getAttribute("domain_UUID");
393+
session.removeAttribute("domain_UUID");
398394

399395
if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
400396
sb.append("{ \"loginresponse\" : { ");

0 commit comments

Comments
 (0)