This is an automated email from the ASF dual-hosted git repository. hefengen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push: new 1f5b5cda23 [type:feature] upgrade checkstyle plugin to 3.4.0 (#5614) 1f5b5cda23 is described below commit 1f5b5cda230c10b577712918db95c4028d902345 Author: aias00 <rok...@163.com> AuthorDate: Mon Aug 26 22:54:42 2024 +0800 [type:feature] upgrade checkstyle plugin to 3.4.0 (#5614) * [type:feature] upgrade checkstyle plugin version and migration checkstyle config * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] upgrade checkstyle plugin version and fix checkstyle errors * [type:feature] recover swagger version --- pom.xml | 3 +- script/shenyu_checkstyle.xml | 36 +++-- .../admin/listener/DataChangedEventDispatcher.java | 2 +- .../admin/service/impl/AppAuthServiceImpl.java | 4 +- .../shenyu/admin/spring/LocalDataSourceLoader.java | 2 +- .../admin/model/query/TagRelationQueryTest.java | 94 ++++++------- .../register/registrar/AbstractApiRegistrar.java | 2 +- .../shenyu/common/utils/ObjectTypeUtils.java | 16 +-- shenyu-e2e/pom.xml | 2 +- shenyu-examples/pom.xml | 3 +- .../websocket/handler/HttpAuthHandler.java | 4 +- shenyu-integrated-test/pom.xml | 3 +- .../spi/LeastActiveLoadBalanceTest.java | 2 +- .../loadbalancer/spi/P2cLoadBalancerTest.java | 2 +- .../shenyu/plugin/api/result/ShenyuResult.java | 2 +- .../shenyu/plugin/api/utils/RequestUrlUtils.java | 4 +- .../base/cache/CommonPluginDataSubscriber.java | 2 +- .../apache/shenyu/plugin/base/trie/ShenyuTrie.java | 6 +- .../logging/console/LoggingConsolePlugin.java | 6 +- .../dubbo/proxy/ApacheDubboProxyService.java | 9 +- .../loadbalance/picker/AbstractReadyPicker.java | 4 +- .../grpc/loadbalance/picker/EmptyPicker.java | 2 +- .../plugin/motan/proxy/MotanProxyService.java | 9 +- .../shenyu/plugin/sofa/proxy/SofaProxyService.java | 9 +- .../org/apache/shenyu/plugin/tars/TarsPlugin.java | 9 +- .../shenyu/plugin/basic/auth/BasicAuthPlugin.java | 148 ++++++++++----------- .../plugin/basic/auth/config/BasicAuthConfig.java | 98 +++++++------- .../auth/handle/BasicAuthPluginDataHandler.java | 144 ++++++++++---------- .../java/org/apache/shenyu/sdk/core/util/Util.java | 4 +- .../annotation/PathVariableParameterProcessor.java | 2 +- .../netty/ShenyuNettyWebServerConfiguration.java | 9 +- .../basic/auth/BasicAuthPluginConfiguration.java | 106 +++++++-------- .../polaris/PolarisSyncDataConfigurationTest.java | 6 +- .../web/fallback/DefaultFallbackController.java | 124 ++++++++--------- 34 files changed, 447 insertions(+), 431 deletions(-) diff --git a/pom.xml b/pom.xml index 51ba54917f..9464e2e382 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version> <maven-release-plugin.version>2.5.3</maven-release-plugin.version> <versions-maven-plugin.version>2.5</versions-maven-plugin.version> - <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version> + <maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version> <apache-rat-plugin.version>0.15</apache-rat-plugin.version> <frontend-maven-plugin.version>1.6</frontend-maven-plugin.version> <frontend-maven-plugin.node.version>v12.14.1</frontend-maven-plugin.node.version> @@ -723,6 +723,7 @@ <artifactId>maven-checkstyle-plugin</artifactId> <version>${maven-checkstyle-plugin.version}</version> <configuration> + <consoleOutput>true</consoleOutput> <configLocation>/script/shenyu_checkstyle.xml</configLocation> <headerLocation>/script/checkstyle-header.txt</headerLocation> <includeTestSourceDirectory>true</includeTestSourceDirectory> diff --git a/script/shenyu_checkstyle.xml b/script/shenyu_checkstyle.xml index 4b9b0f70ab..8905c27046 100644 --- a/script/shenyu_checkstyle.xml +++ b/script/shenyu_checkstyle.xml @@ -31,9 +31,9 @@ <module name="FileLength"> <property name="max" value="2500"/> </module> - <module name="NewlineAtEndOfFile"> - <property name="lineSeparator" value="lf"/> - </module> +<!-- <module name="NewlineAtEndOfFile">--> +<!-- <property name="lineSeparator" value="lf"/>--> +<!-- </module>--> <module name="Translation"/> <module name="UniqueProperties"/> <module name="SeverityMatchFilter"/> @@ -50,7 +50,13 @@ <property name="format" value="\.printStackTrace"/> <property name="message" value="Prohibit invoking .printStackTrace in source code ! Please use org.slf4j.Logger and write log instead."/> </module> - + + <module name="LineLength"> + <property name="max" value="200"/> + <property name="fileExtensions" value="java"/> + <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> + </module> + <module name="TreeWalker"> <!-- Naming Conventions --> @@ -87,10 +93,7 @@ <property name="tokens" value="METHOD_DEF" /> <property name="max" value="80" /> </module> - <module name="LineLength"> - <property name="max" value="200"/> - <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> - </module> + <module name="OuterTypeNumber"/> <!-- Whitespace --> @@ -133,7 +136,7 @@ <module name="WhitespaceAfter"/> <module name="SingleSpaceSeparator"/> <module name="EmptyLineSeparator"> - <property name="allowMultipleEmptyLines" value="false"/> + <property name="allowMultipleEmptyLines" value="true"/> <property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/> </module> @@ -142,7 +145,9 @@ <module name="IllegalImport"/> <module name="RedundantImport"/> <module name="UnusedImports"/> - <module name="CustomImportOrder"/> +<!-- <module name="CustomImportOrder">--> +<!-- <property name="separateLineBetweenGroups" value="true"/>--> +<!-- </module>--> <!-- Annotations --> <module name="AnnotationLocation"> @@ -154,7 +159,9 @@ <property name="tokens" value="VARIABLE_DEF"/> <property name="allowSamelineMultipleAnnotations" value="true"/> </module> - <module name="AnnotationUseStyle"/> + <module name="AnnotationUseStyle"> + <property name="elementStyle" value="ignore"/> + </module> <module name="MissingOverride"/> <module name="SuppressWarnings"/> <module name="MissingDeprecated"/> @@ -235,7 +242,9 @@ <module name="AvoidEscapedUnicodeCharacters"/> <module name="DescendantToken"/> <module name="FinalParameters"/> - <module name="Indentation"/> + <module name="Indentation"> + <property name="arrayInitIndent" value="8"/> + </module> <module name="OuterTypeFilename"/> <module name="TodoComment"/> <module name="TrailingComment"/> @@ -251,9 +260,8 @@ <module name="SingleLineJavadoc"/> <module name="SummaryJavadoc"/> <module name="JavadocMethod"> - <property name="scope" value="public"/> + <property name="accessModifiers" value="public"/> <property name="allowedAnnotations" value="Override, Test, Before, After, BeforeClass, AfterClass, Parameterized, Parameters, BeforeEach, AfterEach, BeforeAll, AfterAll, ParameterizedTest, TestMethodOrder"/> - <property name="ignoreMethodNamesRegex" value="^assert.*$|^verify.*$"/> <property name="tokens" value="METHOD_DEF, ANNOTATION_FIELD_DEF"/> </module> diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/DataChangedEventDispatcher.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/DataChangedEventDispatcher.java index 0089400258..869eb661c9 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/DataChangedEventDispatcher.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/DataChangedEventDispatcher.java @@ -71,7 +71,7 @@ public class DataChangedEventDispatcher implements ApplicationListener<DataChang @SuppressWarnings("unchecked") public void onApplicationEvent(@NotNull final DataChangedEvent event) { for (DataChangedListener listener : listeners) { - if ((!(listener instanceof AbstractDataChangedListener)) + if (!(listener instanceof AbstractDataChangedListener) && clusterProperties.isEnabled() && Objects.nonNull(shenyuClusterSelectMasterService) && !shenyuClusterSelectMasterService.isMaster()) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java index 72d369f355..36bc10cfb3 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java @@ -103,7 +103,7 @@ public class AppAuthServiceImpl implements AppAuthService { @Transactional(rollbackFor = Exception.class) public ShenyuAdminResult applyCreate(final AuthApplyDTO authApplyDTO) { if (StringUtils.isBlank(authApplyDTO.getAppName()) - || (authApplyDTO.getOpen() && CollectionUtils.isEmpty(authApplyDTO.getPathList()))) { + || authApplyDTO.getOpen() && CollectionUtils.isEmpty(authApplyDTO.getPathList())) { return ShenyuAdminResult.error(ShenyuResultMessage.PARAMETER_ERROR); } AppAuthDO appAuthDO = AppAuthDO.create(authApplyDTO); @@ -141,7 +141,7 @@ public class AppAuthServiceImpl implements AppAuthService { @Override public ShenyuAdminResult applyUpdate(final AuthApplyDTO authApplyDTO) { if (StringUtils.isAnyBlank(authApplyDTO.getAppKey(), authApplyDTO.getAppName()) - || (authApplyDTO.getOpen() && CollectionUtils.isEmpty(authApplyDTO.getPathList()))) { + || authApplyDTO.getOpen() && CollectionUtils.isEmpty(authApplyDTO.getPathList())) { return ShenyuAdminResult.error(ShenyuResultMessage.PARAMETER_ERROR); } AppAuthDO appAuthDO = appAuthMapper.findByAppKey(authApplyDTO.getAppKey()); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/spring/LocalDataSourceLoader.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/spring/LocalDataSourceLoader.java index f5ee87077d..de6ca53672 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/spring/LocalDataSourceLoader.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/spring/LocalDataSourceLoader.java @@ -59,7 +59,7 @@ public class LocalDataSourceLoader implements InstantiationAwareBeanPostProcesso @Override public Object postProcessAfterInitialization(@NonNull final Object bean, @NonNull final String beanName) throws BeansException { - if ((bean instanceof DataSourceProperties) && Boolean.TRUE.equals(dataBaseProperties.getInitEnable())) { + if (bean instanceof DataSourceProperties && Boolean.TRUE.equals(dataBaseProperties.getInitEnable())) { this.init((DataSourceProperties) bean); } return bean; diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/query/TagRelationQueryTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/query/TagRelationQueryTest.java index bfedf787d3..99ab5abcae 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/query/TagRelationQueryTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/query/TagRelationQueryTest.java @@ -1,47 +1,47 @@ -/* - * 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. - */ - -package org.apache.shenyu.admin.model.query; - -import org.apache.shenyu.admin.AbstractReflectGetterSetterTest; -import org.junit.jupiter.api.Test; -import java.util.HashSet; -import java.util.Set; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; - -/** - * Test case for TagRelationQuery. - */ -public class TagRelationQueryTest extends AbstractReflectGetterSetterTest { - @Override - protected Class<?> getTargetClass() { - return TagRelationQuery.class; - } - - @Test - public void testEqualsAndHashCode() { - TagRelationQuery tagRelationQuery1 = TagRelationQuery.builder().apiId("apiId").tagId("tagId").build(); - TagRelationQuery tagRelationQuery2 = TagRelationQuery.builder().apiId("apiId").tagId("tagId").build(); - - Set<TagRelationQuery> set = new HashSet<>(); - set.add(tagRelationQuery1); - set.add(tagRelationQuery2); - - assertThat(set, hasSize(1)); - } -} +/* + * 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. + */ + +package org.apache.shenyu.admin.model.query; + +import org.apache.shenyu.admin.AbstractReflectGetterSetterTest; +import org.junit.jupiter.api.Test; +import java.util.HashSet; +import java.util.Set; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; + +/** + * Test case for TagRelationQuery. + */ +public class TagRelationQueryTest extends AbstractReflectGetterSetterTest { + @Override + protected Class<?> getTargetClass() { + return TagRelationQuery.class; + } + + @Test + public void testEqualsAndHashCode() { + TagRelationQuery tagRelationQuery1 = TagRelationQuery.builder().apiId("apiId").tagId("tagId").build(); + TagRelationQuery tagRelationQuery2 = TagRelationQuery.builder().apiId("apiId").tagId("tagId").build(); + + Set<TagRelationQuery> set = new HashSet<>(); + set.add(tagRelationQuery1); + set.add(tagRelationQuery2); + + assertThat(set, hasSize(1)); + } +} diff --git a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/AbstractApiRegistrar.java b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/AbstractApiRegistrar.java index 4a821795b1..e987049da8 100644 --- a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/AbstractApiRegistrar.java +++ b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/AbstractApiRegistrar.java @@ -71,7 +71,7 @@ public abstract class AbstractApiRegistrar<D extends DataTypeParent> implements * Parses the apiDefinition as a registrable objects. * * @param apiDefinition apiDefinition to be parsed - * @return + * @return registrable objects */ protected abstract List<D> parse(ApiBean.ApiDefinition apiDefinition); diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/utils/ObjectTypeUtils.java b/shenyu-common/src/main/java/org/apache/shenyu/common/utils/ObjectTypeUtils.java index ce9ec167d9..730c7d2802 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/utils/ObjectTypeUtils.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/utils/ObjectTypeUtils.java @@ -28,13 +28,13 @@ public final class ObjectTypeUtils { * @return true is basic */ public static boolean isBasicType(final Object object) { - return (object instanceof Integer) - || (object instanceof Byte) - || (object instanceof Long) - || (object instanceof Double) - || (object instanceof Float) - || (object instanceof Short) - || (object instanceof Boolean) - || (object instanceof CharSequence); + return object instanceof Integer + || object instanceof Byte + || object instanceof Long + || object instanceof Double + || object instanceof Float + || object instanceof Short + || object instanceof Boolean + || object instanceof CharSequence; } } diff --git a/shenyu-e2e/pom.xml b/shenyu-e2e/pom.xml index 93073295de..98fcecf3a0 100644 --- a/shenyu-e2e/pom.xml +++ b/shenyu-e2e/pom.xml @@ -54,7 +54,7 @@ <jetbrains-annotations.version>23.0.0</jetbrains-annotations.version> <apache-rat-plugin.version>0.15</apache-rat-plugin.version> <spring-framework.version>5.3.30</spring-framework.version> - <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version> + <maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version> <guava.version>32.0.0-jre</guava.version> <commons-collection.verion>4.4</commons-collection.verion> <websocket.version>1.5.1</websocket.version> diff --git a/shenyu-examples/pom.xml b/shenyu-examples/pom.xml index 2190794928..49e907cd5b 100644 --- a/shenyu-examples/pom.xml +++ b/shenyu-examples/pom.xml @@ -37,7 +37,7 @@ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version> <versions-maven-plugin.version>2.5</versions-maven-plugin.version> <docker-maven-plugin.version>0.40.1</docker-maven-plugin.version> - <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version> + <maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version> <swagger.version>2.6.0</swagger.version> </properties> @@ -91,6 +91,7 @@ <artifactId>maven-checkstyle-plugin</artifactId> <version>${maven-checkstyle-plugin.version}</version> <configuration> + <consoleOutput>true</consoleOutput> <configLocation>/../script/shenyu_checkstyle.xml</configLocation> <headerLocation>/../script/checkstyle-header.txt</headerLocation> <includeTestSourceDirectory>true</includeTestSourceDirectory> diff --git a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/HttpAuthHandler.java b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/HttpAuthHandler.java index 247addce08..27ab2bd021 100644 --- a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/HttpAuthHandler.java +++ b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/HttpAuthHandler.java @@ -66,8 +66,8 @@ public class HttpAuthHandler extends TextWebSocketHandler { String payload = message.getPayload(); Object token = session.getAttributes().get("token"); LOG.info("server received {}, sent {}", token, payload); - boolean isTestClose = (Objects.nonNull(token) && Objects.equals(token, "testCloseStatus")) - || (Objects.nonNull(payload) && Objects.equals(payload, "testCloseStatus")); + boolean isTestClose = Objects.nonNull(token) && Objects.equals(token, "testCloseStatus") + || Objects.nonNull(payload) && Objects.equals(payload, "testCloseStatus"); if (isTestClose) { session.close(new CloseStatus(4400, "test:apache shenyu server close, return closeStatus")); } else { diff --git a/shenyu-integrated-test/pom.xml b/shenyu-integrated-test/pom.xml index b84592c9be..049ee217e0 100644 --- a/shenyu-integrated-test/pom.xml +++ b/shenyu-integrated-test/pom.xml @@ -64,7 +64,7 @@ <tars-client.version>1.7.2</tars-client.version> <!-- <sofa-rpc-all.version>5.13.0</sofa-rpc-all.version>--> <!-- <curator.version>4.0.1</curator.version>--> - <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version> + <maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version> </properties> <dependencies> @@ -132,6 +132,7 @@ <artifactId>maven-checkstyle-plugin</artifactId> <version>${maven-checkstyle-plugin.version}</version> <configuration> + <consoleOutput>true</consoleOutput> <configLocation>/../script/shenyu_checkstyle.xml</configLocation> <headerLocation>/../script/checkstyle-header.txt</headerLocation> <includeTestSourceDirectory>true</includeTestSourceDirectory> diff --git a/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/LeastActiveLoadBalanceTest.java b/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/LeastActiveLoadBalanceTest.java index 552d7917ff..49c1e70ab9 100644 --- a/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/LeastActiveLoadBalanceTest.java +++ b/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/LeastActiveLoadBalanceTest.java @@ -51,7 +51,7 @@ public class LeastActiveLoadBalanceTest { final LeastActiveLoadBalance leastActiveLoadBalance = new LeastActiveLoadBalance(); Upstream upstream = leastActiveLoadBalance.doSelect(onlyOneList, "localhost"); Upstream upstream1 = leastActiveLoadBalance.doSelect(onlyOneList, "localhost"); - Assertions.assertTrue((upstream.getUrl().equals("baidu.com") && upstream1.getUrl().equals("pro.jd.com")) + Assertions.assertTrue(upstream.getUrl().equals("baidu.com") && upstream1.getUrl().equals("pro.jd.com") || upstream1.getUrl().equals("baidu.com") && upstream.getUrl().equals("pro.jd.com")); } } diff --git a/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/P2cLoadBalancerTest.java b/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/P2cLoadBalancerTest.java index fcd98f59cd..493418656b 100644 --- a/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/P2cLoadBalancerTest.java +++ b/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/spi/P2cLoadBalancerTest.java @@ -49,7 +49,7 @@ public class P2cLoadBalancerTest { final P2cLoadBalancer p2cLoadBalancer = new P2cLoadBalancer(); Upstream upstream = p2cLoadBalancer.doSelect(upstreamList, "localhost"); Upstream upstream1 = p2cLoadBalancer.doSelect(upstreamList, "localhost"); - Assertions.assertTrue((upstream.getUrl().equals("baidu.com") && upstream1.getUrl().equals("pro.jd.com")) + Assertions.assertTrue(upstream.getUrl().equals("baidu.com") && upstream1.getUrl().equals("pro.jd.com") || upstream1.getUrl().equals("baidu.com") && upstream.getUrl().equals("pro.jd.com")); } diff --git a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java index 2f4dd74de8..3a1e4c93a8 100644 --- a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java +++ b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResult.java @@ -56,7 +56,7 @@ public interface ShenyuResult<T> { */ default Object format(ServerWebExchange exchange, Object origin) { // basic data or upstream data - if (ObjectTypeUtils.isBasicType(origin) || (origin instanceof byte[])) { + if (ObjectTypeUtils.isBasicType(origin) || origin instanceof byte[]) { return origin; } // error result or rpc origin result. diff --git a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/RequestUrlUtils.java b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/RequestUrlUtils.java index 97fb6807bb..b4d122f299 100644 --- a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/RequestUrlUtils.java +++ b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/RequestUrlUtils.java @@ -55,8 +55,8 @@ public final class RequestUrlUtils { } } URI uri = exchange.getRequest().getURI(); - if ((StringUtils.isNotEmpty(uri.getRawQuery()) && uri.getRawQuery().contains("%")) - || (StringUtils.isNotEmpty(uri.getRawPath()) && uri.getRawPath().contains("%"))) { + if (StringUtils.isNotEmpty(uri.getRawQuery()) && uri.getRawQuery().contains("%") + || StringUtils.isNotEmpty(uri.getRawPath()) && uri.getRawPath().contains("%")) { path = path + "?" + RequestQueryCodecUtil.getCodecQuery(exchange); return UriComponentsBuilder.fromUriString(path).build(true).toUri(); } else { diff --git a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java index c531b93a9b..927747c00c 100644 --- a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java +++ b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java @@ -272,7 +272,7 @@ public class CommonPluginDataSubscriber implements PluginDataSubscriber { return; } if (Objects.isNull(oldPluginData) || Objects.isNull(oldPluginData.getSort()) - || (!Objects.equals(oldPluginData.getSort(), pluginData.getSort()))) { + || !Objects.equals(oldPluginData.getSort(), pluginData.getSort())) { eventPublisher.publishEvent(new PluginHandlerEvent(PluginHandlerEventEnum.SORTED, pluginData)); } } diff --git a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java index 3445a0b03f..1bd5285254 100644 --- a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java +++ b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java @@ -327,9 +327,9 @@ public class ShenyuTrie { ShenyuTrieNode newCurrentNode = currentNode.getFailToNode(); // search failToNode's parentNode ShenyuTrieNode parentNode = newCurrentNode.getParentNode(); - if (Objects.isNull(parentNode) || (Objects.nonNull(parentNode.getFailToNode()) && Objects.nonNull(newCurrentNode.getFailToNode()) + if (Objects.isNull(parentNode) || Objects.nonNull(parentNode.getFailToNode()) && Objects.nonNull(newCurrentNode.getFailToNode()) && completeResolveConflict(parentNode, wildcard, matchAll, pathVariable, startIndex) - && parentNode.getFailToNode().equals(newCurrentNode.getFailToNode()) && "/".equals(parentNode.getParentNode().getMatchStr()))) { + && parentNode.getFailToNode().equals(newCurrentNode.getFailToNode()) && "/".equals(parentNode.getParentNode().getMatchStr())) { return null; } startIndex--; @@ -349,7 +349,7 @@ public class ShenyuTrie { startIndex++; continue; } - if ((startIndex == pathParts.length - 1 && checkNode(currentNode, bizInfo)) || (Objects.nonNull(currentNode) && isMatchAll(currentNode.getMatchStr()) && checkNode(currentNode, bizInfo))) { + if (startIndex == pathParts.length - 1 && checkNode(currentNode, bizInfo) || Objects.nonNull(currentNode) && isMatchAll(currentNode.getMatchStr()) && checkNode(currentNode, bizInfo)) { return currentNode; } } diff --git a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-console/src/main/java/org/apache/shenyu/plugin/logging/console/LoggingConsolePlugin.java b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-console/src/main/java/org/apache/shenyu/plugin/logging/console/LoggingConsolePlugin.java index 3cb1a7654c..c89c3b835d 100644 --- a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-console/src/main/java/org/apache/shenyu/plugin/logging/console/LoggingConsolePlugin.java +++ b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-console/src/main/java/org/apache/shenyu/plugin/logging/console/LoggingConsolePlugin.java @@ -135,10 +135,10 @@ public class LoggingConsolePlugin extends AbstractShenyuPlugin { logInfo.append("[Query Params Start]").append(System.lineSeparator()); params.forEach((key, value) -> { // desensitized query parameters - value = Lists.newArrayList(value); - DataDesensitizeUtils.desensitizeList(desensitized, key, value, keyWordMatch, dataDesensitizeAlg); + List<String> list = Lists.newArrayList(value); + DataDesensitizeUtils.desensitizeList(desensitized, key, list, keyWordMatch, dataDesensitizeAlg); logInfo.append(key).append(": ") - .append(StringUtils.join(value, ",")).append(System.lineSeparator()); + .append(StringUtils.join(list, ",")).append(System.lineSeparator()); }); logInfo.append("[Query Params End]").append(System.lineSeparator()); } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java index 7cf3b026d6..e8d20be872 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java @@ -82,12 +82,13 @@ public class ApacheDubboProxyService { pair = dubboParamResolveService.buildParameter(body, metaData.getParameterTypes()); } return Mono.fromFuture(invokeAsync(genericService, metaData.getMethodName(), pair.getLeft(), pair.getRight()).thenApply(ret -> { - if (Objects.isNull(ret)) { - ret = Constants.DUBBO_RPC_RESULT_EMPTY; + Object result = ret; + if (Objects.isNull(result)) { + result = Constants.DUBBO_RPC_RESULT_EMPTY; } - exchange.getAttributes().put(Constants.RPC_RESULT, ret); + exchange.getAttributes().put(Constants.RPC_RESULT, result); exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName()); - return ret; + return result; })).onErrorMap(exception -> exception instanceof GenericException ? new ShenyuException(((GenericException) exception).getExceptionMessage()) : new ShenyuException(exception)); } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/AbstractReadyPicker.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/AbstractReadyPicker.java index 49d76c737c..63e7949e21 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/AbstractReadyPicker.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/AbstractReadyPicker.java @@ -89,8 +89,8 @@ public abstract class AbstractReadyPicker extends AbstractPicker implements Pick } AbstractReadyPicker other = (AbstractReadyPicker) picker; // the lists cannot contain duplicate subchannels - return other == this || (list.size() == other.list.size() - && new HashSet<>(list).containsAll(other.list)); + return other == this || list.size() == other.list.size() + && new HashSet<>(list).containsAll(other.list); } @Override diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/EmptyPicker.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/EmptyPicker.java index ca938a298a..7c3ae74d2b 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/EmptyPicker.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/loadbalance/picker/EmptyPicker.java @@ -40,7 +40,7 @@ public class EmptyPicker extends AbstractPicker { @Override public boolean isEquivalentTo(final AbstractPicker picker) { - return picker instanceof EmptyPicker && (Objects.equal(status, ((EmptyPicker) picker).status) || (status.isOk() && ((EmptyPicker) picker).status.isOk())); + return picker instanceof EmptyPicker && (Objects.equal(status, ((EmptyPicker) picker).status) || status.isOk() && ((EmptyPicker) picker).status.isOk()); } @Override diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java index 59f939288d..379d5dc0cf 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java @@ -108,12 +108,13 @@ public class MotanProxyService { initThreadPool(); CompletableFuture<Object> future = CompletableFuture.supplyAsync(responseFuture::getValue, threadPool); return Mono.fromFuture(future.thenApply(ret -> { - if (Objects.isNull(ret)) { - ret = Constants.MOTAN_RPC_RESULT_EMPTY; + Object result = ret; + if (Objects.isNull(result)) { + result = Constants.MOTAN_RPC_RESULT_EMPTY; } - exchange.getAttributes().put(Constants.RPC_RESULT, ret); + exchange.getAttributes().put(Constants.RPC_RESULT, result); exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName()); - return ret; + return result; })).onErrorMap(ShenyuException::new); } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java index 236edbae23..087e410f48 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java @@ -102,14 +102,15 @@ public class SofaProxyService { GenericService genericService = reference.refer(); genericService.$genericInvoke(metaData.getMethodName(), pair.getLeft(), pair.getRight()); return Mono.fromFuture(future.thenApply(ret -> { - if (Objects.isNull(ret)) { - ret = Constants.SOFA_RPC_RESULT_EMPTY; + Object result = ret; + if (Objects.isNull(result)) { + result = Constants.SOFA_RPC_RESULT_EMPTY; } - GenericObject genericObject = (GenericObject) ret; + GenericObject genericObject = (GenericObject) result; exchange.getAttributes().put(Constants.RPC_RESULT, genericObject.getFields()); exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName()); - return ret; + return result; })).onErrorMap(ShenyuException::new); } } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/TarsPlugin.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/TarsPlugin.java index 574797f606..42f9f3db73 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/TarsPlugin.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/TarsPlugin.java @@ -93,12 +93,13 @@ public class TarsPlugin extends AbstractShenyuPlugin { return WebFluxResultUtils.result(exchange, error); } return Mono.fromFuture(future.thenApply(ret -> { - if (Objects.isNull(ret)) { - ret = Constants.TARS_RPC_RESULT_EMPTY; + Object result = ret; + if (Objects.isNull(result)) { + result = Constants.TARS_RPC_RESULT_EMPTY; } - exchange.getAttributes().put(Constants.RPC_RESULT, ret); + exchange.getAttributes().put(Constants.RPC_RESULT, result); exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName()); - return ret; + return result; })).onErrorMap(m -> new ShenyuException("failed to invoke tars")).then(chain.execute(exchange)); } diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPlugin.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPlugin.java index 938278aee3..60e247c0a5 100755 --- a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPlugin.java +++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPlugin.java @@ -1,74 +1,74 @@ -/* - * 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. - */ - -package org.apache.shenyu.plugin.basic.auth; - -import org.apache.commons.lang3.StringUtils; -import org.apache.shenyu.common.dto.RuleData; -import org.apache.shenyu.common.dto.SelectorData; -import org.apache.shenyu.common.enums.PluginEnum; -import org.apache.shenyu.plugin.api.ShenyuPluginChain; -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.apache.shenyu.plugin.base.AbstractShenyuPlugin; -import org.apache.shenyu.plugin.base.utils.CacheKeyUtils; -import org.apache.shenyu.plugin.basic.auth.handle.BasicAuthPluginDataHandler; -import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle; -import org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy; -import org.springframework.http.HttpHeaders; -import org.springframework.web.server.ServerWebExchange; -import reactor.core.publisher.Mono; - -import java.util.Optional; - -/** - * basic-auth Plugin. - */ -public class BasicAuthPlugin extends AbstractShenyuPlugin { - - /** - * this is Template Method child has Implement your own logic. - * - * @param exchange exchange the current server exchange {@linkplain ServerWebExchange} - * @param chain chain the current chain {@linkplain ServerWebExchange} - * @param selector selector {@linkplain SelectorData} - * @param rule rule {@linkplain RuleData} - * @return {@code Mono<Void>} to indicate when request handling is complete - */ - @Override - protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) { - String authorization = StringUtils.defaultString(exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION), exchange.getRequest().getURI().getUserInfo()); - BasicAuthRuleHandle basicAuthRuleHandle = BasicAuthPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule)); - BasicAuthAuthenticationStrategy authenticationStrategy = Optional.ofNullable(basicAuthRuleHandle).map(BasicAuthRuleHandle::getBasicAuthAuthenticationStrategy).orElse(null); - - if (authenticationStrategy != null && authenticationStrategy.authenticate(basicAuthRuleHandle, authorization)) { - return chain.execute(exchange); - } - return WebFluxResultUtils.result(exchange, ShenyuResultWrap.error(exchange, ShenyuResultEnum.ERROR_TOKEN)); - } - - @Override - public String named() { - return PluginEnum.BASIC_AUTH.getName(); - } - - @Override - public int getOrder() { - return PluginEnum.BASIC_AUTH.getCode(); - } -} +/* + * 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. + */ + +package org.apache.shenyu.plugin.basic.auth; + +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.common.dto.RuleData; +import org.apache.shenyu.common.dto.SelectorData; +import org.apache.shenyu.common.enums.PluginEnum; +import org.apache.shenyu.plugin.api.ShenyuPluginChain; +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.apache.shenyu.plugin.base.AbstractShenyuPlugin; +import org.apache.shenyu.plugin.base.utils.CacheKeyUtils; +import org.apache.shenyu.plugin.basic.auth.handle.BasicAuthPluginDataHandler; +import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle; +import org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy; +import org.springframework.http.HttpHeaders; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.Optional; + +/** + * basic-auth Plugin. + */ +public class BasicAuthPlugin extends AbstractShenyuPlugin { + + /** + * this is Template Method child has Implement your own logic. + * + * @param exchange exchange the current server exchange {@linkplain ServerWebExchange} + * @param chain chain the current chain {@linkplain ServerWebExchange} + * @param selector selector {@linkplain SelectorData} + * @param rule rule {@linkplain RuleData} + * @return {@code Mono<Void>} to indicate when request handling is complete + */ + @Override + protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) { + String authorization = StringUtils.defaultString(exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION), exchange.getRequest().getURI().getUserInfo()); + BasicAuthRuleHandle basicAuthRuleHandle = BasicAuthPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule)); + BasicAuthAuthenticationStrategy authenticationStrategy = Optional.ofNullable(basicAuthRuleHandle).map(BasicAuthRuleHandle::getBasicAuthAuthenticationStrategy).orElse(null); + + if (authenticationStrategy != null && authenticationStrategy.authenticate(basicAuthRuleHandle, authorization)) { + return chain.execute(exchange); + } + return WebFluxResultUtils.result(exchange, ShenyuResultWrap.error(exchange, ShenyuResultEnum.ERROR_TOKEN)); + } + + @Override + public String named() { + return PluginEnum.BASIC_AUTH.getName(); + } + + @Override + public int getOrder() { + return PluginEnum.BASIC_AUTH.getCode(); + } +} diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/config/BasicAuthConfig.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/config/BasicAuthConfig.java index 035236e6c0..80be737244 100755 --- a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/config/BasicAuthConfig.java +++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/config/BasicAuthConfig.java @@ -1,49 +1,49 @@ -/* - * 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. - */ - -package org.apache.shenyu.plugin.basic.auth.config; - -import java.io.Serializable; - -/** - * basic-auth Plugin. - */ -public class BasicAuthConfig implements Serializable { - /** - * defaultHandleJson. - */ - private String defaultHandleJson; - - /** - * get defaultHandleJson. - * - * @return defaultHandleJson. - */ - public String getDefaultHandleJson() { - return defaultHandleJson; - } - - /** - * set defaultHandleJson. - * - * @param defaultHandleJson defaultHandleJson. - */ - public void setDefaultHandleJson(final String defaultHandleJson) { - this.defaultHandleJson = defaultHandleJson; - } - -} +/* + * 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. + */ + +package org.apache.shenyu.plugin.basic.auth.config; + +import java.io.Serializable; + +/** + * basic-auth Plugin. + */ +public class BasicAuthConfig implements Serializable { + /** + * defaultHandleJson. + */ + private String defaultHandleJson; + + /** + * get defaultHandleJson. + * + * @return defaultHandleJson. + */ + public String getDefaultHandleJson() { + return defaultHandleJson; + } + + /** + * set defaultHandleJson. + * + * @param defaultHandleJson defaultHandleJson. + */ + public void setDefaultHandleJson(final String defaultHandleJson) { + this.defaultHandleJson = defaultHandleJson; + } + +} diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandler.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandler.java index 934187a197..280876e936 100755 --- a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandler.java @@ -1,72 +1,72 @@ -/* - * 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. - */ - -package org.apache.shenyu.plugin.basic.auth.handle; - -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; - -import org.apache.commons.lang3.StringUtils; -import org.apache.shenyu.common.constant.Constants; -import org.apache.shenyu.common.dto.PluginData; -import org.apache.shenyu.common.dto.RuleData; -import org.apache.shenyu.common.enums.PluginEnum; -import org.apache.shenyu.common.utils.GsonUtils; -import org.apache.shenyu.common.utils.Singleton; -import org.apache.shenyu.plugin.base.cache.CommonHandleCache; -import org.apache.shenyu.plugin.base.handler.PluginDataHandler; -import org.apache.shenyu.plugin.base.utils.BeanHolder; -import org.apache.shenyu.plugin.base.utils.CacheKeyUtils; -import org.apache.shenyu.plugin.basic.auth.config.BasicAuthConfig; -import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle; - -/** - * Configuration data of the basic auth plugin. - */ -public class BasicAuthPluginDataHandler implements PluginDataHandler { - - public static final Supplier<CommonHandleCache<String, BasicAuthRuleHandle>> CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new); - - @Override - public void handlerPlugin(final PluginData pluginData) { - Map<String, String> configMap = GsonUtils.getInstance().toObjectMap(pluginData.getConfig(), String.class); - String defaultHandleJson = Optional.ofNullable(configMap.get(Constants.DEFAULT_HANDLE_JSON)).orElse(""); - BasicAuthConfig basicAuthConfig = new BasicAuthConfig(); - basicAuthConfig.setDefaultHandleJson(defaultHandleJson); - Singleton.INST.single(BasicAuthConfig.class, basicAuthConfig); - } - - @Override - public void removeRule(final RuleData ruleData) { - CACHED_HANDLE.get().removeHandle(CacheKeyUtils.INST.getKey(ruleData)); - } - - @Override - public void handlerRule(final RuleData ruleData) { - BasicAuthConfig basicAuthConfig = Singleton.INST.get(BasicAuthConfig.class); - Optional.ofNullable(ruleData.getHandle()).ifPresent(ruleHandle -> { - BasicAuthRuleHandle basicAuthRuleHandle = BasicAuthRuleHandle.newInstance(StringUtils.defaultString(ruleHandle, basicAuthConfig.getDefaultHandleJson())); - CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData), basicAuthRuleHandle); - }); - } - - @Override - public String pluginNamed() { - return PluginEnum.BASIC_AUTH.getName(); - } -} +/* + * 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. + */ + +package org.apache.shenyu.plugin.basic.auth.handle; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; + +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.common.constant.Constants; +import org.apache.shenyu.common.dto.PluginData; +import org.apache.shenyu.common.dto.RuleData; +import org.apache.shenyu.common.enums.PluginEnum; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.Singleton; +import org.apache.shenyu.plugin.base.cache.CommonHandleCache; +import org.apache.shenyu.plugin.base.handler.PluginDataHandler; +import org.apache.shenyu.plugin.base.utils.BeanHolder; +import org.apache.shenyu.plugin.base.utils.CacheKeyUtils; +import org.apache.shenyu.plugin.basic.auth.config.BasicAuthConfig; +import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle; + +/** + * Configuration data of the basic auth plugin. + */ +public class BasicAuthPluginDataHandler implements PluginDataHandler { + + public static final Supplier<CommonHandleCache<String, BasicAuthRuleHandle>> CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new); + + @Override + public void handlerPlugin(final PluginData pluginData) { + Map<String, String> configMap = GsonUtils.getInstance().toObjectMap(pluginData.getConfig(), String.class); + String defaultHandleJson = Optional.ofNullable(configMap.get(Constants.DEFAULT_HANDLE_JSON)).orElse(""); + BasicAuthConfig basicAuthConfig = new BasicAuthConfig(); + basicAuthConfig.setDefaultHandleJson(defaultHandleJson); + Singleton.INST.single(BasicAuthConfig.class, basicAuthConfig); + } + + @Override + public void removeRule(final RuleData ruleData) { + CACHED_HANDLE.get().removeHandle(CacheKeyUtils.INST.getKey(ruleData)); + } + + @Override + public void handlerRule(final RuleData ruleData) { + BasicAuthConfig basicAuthConfig = Singleton.INST.get(BasicAuthConfig.class); + Optional.ofNullable(ruleData.getHandle()).ifPresent(ruleHandle -> { + BasicAuthRuleHandle basicAuthRuleHandle = BasicAuthRuleHandle.newInstance(StringUtils.defaultString(ruleHandle, basicAuthConfig.getDefaultHandleJson())); + CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData), basicAuthRuleHandle); + }); + } + + @Override + public String pluginNamed() { + return PluginEnum.BASIC_AUTH.getName(); + } +} diff --git a/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/util/Util.java b/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/util/Util.java index 62be898cf3..55bc607b44 100644 --- a/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/util/Util.java +++ b/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/util/Util.java @@ -117,8 +117,8 @@ public final class Util { // method.isDefault() is not sufficient for our usage as it does not check // for synthetic methods. As a result, it picks up overridden methods as well as actual default // methods. - return ((method.getModifiers() - & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC | 0x00001000)) == Modifier.PUBLIC) + return (method.getModifiers() + & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC | 0x00001000)) == Modifier.PUBLIC && method.getDeclaringClass().isInterface(); } diff --git a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java index a74b007c88..89edc062ad 100644 --- a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java +++ b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java @@ -43,7 +43,7 @@ public class PathVariableParameterProcessor implements AnnotatedParameterProcess public boolean processArgument(final ShenyuRequest shenyuRequest, final Annotation annotation, final Object arg) { String name = ANNOTATION.cast(annotation).value(); RequestTemplate requestTemplate = shenyuRequest.getRequestTemplate(); - checkState((arg instanceof String && emptyToNull(name) != null) || arg instanceof Map, + checkState(arg instanceof String && emptyToNull(name) != null || arg instanceof Map, "PathVariable Object class pls is String or Map<String, String> and PathVariable annotation value could not be empty when String class at the method %s.", requestTemplate.getMethod()); if (arg instanceof String) { diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java index a6b17cfbae..44c1db881f 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java @@ -90,6 +90,7 @@ public class ShenyuNettyWebServerConfiguration { NettyReactiveWebServerFactory webServerFactory = new NettyReactiveWebServerFactory(); NettyHttpProperties nettyHttpProperties = Optional.ofNullable(properties.getIfAvailable()).orElse(new NettyHttpProperties()); webServerFactory.addServerCustomizers(new EventLoopNettyCustomizer(nettyHttpProperties, httpServer -> { + HttpServer server = httpServer; // Configure sni certificates NettyHttpProperties.SniProperties sniProperties = nettyHttpProperties.getSni(); if (sniProperties.getEnabled()) { @@ -115,19 +116,19 @@ public class ShenyuNettyWebServerConfiguration { SslCrtAndKeyFile defaultCert = certificates.get(0); TcpSslContextSpec defaultSpec = TcpSslContextSpec.forServer(new File(defaultCert.getKeyCertChainFile()), new File(defaultCert.getKeyFile())); - - httpServer = httpServer.secure(spec -> spec.sslContext(defaultSpec) + + server = server.secure(spec -> spec.sslContext(defaultSpec) .setSniAsyncMappings(shenyuSniAsyncMapping), false); } else if ("k8s".equals(sniProperties.getMod())) { TcpSslContextSpec defaultSpec = Objects.requireNonNull(tcpSslContextSpecs.getIfAvailable()); - httpServer = httpServer.secure(spec -> spec.sslContext(defaultSpec) + server = server.secure(spec -> spec.sslContext(defaultSpec) .setSniAsyncMappings(shenyuSniAsyncMapping), false); shenyuSniAsyncMapping.addSslProvider("shenyu-default", SslProvider.builder().sslContext(defaultSpec).build()); } else { throw new ShenyuException("Cannot read the sni mod"); } } - return httpServer; + return server; })); return webServerFactory; } diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/basic/auth/BasicAuthPluginConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/basic/auth/BasicAuthPluginConfiguration.java index cb9c604aba..458979c8b9 100755 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/basic/auth/BasicAuthPluginConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/basic/auth/BasicAuthPluginConfiguration.java @@ -1,53 +1,53 @@ -/* - * 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. - */ - -package org.apache.shenyu.springboot.starter.plugin.basic.auth; - -import org.apache.shenyu.plugin.api.ShenyuPlugin; -import org.apache.shenyu.plugin.base.handler.PluginDataHandler; -import org.apache.shenyu.plugin.basic.auth.BasicAuthPlugin; -import org.apache.shenyu.plugin.basic.auth.handle.BasicAuthPluginDataHandler; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * The type Basic auth plugin configuration. - */ -@Configuration -@ConditionalOnProperty(value = {"shenyu.plugins.basic-auth.enabled"}, havingValue = "true", matchIfMissing = true) -public class BasicAuthPluginConfiguration { - /** - * GeneralContext plugin. - * - * @return the shenyu plugin - */ - @Bean - public ShenyuPlugin basicAuthPlugin() { - return new BasicAuthPlugin(); - } - - /** - * GeneralContext plugin data handler. - * - * @return the plugin data handler - */ - @Bean - public PluginDataHandler basicAuthPluginDataHandler() { - return new BasicAuthPluginDataHandler(); - } -} +/* + * 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. + */ + +package org.apache.shenyu.springboot.starter.plugin.basic.auth; + +import org.apache.shenyu.plugin.api.ShenyuPlugin; +import org.apache.shenyu.plugin.base.handler.PluginDataHandler; +import org.apache.shenyu.plugin.basic.auth.BasicAuthPlugin; +import org.apache.shenyu.plugin.basic.auth.handle.BasicAuthPluginDataHandler; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * The type Basic auth plugin configuration. + */ +@Configuration +@ConditionalOnProperty(value = {"shenyu.plugins.basic-auth.enabled"}, havingValue = "true", matchIfMissing = true) +public class BasicAuthPluginConfiguration { + /** + * GeneralContext plugin. + * + * @return the shenyu plugin + */ + @Bean + public ShenyuPlugin basicAuthPlugin() { + return new BasicAuthPlugin(); + } + + /** + * GeneralContext plugin data handler. + * + * @return the plugin data handler + */ + @Bean + public PluginDataHandler basicAuthPluginDataHandler() { + return new BasicAuthPluginDataHandler(); + } +} diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/test/java/org/apache/shenyu/springboot/stater/sync/data/polaris/PolarisSyncDataConfigurationTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/test/java/org/apache/shenyu/springboot/stater/sync/data/polaris/PolarisSyncDataConfigurationTest.java index 0febf044a4..06ae178d95 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/test/java/org/apache/shenyu/springboot/stater/sync/data/polaris/PolarisSyncDataConfigurationTest.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/test/java/org/apache/shenyu/springboot/stater/sync/data/polaris/PolarisSyncDataConfigurationTest.java @@ -41,9 +41,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @SpringBootTest( classes = PolarisSyncDataConfiguration.class, properties = { - "shenyu.sync.polaris.url=" + PolarisSyncDataConfigurationTest.URL, - "shenyu.sync.polaris.namespace=default", - "shenyu.sync.polaris.fileGroup=fileGroup" + "shenyu.sync.polaris.url=" + PolarisSyncDataConfigurationTest.URL, + "shenyu.sync.polaris.namespace=default", + "shenyu.sync.polaris.fileGroup=fileGroup" }) @EnableAutoConfiguration public final class PolarisSyncDataConfigurationTest { diff --git a/shenyu-web/src/main/java/org/apache/shenyu/web/fallback/DefaultFallbackController.java b/shenyu-web/src/main/java/org/apache/shenyu/web/fallback/DefaultFallbackController.java index bae558946b..4b375f8158 100644 --- a/shenyu-web/src/main/java/org/apache/shenyu/web/fallback/DefaultFallbackController.java +++ b/shenyu-web/src/main/java/org/apache/shenyu/web/fallback/DefaultFallbackController.java @@ -1,62 +1,62 @@ -/* - * 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. - */ - -package org.apache.shenyu.web.fallback; - -import org.apache.shenyu.plugin.api.result.ShenyuResultEnum; -import org.apache.shenyu.plugin.api.result.ShenyuResultWrap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * The default fallback for hystrix plugin and resilience4j plugin. - */ -@RestController -@RequestMapping("/fallback") -public class DefaultFallbackController { - - /** - * default fallback for hystrix. - * - * @return the shenyu result - */ - @GetMapping("/hystrix") - public Object hystrixPluginFallback() { - return ShenyuResultWrap.error(ShenyuResultEnum.HYSTRIX_PLUGIN_FALLBACK, null); - } - - /** - * default fallback for resilience4j. - * - * @return the shenyu result - */ - @GetMapping("/resilience4j") - public Object resilience4jFallBack() { - return ShenyuResultWrap.error(ShenyuResultEnum.RESILIENCE4J_PLUGIN_FALLBACK, null); - } - - /** - * Sentinel fall back object. - * - * @return the object - */ - @GetMapping("/sentinel") - public Object sentinelFallBack() { - return ShenyuResultWrap.error(ShenyuResultEnum.SENTINEL_PLUGIN_FALLBACK, null); - } -} +/* + * 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. + */ + +package org.apache.shenyu.web.fallback; + +import org.apache.shenyu.plugin.api.result.ShenyuResultEnum; +import org.apache.shenyu.plugin.api.result.ShenyuResultWrap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * The default fallback for hystrix plugin and resilience4j plugin. + */ +@RestController +@RequestMapping("/fallback") +public class DefaultFallbackController { + + /** + * default fallback for hystrix. + * + * @return the shenyu result + */ + @GetMapping("/hystrix") + public Object hystrixPluginFallback() { + return ShenyuResultWrap.error(ShenyuResultEnum.HYSTRIX_PLUGIN_FALLBACK, null); + } + + /** + * default fallback for resilience4j. + * + * @return the shenyu result + */ + @GetMapping("/resilience4j") + public Object resilience4jFallBack() { + return ShenyuResultWrap.error(ShenyuResultEnum.RESILIENCE4J_PLUGIN_FALLBACK, null); + } + + /** + * Sentinel fall back object. + * + * @return the object + */ + @GetMapping("/sentinel") + public Object sentinelFallBack() { + return ShenyuResultWrap.error(ShenyuResultEnum.SENTINEL_PLUGIN_FALLBACK, null); + } +}