incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject git commit: refs/heads/4.1 - CLOUDSTACK-1142: Refactor handleRequest definition, clean redundant code
Date Tue, 05 Feb 2013 05:09:46 GMT
Updated Branches:
  refs/heads/4.1 dcb2e5a8e -> 07fa69cac


CLOUDSTACK-1142: Refactor handleRequest definition, clean redundant code

- Get rid of boolean decode arg
- Method assumes that OTW params have been already decoded
- Remove redundant code that tries to decode again based on boolean arg

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
(cherry picked from commit 2b267c1ceb898564bbf60bec161739bc8ae6f6d9)

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/07fa69ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/07fa69ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/07fa69ca

Branch: refs/heads/4.1
Commit: 07fa69cac5c54da1d5f9a829a1524b2133bd51da
Parents: dcb2e5a
Author: Rohit Yadav <bhaisaab@apache.org>
Authored: Tue Feb 5 10:37:09 2013 +0530
Committer: Rohit Yadav <bhaisaab@apache.org>
Committed: Tue Feb 5 10:39:20 2013 +0530

----------------------------------------------------------------------
 server/src/com/cloud/api/ApiServer.java  |   23 +++--------------------
 server/src/com/cloud/api/ApiServlet.java |    2 +-
 2 files changed, 4 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/07fa69ca/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index 0df6cd4..233da15 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -19,13 +19,11 @@ package com.cloud.api;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InterruptedIOException;
-import java.io.UnsupportedEncodingException;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.security.SecureRandom;
 import java.text.DateFormat;
@@ -292,7 +290,7 @@ public class ApiServer implements HttpRequestHandler {
                 // always trust commands from API port, user context will always be UID_SYSTEM/ACCOUNT_ID_SYSTEM
                 UserContext.registerContext(_systemUser.getId(), _systemAccount, null, true);
                 sb.insert(0, "(userId=" + User.UID_SYSTEM + " accountId=" + Account.ACCOUNT_ID_SYSTEM
+ " sessionId=" + null + ") ");
-                String responseText = handleRequest(parameterMap, false, responseType, sb);
+                String responseText = handleRequest(parameterMap, responseType, sb);
                 sb.append(" 200 " + ((responseText == null) ? 0 : responseText.length()));
 
                 writeResponse(response, responseText, HttpStatus.SC_OK, responseType, null);
@@ -312,7 +310,7 @@ public class ApiServer implements HttpRequestHandler {
     }
 
     @SuppressWarnings("rawtypes")
-    public String handleRequest(Map params, boolean decode, String responseType, StringBuffer
auditTrailSb) throws ServerApiException {
+    public String handleRequest(Map params, String responseType, StringBuffer auditTrailSb)
throws ServerApiException {
         String response = null;
         String[] command = null;
         try {
@@ -338,22 +336,7 @@ public class ApiServer implements HttpRequestHandler {
                         continue;
                     }
                     String[] value = (String[]) params.get(key);
-
-                    String decodedValue = null;
-                    if (decode) {
-                        try {
-                            decodedValue = URLDecoder.decode(value[0], "UTF-8");
-                        } catch (UnsupportedEncodingException usex) {
-                            s_logger.warn(key + " could not be decoded, value = " + value[0]);
-                            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, key +
" could not be decoded, received value " + value[0]);
-                        } catch (IllegalArgumentException iae) {
-                            s_logger.warn(key + " could not be decoded, value = " + value[0]);
-                            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, key +
" could not be decoded, received value " + value[0] + " which contains illegal characters
eg.%");
-                        }
-                    } else {
-                        decodedValue = value[0];
-                    }
-                    paramMap.put(key, decodedValue);
+                    paramMap.put(key, value[0]);
                 }
 
                 Class<?> cmdClass = getCmdClass(command[0]);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/07fa69ca/server/src/com/cloud/api/ApiServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java
index 2d73c58..e5c1db7 100755
--- a/server/src/com/cloud/api/ApiServlet.java
+++ b/server/src/com/cloud/api/ApiServlet.java
@@ -299,7 +299,7 @@ public class ApiServlet extends HttpServlet {
                 auditTrailSb.insert(0, "(userId=" + UserContext.current().getCallerUserId()
+ " accountId="
                         + UserContext.current().getCaller().getId() + " sessionId=" + (session
!= null ? session.getId() : null) + ")");
 
-                    String response = _apiServer.handleRequest(params, false, responseType,
auditTrailSb);
+                    String response = _apiServer.handleRequest(params, responseType, auditTrailSb);
                     writeResponse(resp, response != null ? response : "", HttpServletResponse.SC_OK,
responseType);
             } else {
                 if (session != null) {


Mime
View raw message