SSO 示例项目 http 请求工具改为 Forest

This commit is contained in:
click33
2022-10-24 00:31:17 +08:00
parent 10b6e8ac9b
commit 00886066e3
9 changed files with 59 additions and 33 deletions

View File

@@ -60,10 +60,11 @@
<!-- Http请求工具在模式三的单点注销功能下用到如不需要可以注释掉 -->
<dependency>
<groupId>com.ejlchina</groupId>
<artifactId>okhttps</artifactId>
<version>3.1.1</version>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId>
<version>1.5.26</version>
</dependency>
</dependencies>

View File

@@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.ejlchina.okhttps.OkHttps;
import com.dtflys.forest.Forest;
import cn.dev33.satoken.config.SaSsoConfig;
import cn.dev33.satoken.sso.SaSsoHandle;
@@ -55,8 +55,8 @@ public class SsoServerController {
sso.setSendHttp(url -> {
try {
// 发起 http 请求
System.out.println("发起请求:" + url);
return OkHttps.sync(url).get().getBody().toString();
System.out.println("------ 发起请求:" + url);
return Forest.get(url).executeAsString();
} catch (Exception e) {
e.printStackTrace();
return null;

View File

@@ -49,8 +49,10 @@ spring:
# 连接池中的最小空闲连接
min-idle: 0
forest:
# 关闭 forest 请求日志打印
log-enabled: false

View File

@@ -26,7 +26,7 @@
<dependency>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId>
<version>1.5.19</version>
<version>1.5.26</version>
</dependency>
</dependencies>

View File

@@ -56,9 +56,9 @@
<!-- Http请求工具 -->
<dependency>
<groupId>com.ejlchina</groupId>
<artifactId>okhttps</artifactId>
<version>3.1.1</version>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId>
<version>1.5.26</version>
</dependency>

View File

@@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ejlchina.okhttps.OkHttps;
import com.dtflys.forest.Forest;
import cn.dev33.satoken.config.SaSsoConfig;
import cn.dev33.satoken.sso.SaSsoHandle;
@@ -46,8 +46,8 @@ public class SsoClientController {
private void configSso(SaSsoConfig sso) {
// 配置Http请求处理器
sso.setSendHttp(url -> {
System.out.println("发起请求:" + url);
return OkHttps.sync(url).get().getBody().toString();
System.out.println("------ 发起请求:" + url);
return Forest.get(url).executeAsString();
});
}

View File

@@ -45,7 +45,9 @@ spring:
# 连接池中的最小空闲连接
min-idle: 0
forest:
# 关闭 forest 请求日志打印
log-enabled: false