From 01137488be8ad238fe2e6e976d51d6cc2ec6182f Mon Sep 17 00:00:00 2001 From: shedfreewu Date: Mon, 7 Jul 2025 15:01:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=20tsf=20=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/annotation/TsfGatewayFilter.java | 38 ++++++++++++++ .../gateway/scg/AbstractTsfGlobalFilter.java | 50 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/annotation/TsfGatewayFilter.java create mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/scg/AbstractTsfGlobalFilter.java diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/annotation/TsfGatewayFilter.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/annotation/TsfGatewayFilter.java new file mode 100644 index 000000000..1ca7fe258 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/annotation/TsfGatewayFilter.java @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 Tencent. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.tsf.gateway.core.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.stereotype.Component; + +/** + * Compatible with old versions TSF SDK. + * + * @author Shedfree Wu + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Component +public @interface TsfGatewayFilter { +} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/scg/AbstractTsfGlobalFilter.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/scg/AbstractTsfGlobalFilter.java new file mode 100644 index 000000000..c6bf9f3cd --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/scg/AbstractTsfGlobalFilter.java @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 Tencent. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.tsf.gateway.scg; + +import reactor.core.publisher.Mono; + +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.web.server.ServerWebExchange; + +/** + * Compatible with old versions TSF SDK. + * + * @author Shedfree Wu + */ +public abstract class AbstractTsfGlobalFilter implements GlobalFilter, Ordered { + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + if (shouldFilter(exchange, chain)) { + return doFilter(exchange, chain); + } + else { + return chain.filter(exchange); + } + } + + @Override + abstract public int getOrder(); + + abstract public boolean shouldFilter(ServerWebExchange exchange, GatewayFilterChain chain); + + abstract public Mono doFilter(ServerWebExchange exchange, GatewayFilterChain chain); +}