api: minor fixes in ApiServlet

- Reusing local variable for string splitting/processing
- Fix comments
- Fix indentations

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2012-12-10 16:19:40 -08:00
parent c8923c9625
commit 8fbbc76466

View File

@ -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<String, Object[]> params = new HashMap<String, Object[]>();
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\" : { ");