You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2021/07/29 15:28:04 UTC

[GitHub] [incubator-shenyu] dengliming commented on a change in pull request #1830: refactor plugin-modify-response : Finishing method.

dengliming commented on a change in pull request #1830:
URL: https://github.com/apache/incubator-shenyu/pull/1830#discussion_r679258207



##########
File path: shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/modify/response/ModifyResponsePlugin.java
##########
@@ -175,14 +175,6 @@ public Boolean skip(final ServerWebExchange exchange) {
         private String operation(final String jsonValue, final ModifyResponseRuleHandle handle) {
             DocumentContext context = JsonPath.parse(jsonValue);
             operation(context, handle);
-            if (!CollectionUtils.isEmpty(handle.getReplaceBodyKeys())) {
-                handle.getReplaceBodyKeys().forEach(info -> {
-                    context.renameKey(info.getPath(), info.getKey(), info.getValue());
-                });
-            }
-            if (!CollectionUtils.isEmpty(handle.getRemoveBodyKeys())) {
-                handle.getRemoveBodyKeys().forEach(context::delete);
-            }
             return context.jsonString();
         }

Review comment:
       How about remove `private void operation(final DocumentContext context, final ModifyResponseRuleHandle handle)` and refactor like this?
   ```
   private String operation(final String jsonValue, final ModifyResponseRuleHandle handle) {
               DocumentContext context = JsonPath.parse(jsonValue);
               if (!CollectionUtils.isEmpty(handle.getAddBodyKeys())) {
                   handle.getAddBodyKeys().forEach(info -> context.put(info.getPath(), info.getKey(), info.getValue()));
               }
               if (!CollectionUtils.isEmpty(handle.getReplaceBodyKeys())) {
                   handle.getReplaceBodyKeys().forEach(info -> context.renameKey(info.getPath(), info.getKey(), info.getValue()));
               }
               if (!CollectionUtils.isEmpty(handle.getRemoveBodyKeys())) {
                   handle.getRemoveBodyKeys().forEach(context::delete);
               }
               return context.jsonString();
           }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org