From b53eac926994db2d63c2e2a3ddcf28ef0c1e4ad3 Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Sat, 26 Apr 2025 23:50:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20sa-token-forest=20?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=9C=A8=20Http?= =?UTF-8?q?=20=E8=AF=B7=E6=B1=82=E5=A4=84=E7=90=86=E5=99=A8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=95=B4=E5=90=88=20Forest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-dependencies/pom.xml | 8 ++++ sa-token-plugin/pom.xml | 1 + sa-token-plugin/sa-token-forest/pom.xml | 25 ++++++++++ .../satoken/http/SaHttpTemplateForForest.java | 47 +++++++++++++++++++ .../plugin/SaTokenPluginForForest.java | 34 ++++++++++++++ .../cn.dev33.satoken.plugin.SaTokenPlugin | 1 + 6 files changed, 116 insertions(+) create mode 100644 sa-token-plugin/sa-token-forest/pom.xml create mode 100644 sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/http/SaHttpTemplateForForest.java create mode 100644 sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginForForest.java create mode 100644 sa-token-plugin/sa-token-forest/src/main/resources/META-INF/satoken/cn.dev33.satoken.plugin.SaTokenPlugin diff --git a/sa-token-dependencies/pom.xml b/sa-token-dependencies/pom.xml index f4dd0615..c75944b8 100644 --- a/sa-token-dependencies/pom.xml +++ b/sa-token-dependencies/pom.xml @@ -40,6 +40,7 @@ 3.45.0 5.8.36 3.2.0 + 1.6.4 @@ -274,6 +275,13 @@ ${caffeine.version} + + + com.dtflys.forest + forest-core + ${forest.version} + + cn.dev33 diff --git a/sa-token-plugin/pom.xml b/sa-token-plugin/pom.xml index 79e4fb15..a6ce6ac2 100644 --- a/sa-token-plugin/pom.xml +++ b/sa-token-plugin/pom.xml @@ -36,6 +36,7 @@ sa-token-redisson sa-token-redisx sa-token-serializer-features + sa-token-forest sa-token-redis-template diff --git a/sa-token-plugin/sa-token-forest/pom.xml b/sa-token-plugin/sa-token-forest/pom.xml new file mode 100644 index 00000000..8496f46b --- /dev/null +++ b/sa-token-plugin/sa-token-forest/pom.xml @@ -0,0 +1,25 @@ + + + + sa-token-plugin + cn.dev33 + ${revision} + ../pom.xml + + 4.0.0 + + sa-token-forest + + + + cn.dev33 + sa-token-core + + + com.dtflys.forest + forest-core + + + \ No newline at end of file diff --git a/sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/http/SaHttpTemplateForForest.java b/sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/http/SaHttpTemplateForForest.java new file mode 100644 index 00000000..9e24b800 --- /dev/null +++ b/sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/http/SaHttpTemplateForForest.java @@ -0,0 +1,47 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed 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 cn.dev33.satoken.http; + +import cn.dev33.satoken.SaManager; +import com.dtflys.forest.Forest; + +import java.util.Map; + +/** + * Http 转换器, Forest 版实现 + * + * @author click33 + * @since 1.43.0 + */ +public class SaHttpTemplateForForest implements SaHttpTemplate { + + @Override + public String get(String url) { + SaManager.log.debug("发起请求,GET:{}", url); + String res = Forest.get(url).executeAsString(); + SaManager.log.debug("返回结果:{}", res); + return res; + } + + @Override + public String postByFormData(String url, Map params) { + SaManager.log.debug("发起请求,POST:{}\t参数:{}", url, params); + String res = Forest.post(url).addBody(params).executeAsString(); + SaManager.log.debug("返回结果:{}", res); + return res; + } + +} diff --git a/sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginForForest.java b/sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginForForest.java new file mode 100644 index 00000000..dad3712a --- /dev/null +++ b/sa-token-plugin/sa-token-forest/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginForForest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed 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 cn.dev33.satoken.plugin; + +import cn.dev33.satoken.SaManager; +import cn.dev33.satoken.http.SaHttpTemplateForForest; + +/** + * SaToken 插件安装:Http 请求处理器 - Forest 版 + * + * @author click33 + * @since 1.43.0 + */ +public class SaTokenPluginForForest implements SaTokenPlugin { + + @Override + public void install() { + SaManager.setSaHttpTemplate(new SaHttpTemplateForForest()); + } + +} \ No newline at end of file diff --git a/sa-token-plugin/sa-token-forest/src/main/resources/META-INF/satoken/cn.dev33.satoken.plugin.SaTokenPlugin b/sa-token-plugin/sa-token-forest/src/main/resources/META-INF/satoken/cn.dev33.satoken.plugin.SaTokenPlugin new file mode 100644 index 00000000..58696739 --- /dev/null +++ b/sa-token-plugin/sa-token-forest/src/main/resources/META-INF/satoken/cn.dev33.satoken.plugin.SaTokenPlugin @@ -0,0 +1 @@ +cn.dev33.satoken.plugin.SaTokenPluginForForest \ No newline at end of file