geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject incubator-geode git commit: GEODE-1469: correctly handle the step arguements in http request
Date Thu, 02 Jun 2016 22:40:05 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop a3a721a18 -> 711fc3518


GEODE-1469: correctly handle the step arguements in http request


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/711fc351
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/711fc351
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/711fc351

Branch: refs/heads/develop
Commit: 711fc3518eb802d9400e740a4011a189ca0fd372
Parents: a3a721a
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Tue May 31 10:33:16 2016 -0700
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Thu Jun 2 15:38:23 2016 -0700

----------------------------------------------------------------------
 .../cli/multistep/CLIMultiStepHelper.java       | 22 +++++++----------
 .../controllers/AbstractCommandsController.java |  6 ++---
 .../controllers/ConfigCommandsController.java   |  2 +-
 .../support/LoginHandlerInterceptor.java        | 25 +++++++++++++-------
 .../internal/web/http/ClientHttpRequest.java    |  9 +++++++
 5 files changed, 38 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/711fc351/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/multistep/CLIMultiStepHelper.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/multistep/CLIMultiStepHelper.java
b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/multistep/CLIMultiStepHelper.java
index 393f09b..0e05bc5 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/multistep/CLIMultiStepHelper.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/multistep/CLIMultiStepHelper.java
@@ -20,9 +20,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.springframework.shell.event.ParseResult;
-import org.springframework.util.ReflectionUtils;
-
 import com.gemstone.gemfire.LogWriter;
 import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.management.cli.Result;
@@ -42,6 +39,9 @@ import com.gemstone.gemfire.management.internal.cli.result.ResultData;
 import com.gemstone.gemfire.management.internal.cli.result.TabularResultData;
 import com.gemstone.gemfire.management.internal.cli.shell.Gfsh;
 
+import org.springframework.shell.event.ParseResult;
+import org.springframework.util.ReflectionUtils;
+
 /**
  * Utility class to abstract CompositeResultData for Multi-step commands
  * Also contain execution strategy for multi-step commands
@@ -115,8 +115,12 @@ public class CLIMultiStepHelper {
         if (shell.isConnectedAndReady()) {
           if (GfshParseResult.class.isInstance(parseResult)) {
             GfshParseResult gfshParseResult = (GfshParseResult) parseResult;
-
-            CommandRequest commandRequest = new CommandRequest(gfshParseResult, prepareJSONArgs(shell.getEnv(),
nextStepArgs));
+            // this makes sure that "quit" step will correctly update the environment with
empty stepArgs
+            if (nextStepArgs != null) {
+              GfJsonObject argsJSon = nextStepArgs.getSectionGfJsonObject();
+              shell.setEnvProperty(CLIMultiStepHelper.STEP_ARGS, argsJSon.toString());
+            }
+            CommandRequest commandRequest = new CommandRequest(gfshParseResult, shell.getEnv());
             commandRequest.setCustomInput(changeStepName(gfshParseResult.getUserInput(),
nextStep.getName()));
             commandRequest.getCustomParameters().put(CliStrings.QUERY__STEPNAME, nextStep.getName());
 
@@ -159,14 +163,6 @@ public class CLIMultiStepHelper {
     }
   }
 
-  public static Map<String, String> prepareJSONArgs(Map<String, String> env,
SectionResultData nextStepArgs) {
-    if (nextStepArgs != null) {
-      GfJsonObject argsJSon = nextStepArgs.getSectionGfJsonObject();
-      env.put(CLIMultiStepHelper.STEP_ARGS, argsJSon.toString());
-    }
-    return env;
-  }
-
   public static SectionResultData extractArgumentsForNextStep(Result result) {
     CommandResult cResult = (CommandResult) result;
     if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/711fc351/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/AbstractCommandsController.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/AbstractCommandsController.java
b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/AbstractCommandsController.java
index f78c6f9..0d94c7f 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/AbstractCommandsController.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/AbstractCommandsController.java
@@ -534,16 +534,16 @@ public abstract class AbstractCommandsController {
   }
 
   protected Callable<ResponseEntity<String>> getProcessCommandCallable(final
String command){
-    return getProcessCommandCallable(command, null);
+    return getProcessCommandCallable(command, getEnvironment(), null);
   }
 
-  protected Callable<ResponseEntity<String>> getProcessCommandCallable(final
String command, final byte[][] fileData){
+  protected Callable<ResponseEntity<String>> getProcessCommandCallable(final
String command, final Map<String, String> environment, final byte[][] fileData){
     Callable callable = new Callable<ResponseEntity<String>>() {
       @Override
       public ResponseEntity<String> call() throws Exception {
         String result = null;
         try {
-          result = processCommand(command, fileData);
+          result = processCommand(command, environment, fileData);
         }
         catch(NotAuthorizedException ex){
           return new ResponseEntity<String>(ex.getMessage(), HttpStatus.FORBIDDEN);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/711fc351/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/ConfigCommandsController.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/ConfigCommandsController.java
b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/ConfigCommandsController.java
index ebacd3d..ece461b 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/ConfigCommandsController.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/ConfigCommandsController.java
@@ -193,7 +193,7 @@ public class ConfigCommandsController extends AbstractMultiPartCommandsControlle
 
     command.addOption(CliStrings.IMPORT_SHARED_CONFIG__ZIP, zipFileName);
 
-    return getProcessCommandCallable(command.toString(), ConvertUtils.convert(zipFileResources));
+    return getProcessCommandCallable(command.toString(), getEnvironment(), ConvertUtils.convert(zipFileResources));
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/711fc351/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptor.java
b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptor.java
index 13face2..52cce90 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptor.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptor.java
@@ -16,22 +16,25 @@
  */
 package com.gemstone.gemfire.management.internal.web.controllers.support;
 
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.internal.logging.LogService;
 import com.gemstone.gemfire.internal.security.GeodeSecurityUtil;
+import com.gemstone.gemfire.management.internal.cli.multistep.CLIMultiStepHelper;
 import com.gemstone.gemfire.management.internal.security.ResourceConstants;
+import com.gemstone.gemfire.management.internal.web.util.UriUtils;
 import com.gemstone.gemfire.security.Authenticator;
+
 import org.apache.logging.log4j.Logger;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * The GetEnvironmentHandlerInterceptor class handles extracting Gfsh environment variables
encoded in the HTTP request
  * message as request parameters.
@@ -73,10 +76,14 @@ public class LoginHandlerInterceptor extends HandlerInterceptorAdapter
{
 
     for (Enumeration<String> requestParameters = request.getParameterNames(); requestParameters.hasMoreElements();
) {
       final String requestParameter = requestParameters.nextElement();
-
       if (requestParameter.startsWith(ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX)) {
+        String requestValue = request.getParameter(requestParameter);
+        //GEODE-1469: since we enced stepArgs, we will need to decode it here. See #ClientHttpRequest
+        if(requestParameter.contains(CLIMultiStepHelper.STEP_ARGS)){
+          requestValue = UriUtils.decode(requestValue);
+        }
         requestParameterValues.put(requestParameter.substring(ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX.length()),
-          request.getParameter(requestParameter));
+          requestValue);
       }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/711fc351/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/http/ClientHttpRequest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/http/ClientHttpRequest.java
b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/http/ClientHttpRequest.java
index 447733d..4548d04 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/http/ClientHttpRequest.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/http/ClientHttpRequest.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import com.gemstone.gemfire.internal.lang.Filter;
 import com.gemstone.gemfire.internal.lang.ObjectUtils;
 import com.gemstone.gemfire.internal.util.CollectionUtils;
+import com.gemstone.gemfire.management.internal.cli.multistep.CLIMultiStepHelper;
 import com.gemstone.gemfire.management.internal.web.domain.Link;
 import com.gemstone.gemfire.management.internal.web.util.UriUtils;
 
@@ -257,6 +258,14 @@ public class ClientHttpRequest implements HttpRequest {
       final Map<String, List<Object>> queryParameters = CollectionUtils.removeKeys(
         new LinkedMultiValueMap<String, Object>(getParameters()), new Filter<Map.Entry<String,
List<Object>>>() {
           @Override public boolean accept(final Map.Entry<String, List<Object>>
entry) {
+            //GEODE-1469: since stepArgs has json string in there, we will need to encode
it so that it won't interfere with the expand() call afterwards
+            if(entry.getKey().contains(CLIMultiStepHelper.STEP_ARGS)){
+              List<Object> stepArgsList = entry.getValue();
+              if(stepArgsList!=null){
+                String stepArgs = (String)stepArgsList.remove(0);
+                stepArgsList.add(UriUtils.encode(stepArgs));
+              }
+            }
             return !pathVariables.contains(entry.getKey());
           }
       });


Mime
View raw message