【3.7.4 开源代码同步】新增断言异常类和断言工具类,优化JWT工具类,更新文件类型白名单,切换undertow配置,修改多个YAML配置文件

This commit is contained in:
JEECG
2025-03-30 17:51:55 +08:00
parent 4fb53637aa
commit 9191a8b620
50 changed files with 679 additions and 930 deletions

View File

@ -36,7 +36,7 @@ public class FlywayConfig {
*/
@Value("${spring.flyway.enabled:false}")
private Boolean enabled;
/**
* 编码格式默认UTF-8
*/
@ -102,7 +102,7 @@ public class FlywayConfig {
if(!enabled){
return;
}
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
Map<String, DataSource> dataSources = ds.getDataSources();
dataSources.forEach((k, v) -> {

View File

@ -1,7 +1,11 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
# max-http-post-size: 10MB # 平替 tomcat server.tomcat.max-swallow-siz undertow该值默认为-1
worker-threads: 16 # 4核CPU标准配置
buffers:
websocket: 8192 # WebSocket缓冲 以字节为单位这里设置为8 KB
io: 16384 # IO操作缓冲 以字节为单位这里设置为16 KB
error:
include-exception: true
include-stacktrace: ALWAYS
@ -269,11 +273,6 @@ jeecg:
app-id: ??
api-key: ??
secret-key: ??
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
#cas单点登录
cas:
prefixUrl: http://cas.example.org:8443/cas

View File

@ -1,7 +1,11 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
# max-http-post-size: 10MB # 平替 tomcat server.tomcat.max-swallow-siz undertow该值默认为-1
worker-threads: 16 # 4核CPU标准配置
buffers:
websocket: 8192 # WebSocket缓冲 以字节为单位这里设置为8 KB
io: 16384 # IO操作缓冲 以字节为单位这里设置为16 KB
error:
include-exception: true
include-stacktrace: ALWAYS
@ -230,11 +234,6 @@ jeecg:
password:
type: STANDALONE
enabled: true
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
#cas单点登录
cas:
prefixUrl: http://cas.example.org:8443/cas

View File

@ -1,7 +1,11 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
# max-http-post-size: 10MB # 平替 tomcat server.tomcat.max-swallow-siz undertow该值默认为-1
worker-threads: 16 # 4核CPU标准配置
buffers:
websocket: 8192 # WebSocket缓冲 以字节为单位这里设置为8 KB
io: 16384 # IO操作缓冲 以字节为单位这里设置为16 KB
error:
include-exception: true
include-stacktrace: ALWAYS
@ -209,11 +213,6 @@ jeecg:
secretKey: ??
endpoint: oss-cn-beijing.aliyuncs.com
bucketName: jeecgdev
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
# 在线预览文件服务器地址配置
file-view-domain: http://fileview.jeecg.com
# minio文件上传

View File

@ -1,7 +1,7 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
worker-threads: 16
error:
include-exception: true
include-stacktrace: ALWAYS
@ -22,7 +22,7 @@ management:
spring:
flyway:
# 是否启用flyway
enabled: false
enabled: true
# 是否关闭要清除已有库下的表功能,生产环境必须为true,否则会删库,非常重要!!!
clean-disabled: true
servlet:
@ -230,11 +230,7 @@ jeecg:
SMS_465391221:
# 注册账号短信模板编码
SMS_175430166:
# ElasticSearch 设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
SMS_461885023:
# 在线预览文件服务器地址配置
file-view-domain: http://fileview.jeecg.com
# minio文件上传

View File

@ -1,7 +1,7 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
worker-threads: 16
error:
include-exception: true
include-stacktrace: ALWAYS
@ -22,9 +22,9 @@ management:
spring:
flyway:
# 是否启用flyway
enabled: false
# 是否关闭要清除已有库下的表功能,生产环境必须为true,否则会删库,非常重要!!!
clean-disabled: true
enabled: true
# 迁移sql脚本存放路径
locations: classpath:flyway/sql/mysql
servlet:
multipart:
max-file-size: 10MB
@ -270,11 +270,6 @@ jeecg:
app-id: ??
api-key: ??
secret-key: ??
# ElasticSearch 设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 192.168.1.188:9200
check-enabled: false
#Mybatis输出sql日志
logging:
level:

View File

@ -1,47 +1,47 @@
//package org.jeecg;
//
//import com.alibaba.fastjson.JSONObject;
//import org.jeecg.common.util.RestUtil;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//
///**
// * @Description: TODO
// * @author: scott
// * @date: 2022年05月10日 14:02
// */
//public class TestMain {
// public static void main(String[] args) {
// // 请求地址
// String url = "https://api.boot.jeecg.com/sys/user/list";
// // 请求 Header 用于传递Token
// HttpHeaders headers = getHeaders();
// // 请求方式是 GET 代表获取数据
// HttpMethod method = HttpMethod.GET;
//
// System.out.println("请求地址:" + url);
// System.out.println("请求方式:" + method);
//
// // 利用 RestUtil 请求该url
// ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
// if (result != null && result.getBody() != null) {
// System.out.println("返回结果:" + result.getBody().toJSONString());
// } else {
// System.out.println("查询失败");
// }
// }
// private static HttpHeaders getHeaders() {
// String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.50h-g6INOZRVnznExiawFb1U6PPjcVVA4POeYRA5a5Q";
// System.out.println("请求Token" + token);
//
// HttpHeaders headers = new HttpHeaders();
// String mediaType = MediaType.APPLICATION_JSON_VALUE;
// headers.setContentType(MediaType.parseMediaType(mediaType));
// headers.set("Accept", mediaType);
// headers.set("X-Access-Token", token);
// return headers;
// }
//
//}
package org.jeecg;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.util.RestUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
/**
* @Description: TODO
* @author: scott
* @date: 2022年05月10日 14:02
*/
public class TestMain {
public static void main(String[] args) {
// 请求地址
String url = "https://api3.boot.jeecg.com/sys/user/list";
// 请求 Header 用于传递Token
HttpHeaders headers = getHeaders();
// 请求方式是 GET 代表获取数据
HttpMethod method = HttpMethod.GET;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
private static HttpHeaders getHeaders() {
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.50h-g6INOZRVnznExiawFb1U6PPjcVVA4POeYRA5a5Q";
System.out.println("请求Token" + token);
HttpHeaders headers = new HttpHeaders();
String mediaType = MediaType.APPLICATION_JSON_VALUE;
headers.setContentType(MediaType.parseMediaType(mediaType));
headers.set("Accept", mediaType);
headers.set("X-Access-Token", token);
return headers;
}
}

View File

@ -1,83 +0,0 @@
package org.jeecg.modules.system.test;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.JeecgSystemApplication;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.RestUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
/**
* 系统用户单元测试
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class)
public class InsertDemoTest {
/**
* 测试地址:实际使用时替换成你自己的地址
*/
private final String BASE_URL = "http://localhost:8080/jeecg-boot//test/jeecgDemo/";
//测试:用户名和密码
private final String USERNAME = "admin";
private final String PASSWORD = "123456";
@Autowired
private RedisUtil redisUtil;
/**
* 测试用例:新增
*/
@Test
public void testAdd() {
// 请求地址
String url = BASE_URL + "add" ;
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 POST 代表提交新增数据
HttpMethod method = HttpMethod.POST;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
for (int i = 0; i < 100; i++) {
String name = "李哈哈" + i;
JSONObject params = new JSONObject();
params.put("name", name);
System.out.println("请求参数:" + params.toJSONString());
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
}
private String getToken() {
String token = JwtUtil.sign(USERNAME, PASSWORD);
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60);
return token;
}
private HttpHeaders getHeaders() {
String token = this.getToken();
System.out.println("请求Token" + token);
HttpHeaders headers = new HttpHeaders();
String mediaType = MediaType.APPLICATION_JSON_VALUE;
headers.setContentType(MediaType.parseMediaType(mediaType));
headers.set("Accept", mediaType);
headers.set("X-Access-Token", token);
return headers;
}
}

View File

@ -6,10 +6,9 @@ import org.jeecg.modules.demo.test.entity.JeecgDemo;
import org.jeecg.modules.demo.test.mapper.JeecgDemoMapper;
import org.jeecg.modules.demo.test.service.IJeecgDemoService;
import org.jeecg.modules.system.service.ISysDataLogService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.List;
@ -29,7 +28,7 @@ public class SampleTest {
public void testSelect() {
System.out.println(("----- selectAll method test ------"));
List<JeecgDemo> userList = jeecgDemoMapper.selectList(null);
Assertions.assertEquals(5, userList.size());
Assert.isTrue(15==userList.size(),"结果不是5条");
userList.forEach(System.out::println);
}

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.system.test;
import org.aspectj.lang.annotation.Before;
import org.jeecg.JeecgSystemApplication;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.config.JeecgBaseConfig;
@ -8,7 +9,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @Description: 系统表白名单测试

View File

@ -1,175 +0,0 @@
package org.jeecg.modules.system.test;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.JeecgSystemApplication;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.RestUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
/**
* 系统用户单元测试
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class)
public class SysUserTest {
/**
* 测试地址:实际使用时替换成你自己的地址
*/
private final String BASE_URL = "http://localhost:8080/jeecg-boot/sys/user/";
//测试:用户名和密码
private final String USERNAME = "admin";
private final String PASSWORD = "123456";
@Autowired
private RedisUtil redisUtil;
/**
* 测试用例:查询记录
*/
@Test
public void testQuery() {
// 请求地址
String url = BASE_URL + "list";
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 GET 代表获取数据
HttpMethod method = HttpMethod.GET;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
/**
* 测试用例:新增
*/
@Test
public void testAdd() {
// 请求地址
String url = BASE_URL + "add" ;
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 POST 代表提交新增数据
HttpMethod method = HttpMethod.POST;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
JSONObject params = new JSONObject();
params.put("username", "wangwuTest");
params.put("password", "123456");
params.put("confirmpassword","123456");
params.put("realname", "单元测试");
params.put("activitiSync", "1");
params.put("userIdentity","1");
params.put("workNo","0025");
System.out.println("请求参数:" + params.toJSONString());
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
/**
* 测试用例:修改
*/
@Test
public void testEdit() {
// 数据Id
String dataId = "1331795062924374018";
// 请求地址
String url = BASE_URL + "edit";
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 PUT 代表提交修改数据
HttpMethod method = HttpMethod.PUT;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
JSONObject params = new JSONObject();
params.put("username", "wangwuTest");
params.put("realname", "单元测试1111");
params.put("activitiSync", "1");
params.put("userIdentity","1");
params.put("workNo","0025");
params.put("id",dataId);
System.out.println("请求参数:" + params.toJSONString());
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
/**
* 测试用例:删除
*/
@Test
public void testDelete() {
// 数据Id
String dataId = "1331795062924374018";
// 请求地址
String url = BASE_URL + "delete" + "?id=" + dataId;
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 DELETE 代表删除数据
HttpMethod method = HttpMethod.DELETE;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
private String getToken() {
String token = JwtUtil.sign(USERNAME, PASSWORD);
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60);
return token;
}
private HttpHeaders getHeaders() {
String token = this.getToken();
System.out.println("请求Token" + token);
HttpHeaders headers = new HttpHeaders();
String mediaType = MediaType.APPLICATION_JSON_VALUE;
headers.setContentType(MediaType.parseMediaType(mediaType));
headers.set("Accept", mediaType);
headers.set("X-Access-Token", token);
return headers;
}
}

View File

@ -1,5 +1,6 @@
package org.jeecg.smallTools;
import org.junit.jupiter.api.Test;
/**

View File

@ -2,11 +2,17 @@ package org.jeecg.smallTools;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.DateUtils;
import org.junit.jupiter.api.Test;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
/**
* 字符串处理测试
@ -37,6 +43,23 @@ public class TestStr {
System.out.println("length = "+ conditionValueArray.length);
Arrays.stream(conditionValueArray).forEach(System.out::println);
}
@Test
public void getThisDate() {
LocalDate d = DateUtils.getLocalDate();
System.out.println(d);
}
@Test
public void firstDayOfLastSixMonths() {
LocalDate today = LocalDate.now(); // 获取当前日期
LocalDate firstDayOfLastSixMonths = today.minusMonths(6).withDayOfMonth(1); // 获取近半年的第一天
LocalDateTime firstDateTime = LocalDateTime.of(firstDayOfLastSixMonths, LocalTime.MIN); // 设置时间为当天的最小时间00:00:00
Date date = Date.from(firstDateTime.atZone(ZoneId.systemDefault()).toInstant()); // 将 LocalDateTime 转换为 Date
System.out.println("近半年的第一天的 00:00:00 时间戳:" + date);
}
@Test
public void testJSONArrayJoin() {
@ -67,7 +90,7 @@ public class TestStr {
*/
@Test
public void testSpecialChar() {
String str = "Hello, World! 你好这是一段特殊符号的测试This is a test string with special characters: @#$%^&*";
String str = "Hello, World! 你好这是一段特殊符号的测试This is__ a test string with special characters: @#$%^&*";
// 使用正则表达式替换特殊字符
String replacedStr = str.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", "");
System.out.println("Replaced String: " + replacedStr);