From 8fbbc7646648c86da56239d9cfee8633edaf2484 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Mon, 10 Dec 2012 16:19:40 -0800 Subject: [PATCH] api: minor fixes in ApiServlet - Reusing local variable for string splitting/processing - Fix comments - Fix indentations Signed-off-by: Rohit Yadav --- server/src/com/cloud/api/ApiServlet.java | 30 ++++++++++-------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index 4c2739cb323..7e1f2c39bf6 100755 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -86,8 +86,8 @@ public class ApiServlet extends HttpServlet { for (String param : paramsInQueryString) { String[] paramTokens = param.split("="); if (paramTokens != null && paramTokens.length == 2) { - String name = param.split("=")[0]; - String value = param.split("=")[1]; + String name = paramTokens[0]; + String value = paramTokens[1]; try { name = URLDecoder.decode(name, "UTF-8"); @@ -99,7 +99,7 @@ public class ApiServlet extends HttpServlet { } params.put(name, new String[] { value }); } else { - s_logger.debug("Invalid paramemter in URL found. param: " + param); + s_logger.debug("Invalid parameter in URL found. param: " + param); } } } @@ -115,13 +115,10 @@ public class ApiServlet extends HttpServlet { Map params = new HashMap(); params.putAll(req.getParameterMap()); - // // For HTTP GET requests, it seems that HttpServletRequest.getParameterMap() actually tries // to unwrap URL encoded content from ISO-9959-1. - // - // After failed in using setCharacterEncoding() to control it, end up with following hacking : for all GET requests, - // we will override it with our-own way of UTF-8 based URL decoding. - // + // After failed in using setCharacterEncoding() to control it, end up with following hacking: + // for all GET requests, we will override it with our-own way of UTF-8 based URL decoding. utf8Fixup(req, params); // logging the request start and end in management log for easy debugging @@ -265,7 +262,8 @@ public class ApiServlet extends HttpServlet { } // Do a sanity check here to make sure the user hasn't already been deleted - if ((userId != null) && (account != null) && (accountObj != null) && _apiServer.verifyUser(userId)) { + if ((userId != null) && (account != null) + && (accountObj != null) && _apiServer.verifyUser(userId)) { String[] command = (String[]) params.get("command"); if (command == null) { s_logger.info("missing command, ignoring request..."); @@ -276,9 +274,8 @@ public class ApiServlet extends HttpServlet { } UserContext.updateContext(userId, (Account) accountObj, session.getId()); } else { - // Invalidate the session to ensure we won't allow a request across management server restarts if the userId - // was serialized to the - // stored session + // Invalidate the session to ensure we won't allow a request across management server + // restarts if the userId was serialized to the stored session try { session.invalidate(); } catch (IllegalStateException ise) { @@ -389,12 +386,11 @@ public class ApiServlet extends HttpServlet { StringBuffer sb = new StringBuffer(); int inactiveInterval = session.getMaxInactiveInterval(); - String user_UUID = (String)session.getAttribute("user_UUID"); - session.removeAttribute("user_UUID"); + String user_UUID = (String)session.getAttribute("user_UUID"); + session.removeAttribute("user_UUID"); - String domain_UUID = (String)session.getAttribute("domain_UUID"); - session.removeAttribute("domain_UUID"); - + String domain_UUID = (String)session.getAttribute("domain_UUID"); + session.removeAttribute("domain_UUID"); if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { sb.append("{ \"loginresponse\" : { ");