You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by zh...@apache.org on 2021/09/09 10:13:12 UTC
[incubator-shenyu] branch master updated: [Integration: Test]
refactor spring cloud (#2045)
This is an automated email from the ASF dual-hosted git repository.
zhangyonglun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new dbcac50 [Integration: Test] refactor spring cloud (#2045)
dbcac50 is described below
commit dbcac506a670e090242e2f887705519c93e3000e
Author: xiaoyu <xi...@apache.org>
AuthorDate: Thu Sep 9 18:13:05 2021 +0800
[Integration: Test] refactor spring cloud (#2045)
* [Integration: Test] refactor spring cloud
* [Integration: Test] refactor spring cloud
* [Integration: Test] refactor spring cloud
* modify docker
---
.../apache/shenyu/common/constant/Constants.java | 2 +-
.../org/apache/shenyu/common/enums/PluginEnum.java | 115 +++++++++++----------
.../shenyu-integrated-test-common/pom.xml | 1 -
.../common}/AbstractPluginDataInit.java | 3 +-
.../http/combination/ContextPathPluginTest.java | 1 +
.../test/http/combination/JwtPluginTest.java | 1 +
.../http/combination/ParamMappingPluginTest.java | 1 +
.../test/http/combination/RedirectPluginTest.java | 1 +
.../test/http/combination/RequestPluginTest.java | 1 +
.../test/http/combination/SentinelPluginTest.java | 1 +
.../test/http/combination/WafPluginTest.java | 1 +
.../docker-compose.yml | 8 +-
.../src/main/resources/admin-config/schema.sql | 21 ----
.../springcloud/SpringCloudPluginTest.java | 14 ++-
...ormPlugin.java => RpcParamTransformPlugin.java} | 11 +-
...nTest.java => RpcParamTransformPluginTest.java} | 22 ++--
.../modify/response/ModifyResponsePlugin.java | 11 +-
.../plugin/motan/response/MotanResponsePlugin.java | 84 ---------------
.../starter/gateway/ShenyuConfiguration.java | 4 +-
.../plugin/motan/MotanPluginConfiguration.java | 12 ---
20 files changed, 102 insertions(+), 213 deletions(-)
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
index af064e8..64399fb 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
@@ -113,7 +113,7 @@ public interface Constants {
String HTTP_URL = "httpUrl";
/**
- * The constant PARAM_TRANSFORM.
+ * The constant RPC_PARAM_TRANSFORM.
*/
String PARAM_TRANSFORM = "param_transform";
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
index 6fc58ee..7f1cad6 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
@@ -24,151 +24,156 @@ import java.util.List;
* PluginEnum.
*/
public enum PluginEnum {
-
+
/**
* Global plugin enum.
*/
GLOBAL(10, 0, "global"),
-
+
/**
* Sign plugin enum.
*/
SIGN(20, 0, "sign"),
-
+
/**
* Jwt plugin enum.
*/
JWT(30, 0, "jwt"),
-
+
/**
* OAuth2 plugin enum.
*/
OAUTH2(40, 0, "oauth2"),
-
+
/**
* Waf plugin enum.
*/
WAF(50, 0, "waf"),
-
+
/**
* Rate limiter plugin enum.
*/
RATE_LIMITER(60, 0, "rate_limiter"),
-
+
/**
* Param mapping plugin enum.
*/
PARAM_MAPPING(70, 0, "param_mapping"),
-
+
/**
* Context path plugin enum.
*/
CONTEXT_PATH(80, 0, "context_path"),
-
+
/**
* Rewrite plugin enum.
*/
REWRITE(90, 0, "rewrite"),
-
+
/**
* Cryptor request plugin enum.
*/
CRYPTOR_REQUEST(100, 0, "cryptor_request"),
-
+
/**
* Redirect plugin enum.
*/
REDIRECT(110, 0, "redirect"),
-
+
/**
* Request plugin enum.
*/
REQUEST(120, 0, "request"),
-
- /**
- * ModifyResponse plugin enum.
- */
- MODIFY_RESPONSE(130, 0, "modifyResponse"),
-
+
/**
* Hystrix plugin enum.
*/
HYSTRIX(140, 0, "hystrix"),
-
+
/**
* Sentinel plugin enum.
*/
SENTINEL(150, 0, "sentinel"),
-
+
/**
* Resilence4J plugin enum.
*/
RESILIENCE4J(160, 0, "resilience4j"),
-
+
/**
* Logging plugin enum.
*/
LOGGING(170, 0, "logging"),
-
+
+ /**
+ * Monitor plugin enum.
+ */
+ MONITOR(180, 0, "monitor"),
+
/**
* Divide plugin enum.
*/
- DIVIDE(180, 0, "divide"),
-
+ DIVIDE(200, 0, "divide"),
+
/**
* springCloud plugin enum.
*/
- SPRING_CLOUD(190, 0, "springCloud"),
-
+ SPRING_CLOUD(200, 0, "springCloud"),
+
/**
* webSocket plugin enum.
*/
WEB_SOCKET(200, 0, "websocket"),
-
+
+ /**
+ * Web client plugin enum.
+ */
+ WEB_CLIENT(210, 0, "webClient"),
+
/**
* Param transform plugin enum.
*/
- PARAM_TRANSFORM(210, 0, "paramTransform"),
-
+ RPC_PARAM_TRANSFORM(300, 0, "paramTransform"),
+
/**
* Dubbo plugin enum.
*/
- DUBBO(220, 0, "dubbo"),
-
+ DUBBO(310, 0, "dubbo"),
+
/**
* Sofa plugin enum.
*/
- SOFA(230, 0, "sofa"),
-
+ SOFA(310, 0, "sofa"),
+
/**
* Tars plugin enum.
*/
- TARS(240, 0, "tars"),
-
+ TARS(310, 0, "tars"),
+
/**
* GPRC plugin enum.
*/
- GRPC(250, 0, "grpc"),
-
+ GRPC(310, 0, "grpc"),
+
/**
* Motan plugin enum.
*/
- MOTAN(260, 0, "motan"),
-
- /**
- * Monitor plugin enum.
- */
- MONITOR(270, 0, "monitor"),
-
+ MOTAN(310, 0, "motan"),
+
/**
* Cryptor response plugin enum.
*/
- CRYPTOR_RESPONSE(280, 0, "cryptor_response"),
-
+ CRYPTOR_RESPONSE(410, 0, "cryptor_response"),
+
/**
* Response plugin enum.
*/
- RESPONSE(290, 0, "response");
+ RESPONSE(420, 0, "response"),
+
+ /**
+ * ModifyResponse plugin enum.
+ */
+ MODIFY_RESPONSE(430, 0, "modifyResponse");
private final int code;
@@ -188,34 +193,34 @@ public enum PluginEnum {
this.role = role;
this.name = name;
}
-
+
/**
* get code.
*
- * @return code
+ * @return code code
*/
public int getCode() {
return code;
}
-
+
/**
* get role.
*
- * @return role
+ * @return role role
*/
public int getRole() {
return role;
}
-
+
/**
* get name.
*
- * @return name
+ * @return name name
*/
public String getName() {
return name;
}
-
+
/**
* get plugin enum by name.
*
@@ -227,7 +232,7 @@ public enum PluginEnum {
.filter(pluginEnum -> pluginEnum.getName().equals(name))
.findFirst().orElse(PluginEnum.GLOBAL);
}
-
+
/**
* get upstream plugin names.
*
diff --git a/shenyu-integrated-test/shenyu-integrated-test-common/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-common/pom.xml
index d43871b..00f8977 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-common/pom.xml
+++ b/shenyu-integrated-test/shenyu-integrated-test-common/pom.xml
@@ -22,7 +22,6 @@
<artifactId>shenyu-integrated-test</artifactId>
<groupId>org.apache.shenyu</groupId>
<version>2.4.1-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
</parent>
<artifactId>shenyu-integrated-test-common</artifactId>
<name>shenyu-integrated-test-common</name>
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/AbstractPluginDataInit.java b/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/AbstractPluginDataInit.java
similarity index 97%
rename from shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/AbstractPluginDataInit.java
rename to shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/AbstractPluginDataInit.java
index dd6042d..7edc01e 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/AbstractPluginDataInit.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/AbstractPluginDataInit.java
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-package org.apache.shenyu.integrated.test.http.combination;
+package org.apache.shenyu.integratedtest.common;
import org.apache.shenyu.common.dto.ConditionData;
import org.apache.shenyu.common.dto.PluginData;
-import org.apache.shenyu.integratedtest.common.AbstractTest;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.web.controller.PluginController.RuleLocalData;
import org.apache.shenyu.web.controller.PluginController.SelectorRuleData;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ContextPathPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ContextPathPluginTest.java
index b68fccd..49b4b45 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ContextPathPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ContextPathPluginTest.java
@@ -21,6 +21,7 @@ import org.apache.shenyu.common.dto.ConditionData;
import org.apache.shenyu.common.enums.OperatorEnum;
import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.dto.OrderDTO;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.web.controller.PluginController;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/JwtPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/JwtPluginTest.java
index a91f865..ff7ed37 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/JwtPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/JwtPluginTest.java
@@ -23,6 +23,7 @@ import org.apache.shenyu.common.dto.ConditionData;
import org.apache.shenyu.common.enums.OperatorEnum;
import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.web.controller.PluginController;
import org.junit.AfterClass;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ParamMappingPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ParamMappingPluginTest.java
index 85f5139..69c3d51 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ParamMappingPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/ParamMappingPluginTest.java
@@ -23,6 +23,7 @@ import org.apache.shenyu.common.enums.OperatorEnum;
import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.dto.OrderDTO;
import org.apache.shenyu.integratedtest.common.dto.UserDTO;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RedirectPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RedirectPluginTest.java
index 681cd55..a78b822 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RedirectPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RedirectPluginTest.java
@@ -23,6 +23,7 @@ import org.apache.shenyu.common.enums.OperatorEnum;
import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.web.controller.PluginController.RuleLocalData;
import org.junit.AfterClass;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RequestPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RequestPluginTest.java
index 090da53..01fd2e6 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RequestPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RequestPluginTest.java
@@ -24,6 +24,7 @@ import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.web.controller.PluginController.RuleLocalData;
import org.junit.AfterClass;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/SentinelPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/SentinelPluginTest.java
index efdb01f..ec391af 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/SentinelPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/SentinelPluginTest.java
@@ -23,6 +23,7 @@ import org.apache.shenyu.common.enums.OperatorEnum;
import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.web.controller.PluginController.RuleLocalData;
import org.junit.AfterClass;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/WafPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/WafPluginTest.java
index ccd10a9..3eb1a1e 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/WafPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/WafPluginTest.java
@@ -24,6 +24,7 @@ import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.enums.WafEnum;
import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
import org.apache.shenyu.web.controller.PluginController.RuleLocalData;
import org.junit.AfterClass;
diff --git a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml
index 709ab8e..dd9de05 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml
@@ -21,15 +21,11 @@ services:
restart: always
networks:
- shenyu
- volumes:
- - type: bind
- source: ./src/main/resources/admin-config/
- target: /opt/sql/
ports:
- 9095:9095
environment:
- SPRING_PROFILES_ACTIVE=h2
- - "shenyu.database.init_script=sql-script/h2/schema.sql;file:/opt/sql/schema.sql"
+ - "shenyu.database.init_script=sql-script/h2/schema.sql"
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
timeout: 2s
@@ -77,7 +73,7 @@ services:
- shenyu
depends_on:
shenyu-integrated-test-spring-cloud:
- condition: service_healthy
+ condition: service_healthy
# from http plugin dockerfile
shenyu-integrated-test-spring-cloud:
container_name: shenyu-integrated-test-spring-cloud
diff --git a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/admin-config/schema.sql b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/admin-config/schema.sql
deleted file mode 100644
index c726528..0000000
--- a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/admin-config/schema.sql
+++ /dev/null
@@ -1,21 +0,0 @@
--- noinspection SqlNoDataSourceInspectionForFile
-
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you under the Apache License, Version 2.0 (the
--- "License"); you may not use this file except in compliance
--- with the License. You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
-
-/** prepare rate limit **/
-UPDATE `plugin` SET enabled = 1 WHERE id = '8';
-UPDATE `plugin` SET enabled = 0 WHERE id = '5';
\ No newline at end of file
diff --git a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/test/java/org/apache/shenyu/integratedtest/springcloud/SpringCloudPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/test/java/org/apache/shenyu/integratedtest/springcloud/SpringCloudPluginTest.java
index f80c59b..b04fb62 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/test/java/org/apache/shenyu/integratedtest/springcloud/SpringCloudPluginTest.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/test/java/org/apache/shenyu/integratedtest/springcloud/SpringCloudPluginTest.java
@@ -17,16 +17,26 @@
package org.apache.shenyu.integratedtest.springcloud;
-import org.apache.shenyu.integratedtest.common.AbstractTest;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.dto.OrderDTO;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
+import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
-public class SpringCloudPluginTest extends AbstractTest {
+public class SpringCloudPluginTest extends AbstractPluginDataInit {
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ String pluginResult = initPlugin(PluginEnum.SPRING_CLOUD.getName(), "");
+ assertThat(pluginResult, is("success"));
+ }
@Test
public void testHelloWorld() throws IOException {
diff --git a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/ParamTransformPlugin.java b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/RpcParamTransformPlugin.java
similarity index 94%
rename from shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/ParamTransformPlugin.java
rename to shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/RpcParamTransformPlugin.java
index e3f0580..ffe46f7 100644
--- a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/ParamTransformPlugin.java
+++ b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/RpcParamTransformPlugin.java
@@ -45,14 +45,14 @@ import java.util.Objects;
/**
* The param transform plugin.
*/
-public class ParamTransformPlugin implements ShenyuPlugin {
+public class RpcParamTransformPlugin implements ShenyuPlugin {
private final List<HttpMessageReader<?>> messageReaders;
/**
* Instantiates a new param transform plugin.
*/
- public ParamTransformPlugin() {
+ public RpcParamTransformPlugin() {
this.messageReaders = HandlerStrategies.withDefaults().messageReaders();
}
@@ -75,12 +75,12 @@ public class ParamTransformPlugin implements ShenyuPlugin {
@Override
public int getOrder() {
- return PluginEnum.PARAM_TRANSFORM.getCode();
+ return PluginEnum.RPC_PARAM_TRANSFORM.getCode();
}
@Override
public String named() {
- return PluginEnum.PARAM_TRANSFORM.getName();
+ return PluginEnum.RPC_PARAM_TRANSFORM.getName();
}
private Mono<Void> body(final ServerWebExchange exchange, final ServerHttpRequest serverHttpRequest, final ShenyuPluginChain chain) {
@@ -127,7 +127,6 @@ public class ParamTransformPlugin implements ShenyuPlugin {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);
- String bodyString = new String(bytes, StandardCharsets.UTF_8);
- return bodyString;
+ return new String(bytes, StandardCharsets.UTF_8);
}
}
diff --git a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/ParamTransformPluginTest.java b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/RpcParamTransformPluginTest.java
similarity index 85%
rename from shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/ParamTransformPluginTest.java
rename to shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/RpcParamTransformPluginTest.java
index 5de24d2..45668d2 100644
--- a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/ParamTransformPluginTest.java
+++ b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/RpcParamTransformPluginTest.java
@@ -41,18 +41,18 @@ import static org.mockito.Mockito.mock;
* TThe param transform plugin test.
*/
@RunWith(MockitoJUnitRunner.class)
-public final class ParamTransformPluginTest {
+public final class RpcParamTransformPluginTest {
private ShenyuPluginChain chain;
- private ParamTransformPlugin paramTransformPlugin;
+ private RpcParamTransformPlugin rpcParamTransformPlugin;
/**
* Sets up.
*/
@Before
public void setUp() {
- paramTransformPlugin = new ParamTransformPlugin();
+ rpcParamTransformPlugin = new RpcParamTransformPlugin();
chain = mock(ShenyuPluginChain.class);
}
@@ -61,8 +61,8 @@ public final class ParamTransformPluginTest {
*/
@Test
public void testGetOrder() {
- int result = paramTransformPlugin.getOrder();
- assertEquals(PluginEnum.PARAM_TRANSFORM.getCode(), result);
+ int result = rpcParamTransformPlugin.getOrder();
+ assertEquals(PluginEnum.RPC_PARAM_TRANSFORM.getCode(), result);
}
/**
@@ -70,8 +70,8 @@ public final class ParamTransformPluginTest {
*/
@Test
public void testNamed() {
- String result = paramTransformPlugin.named();
- assertEquals(PluginEnum.PARAM_TRANSFORM.getName(), result);
+ String result = rpcParamTransformPlugin.named();
+ assertEquals(PluginEnum.RPC_PARAM_TRANSFORM.getName(), result);
}
/**
@@ -85,7 +85,7 @@ public final class ParamTransformPluginTest {
ShenyuContext context = new ShenyuContext();
context.setRpcType(RpcTypeEnum.DUBBO.getName());
exchange.getAttributes().put(Constants.CONTEXT, context);
- Mono<Void> result = paramTransformPlugin.execute(exchange, chain);
+ Mono<Void> result = rpcParamTransformPlugin.execute(exchange, chain);
StepVerifier.create(result).expectSubscription().verifyComplete();
}
@@ -100,7 +100,7 @@ public final class ParamTransformPluginTest {
ShenyuContext context = new ShenyuContext();
context.setRpcType(RpcTypeEnum.DUBBO.getName());
exchange.getAttributes().put(Constants.CONTEXT, context);
- Mono<Void> result = paramTransformPlugin.execute(exchange, chain);
+ Mono<Void> result = rpcParamTransformPlugin.execute(exchange, chain);
StepVerifier.create(result).expectSubscription().verifyComplete();
}
@@ -115,7 +115,7 @@ public final class ParamTransformPluginTest {
ShenyuContext context = new ShenyuContext();
context.setRpcType(RpcTypeEnum.DUBBO.getName());
exchange.getAttributes().put(Constants.CONTEXT, context);
- Mono<Void> result = paramTransformPlugin.execute(exchange, chain);
+ Mono<Void> result = rpcParamTransformPlugin.execute(exchange, chain);
StepVerifier.create(result).expectSubscription().verifyComplete();
}
@@ -130,7 +130,7 @@ public final class ParamTransformPluginTest {
ShenyuContext context = new ShenyuContext();
context.setRpcType(RpcTypeEnum.DUBBO.getName());
exchange.getAttributes().put(Constants.CONTEXT, context);
- Mono<Void> result = paramTransformPlugin.execute(exchange, chain);
+ Mono<Void> result = rpcParamTransformPlugin.execute(exchange, chain);
StepVerifier.create(result).expectSubscription().verifyComplete();
}
}
diff --git a/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/modify/response/ModifyResponsePlugin.java b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/modify/response/ModifyResponsePlugin.java
index fa5d358..625840b 100644
--- a/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/modify/response/ModifyResponsePlugin.java
+++ b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/modify/response/ModifyResponsePlugin.java
@@ -60,11 +60,7 @@ import java.util.Set;
* ModifyResponse plugin.
*/
public class ModifyResponsePlugin extends AbstractShenyuPlugin {
-
- public ModifyResponsePlugin() {
-
- }
-
+
@Override
protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
if (Objects.isNull(rule)) {
@@ -118,11 +114,6 @@ public class ModifyResponsePlugin extends AbstractShenyuPlugin {
return PluginEnum.MODIFY_RESPONSE.getName();
}
- @Override
- public boolean skip(final ServerWebExchange exchange) {
- return false;
- }
-
static class ModifyServerHttpResponse extends ServerHttpResponseDecorator {
private final ServerWebExchange exchange;
diff --git a/shenyu-plugin/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/response/MotanResponsePlugin.java b/shenyu-plugin/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/response/MotanResponsePlugin.java
deleted file mode 100644
index 03815f6..0000000
--- a/shenyu-plugin/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/response/MotanResponsePlugin.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * Contributor license agreements.See the NOTICE file distributed with
- * This work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * he License.You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.shenyu.plugin.motan.response;
-
-import org.apache.shenyu.common.constant.Constants;
-import org.apache.shenyu.common.enums.PluginEnum;
-import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.common.utils.JsonUtils;
-import org.apache.shenyu.plugin.api.ShenyuPlugin;
-import org.apache.shenyu.plugin.api.ShenyuPluginChain;
-import org.apache.shenyu.plugin.api.context.ShenyuContext;
-import org.apache.shenyu.plugin.api.result.ShenyuResultEnum;
-import org.apache.shenyu.plugin.api.result.ShenyuResultWrap;
-import org.apache.shenyu.plugin.api.utils.WebFluxResultUtils;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-import java.util.Objects;
-
-/**
- * this is motan response plugin.
- */
-public class MotanResponsePlugin implements ShenyuPlugin {
-
- /**
- * Process the Web request and (optionally) delegate to the next
- * {@code WebFilter} through the given {@link ShenyuPluginChain}.
- *
- * @param exchange the current server exchange
- * @param chain provides a way to delegate to the next filter
- * @return {@code Mono<Void>} to indicate when request processing is complete
- */
- @Override
- public Mono<Void> execute(final ServerWebExchange exchange, final ShenyuPluginChain chain) {
- return chain.execute(exchange).then(Mono.defer(() -> {
- final Object result = exchange.getAttribute(Constants.MOTAN_RPC_RESULT);
- if (Objects.isNull(result)) {
- Object error = ShenyuResultWrap.error(ShenyuResultEnum.SERVICE_RESULT_ERROR.getCode(), ShenyuResultEnum.SERVICE_RESULT_ERROR.getMsg(), null);
- return WebFluxResultUtils.result(exchange, error);
- }
- Object success = ShenyuResultWrap.success(ShenyuResultEnum.SUCCESS.getCode(), ShenyuResultEnum.SUCCESS.getMsg(), JsonUtils.removeClass(result));
- return WebFluxResultUtils.result(exchange, success);
- }));
- }
-
- @Override
- public boolean skip(final ServerWebExchange exchange) {
- final ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
- assert shenyuContext != null;
- return !Objects.equals(shenyuContext.getRpcType(), RpcTypeEnum.MOTAN.getName());
- }
-
- @Override
- public int getOrder() {
- return PluginEnum.RESPONSE.getCode();
- }
-
- /**
- * acquire plugin name.
- *
- * @return plugin name.
- */
- @Override
- public String named() {
- return PluginEnum.RESPONSE.getName();
- }
-}
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java
index d909d99..e5132bc 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java
@@ -20,7 +20,7 @@ package org.apache.shenyu.springboot.starter.gateway;
import org.apache.shenyu.common.config.ShenyuConfig;
import org.apache.shenyu.plugin.api.RemoteAddressResolver;
import org.apache.shenyu.plugin.api.ShenyuPlugin;
-import org.apache.shenyu.plugin.base.ParamTransformPlugin;
+import org.apache.shenyu.plugin.base.RpcParamTransformPlugin;
import org.apache.shenyu.plugin.base.cache.CommonPluginDataSubscriber;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
import org.apache.shenyu.sync.data.api.PluginDataSubscriber;
@@ -104,7 +104,7 @@ public class ShenyuConfiguration {
*/
@Bean
public ShenyuPlugin paramTransformPlugin() {
- return new ParamTransformPlugin();
+ return new RpcParamTransformPlugin();
}
/**
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-motan/src/main/java/org/apache/shenyu/springboot/starter/plugin/motan/MotanPluginConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-motan/src/main/java/org/apache/shenyu/springboot/starter/plugin/motan/MotanPluginConfiguration.java
index 71b867f..8facfe0 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-motan/src/main/java/org/apache/shenyu/springboot/starter/plugin/motan/MotanPluginConfiguration.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-motan/src/main/java/org/apache/shenyu/springboot/starter/plugin/motan/MotanPluginConfiguration.java
@@ -18,14 +18,12 @@
package org.apache.shenyu.springboot.starter.plugin.motan;
-import org.apache.shenyu.plugin.api.ShenyuPlugin;
import org.apache.shenyu.plugin.api.context.ShenyuContextDecorator;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
import org.apache.shenyu.plugin.motan.MotanPlugin;
import org.apache.shenyu.plugin.motan.context.MotanShenyuContextDecorator;
import org.apache.shenyu.plugin.motan.handler.MotanPluginDataHandler;
import org.apache.shenyu.plugin.motan.proxy.MotanProxyService;
-import org.apache.shenyu.plugin.motan.response.MotanResponsePlugin;
import org.apache.shenyu.plugin.motan.subscriber.MotanMetaDataSubscriber;
import org.apache.shenyu.sync.data.api.MetaDataSubscriber;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -50,16 +48,6 @@ public class MotanPluginConfiguration {
}
/**
- * Motan response plugin shenyu plugin.
- *
- * @return the shenyu plugin
- */
- @Bean
- public ShenyuPlugin motanResponsePlugin() {
- return new MotanResponsePlugin();
- }
-
- /**
* Motan plugin data handler plugin data handler.
*
* @return the plugin data handler