Skip to content

Commit dbc1b9f

Browse files
committed
Java:MultiDataSource 新增后台 Headless 自动化测试接口,并支持内部请求突破默认查询数量限制
1 parent fd39e18 commit dbc1b9f

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@
142142
</dependency>
143143

144144
<!-- 需要用的 HikariCP 数据库连接池库,3.1.0 以上 -->
145-
<!-- <dependency>-->
146-
<!-- <groupId>com.zaxxer</groupId>-->
147-
<!-- <artifactId>HikariCP</artifactId>-->
148-
<!-- <version>5.0.1</version>-->
149-
<!-- </dependency>-->
145+
<dependency>
146+
<groupId>com.zaxxer</groupId>
147+
<artifactId>HikariCP</artifactId>
148+
<version>5.0.1</version>
149+
</dependency>
150150

151151
<!-- 需要用的 Druid 数据库连接池库,1.0.29 以上 -->
152152
<dependency>

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/DemoController.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.springframework.web.bind.annotation.RestController;
4949
import org.springframework.web.client.RestTemplate;
5050

51+
import java.io.IOException;
5152
import java.net.URLDecoder;
5253
import java.rmi.ServerException;
5354
import java.sql.PreparedStatement;
@@ -75,7 +76,6 @@
7576
import apijson.Log;
7677
import apijson.RequestMethod;
7778
import apijson.StringUtil;
78-
import apijson.demo.CompareUtil;
7979
import apijson.demo.DemoFunctionParser;
8080
import apijson.demo.DemoParser;
8181
import apijson.demo.DemoSQLConfig;
@@ -2030,6 +2030,20 @@ public void invokeMethod(@RequestBody String request, HttpServletRequest servlet
20302030
super.invokeMethod(request, servletRequest);
20312031
}
20322032

2033+
2034+
@GetMapping("/api/test/start")
2035+
public String startApiTest(HttpServletResponse response, HttpSession session) throws Exception {
2036+
//response.sendRedirect("http://localhost:3000/test/start");
2037+
long id = 100000 + Math.round(899999*Math.random());
2038+
DemoParser.KEY_MAP.put(id, session); // 调这个接口一般是前端/CI/CD,调查询接口的是 Node,Session 不同 session.setAttribute("key", id);
2039+
return delegate("http://localhost:3000/test/start?key=" + id, null, null, null, null, HttpMethod.GET, session);
2040+
}
2041+
@GetMapping("/api/test/status")
2042+
public String getApiTestStatus(HttpServletResponse response, HttpSession session) throws Exception {
2043+
//response.sendRedirect("http://localhost:3000/test/status");
2044+
return delegate("http://localhost:3000/test/status", null, null, null, null, HttpMethod.GET, session);
2045+
}
2046+
20332047
// 为 UnitAuto 提供的单元测试接口 https://github.com/TommyLemon/UnitAuto >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
20342048

20352049

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/demo/DemoParser.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
import com.alibaba.fastjson.JSONObject;
1818

19+
import java.util.HashMap;
20+
import java.util.Map;
21+
1922
import javax.servlet.http.HttpSession;
2023

2124
import apijson.RequestMethod;
@@ -35,6 +38,11 @@
3538
*/
3639
public class DemoParser extends APIJSONParser<Long> {
3740

41+
public static final Map<Long, HttpSession> KEY_MAP;
42+
static {
43+
KEY_MAP = new HashMap<>();
44+
}
45+
3846
public DemoParser() {
3947
super();
4048
}
@@ -45,12 +53,26 @@ public DemoParser(RequestMethod method, boolean needVerify) {
4553
super(method, needVerify);
4654
}
4755

56+
private int maxQueryCount = MAX_QUERY_COUNT;
4857
// 可重写来设置最大查询数量
49-
// @Override
50-
// public int getMaxQueryCount() {
51-
// return 50;
52-
// }
58+
@Override
59+
public int getMaxQueryCount() {
60+
return maxQueryCount;
61+
}
5362

63+
@Override
64+
public JSONObject parseResponse(JSONObject request) {
65+
try { // 内部使用,可通过这种方式来突破限制,获得更大的自由度
66+
HttpSession session = KEY_MAP.get(request.getLong("key"));
67+
//DemoVerifier.verifyLogin(session);
68+
if (session != null) {
69+
request.remove("key");
70+
maxQueryCount = 1000;
71+
}
72+
} catch (Exception e) {}
73+
74+
return super.parseResponse(request);
75+
}
5476

5577
@Override
5678
public APIJSONObjectParser createObjectParser(JSONObject request, String parentPath, SQLConfig arrayConfig

0 commit comments

Comments
 (0)