Skip to content

Commit 8536d8a

Browse files
committed
Java:MultiDataSource 支持代理转发 HTTP PATCH 请求;APIAuto:分组数量悬浮显示完整 名称 URL;解决不显示 HTTP Error,解决场景串联用例有时错用参数配置
1 parent 7a7eca6 commit 8536d8a

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@
286286
</exclusions>
287287
</dependency>
288288

289+
<!-- DemoController /delegate 代理转发请求 HTTP PATCH 方法需要,使用 PATCH 可以取消注释 -->
290+
<!-- <dependency>-->
291+
<!-- <groupId>org.apache.httpcomponents.client5</groupId>-->
292+
<!-- <artifactId>httpclient5</artifactId>-->
293+
<!-- <version>5.3</version>-->
294+
<!-- </dependency>-->
295+
289296
<!-- &lt;!&ndash; 需要用的 HikariCP 数据库连接池库,3.1.0 以上 &ndash;&gt;-->
290297
<!-- <dependency>-->
291298
<!-- <groupId>com.zaxxer</groupId>-->

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@
2525

2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.http.*;
28+
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
2829
import org.springframework.stereotype.Service;
29-
import org.springframework.web.bind.annotation.GetMapping;
30-
import org.springframework.web.bind.annotation.PathVariable;
31-
import org.springframework.web.bind.annotation.PostMapping;
32-
import org.springframework.web.bind.annotation.RequestBody;
33-
import org.springframework.web.bind.annotation.RequestMapping;
34-
import org.springframework.web.bind.annotation.RequestParam;
35-
import org.springframework.web.bind.annotation.RestController;
30+
import org.springframework.web.bind.annotation.*;
3631
import org.springframework.web.client.HttpClientErrorException;
3732
import org.springframework.web.client.RestClientResponseException;
3833
import org.springframework.web.client.RestTemplate;
@@ -1869,6 +1864,14 @@ protected String sendRequest(HttpSession session, HttpMethod method, String url,
18691864
String rspBody = null;
18701865
try {
18711866
RestTemplate client = new RestTemplate();
1867+
try { // 支持 PATCH 方法,需要 Maven 依赖 org.apache.httpcomponents.client5:httpclient5
1868+
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
1869+
client.setRequestFactory(requestFactory);
1870+
}
1871+
catch (Throwable e) {
1872+
e.printStackTrace();
1873+
}
1874+
18721875
HttpEntity<String> requestEntity = new HttpEntity<>(method == HttpMethod.GET ? null : body, headers);
18731876
ResponseEntity<String> entity = client.exchange(url, method, requestEntity, String.class);
18741877

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
<li v-for="(item, index) in caseGroups" :id="'caseGroup' + index" >
204204
<div style="display: inline-table; width: 100%">
205205
<input v-show="isCaseGroupEditable" style="min-width: 60px; width: 40%; margin-right: 6px" v-model="item.groupName" @keyup="doOnKeyUp(event, 'caseGroup', false, item)" />
206-
<a href="javascript:void(0)" @click="selectCaseGroup(index, item)" > {{(isCaseGroupEditable ? '' : (StringUtil.isEmpty(item.groupName) ? '-' : item.groupName) + ' ') + item.groupUrl}}</a><a style="right: 0px; position: absolute; z-index: 100; width: fit-content; background-color: white">{{' (' + item.count + ') '}}</a>
206+
<a href="javascript:void(0)" @click="selectCaseGroup(index, item)" > {{(isCaseGroupEditable ? '' : (StringUtil.isEmpty(item.groupName) ? '-' : item.groupName) + ' ') + item.groupUrl}}</a><a style="right: 0px; position: absolute; z-index: 100; width: fit-content; background-color: white" class="hint--left" :data-hint="(StringUtil.isEmpty(item.groupName) ? '-' : item.groupName) + ' ' + item.groupUrl">{{' (' + item.count + ') '}}</a>
207207
<!-- <div v-show="isStatisticsEnabled" style="position: absolute; right: 36px; top: 8px; display: inline-flex">-->
208208
<!-- <div v-show="(item.totalCount || 0) > 0" style="background: lightgray; padding: 1px; margin-right: 2px; display: inline-block; position: relative" @click="restoreRemote(index, item, null, true)" >-->
209209
<!-- &lt;!&ndash; 只能写成一行来消除间隙,不能换行、空格 &ndash;&gt;-->
@@ -231,13 +231,13 @@
231231
</div>
232232

233233
<div v-show="isChainShow && isChainGroupShow() && ! isLocalShow" :style="{width: chainShowType == 0 ? '40%' : '100%', 'border-right': chainShowType != 0 ? 'none' : '#DDD 1px solid' }" style="float: left; min-width: 30px; width: 40%; height: 100%;">
234-
<input id="vChainGroupAdd" style="width: 100%" @keyup="doOnKeyUp(event, 'chainGroupAdd', false, {'groupName': vChainGroupAdd.value})" placeholder="输入名称,回车来添加" />
234+
<input id="vChainGroupAdd" style="width: 100%; text-align: center" @keyup="doOnKeyUp(event, 'chainGroupAdd', false, {'groupName': vChainGroupAdd.value})" placeholder="输入名称,回车来添加" />
235235

236236
<ul class="historys" style="width: 100%; height: 100%;overflow: hidden;overflow-y: scroll;padding-bottom: 50px">
237237
<li v-for="(item, index) in chainGroups" :id="'chainGroup' + index" >
238238
<div style="display: inline-table; width: 100%">
239239
<input v-show="isCaseGroupEditable" style="min-width: 60px; width: 40%; margin-right: 6px" v-model="item.Chain.groupName" @keyup="doOnKeyUp(event, 'chainGroup', false, item)" />
240-
<a href="javascript:void(0)" @click="selectChainGroup(index, item.Chain)" :style="{ color: index == currentChainGroupIndex ? 'black' : 'gray' }" >{{ isCaseGroupEditable ? '' : item.Chain.groupName }}</a><a style="right: 0px; position: absolute; z-index: 100; width: fit-content; background-color: white; margin-right: 24px">{{' (' + (item.Chain.count - 1) + ') '}}</a>
240+
<a href="javascript:void(0)" @click="selectChainGroup(index, item.Chain)" :style="{ color: index == currentChainGroupIndex ? 'black' : 'gray' }" >{{ isCaseGroupEditable ? '' : item.Chain.groupName }}</a><a style="right: 0px; position: absolute; z-index: 100; width: fit-content; background-color: white; margin-right: 24px" class="hint--left" :data-hint="item.Chain.groupName">{{' (' + (item.Chain.count - 1) + ') '}}</a>
241241
<svg class="icon" @click="remove(item, index, true, false, false, true)" style="background-color: white; width: 27px; height: 18px; right: -2px; top: 10px; padding-left: 3px; padding-right: 4px; padding-top: 2px; padding-bottom: 2px;" >
242242
<use xlink:href="svg/icon.svg#trash"></use>
243243
</svg>
@@ -256,7 +256,7 @@
256256

257257

258258
<div v-show="isLocalShow || isCaseItemShow()" :style="{width: isCaseGroupShow() && ! isLocalShow ? '60%' : '100%'}" style="float: right; flex-grow: 1; height: 100%;">
259-
<input id="vChainAdd" v-show="isChainShow && currentChainGroupIndex >= 0" style="width: 100%" @keyup="doOnKeyUp(event, 'chainAdd', false, {'groupName': vChainAdd.value})" placeholder="输入名称,回车来搜索及添加" />
259+
<input id="vChainAdd" v-show="isChainShow && currentChainGroupIndex >= 0" style="width: 100%; text-align: center" @keyup="doOnKeyUp(event, 'chainAdd', false, {'groupName': vChainAdd.value})" placeholder="输入名称,回车来搜索及添加" />
260260

261261
<ul class="historys" style="width: 100%; height: 100%;overflow: hidden;overflow-y: scroll;padding-bottom: 50px">
262262
<li v-for="(item, index) in testCases" :id="'docItem' + index" >

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/js/main.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -2700,6 +2700,7 @@ https://github.com/Tencent/APIJSON/issues
27002700
vUrl.value = item.host + bu
27012701
this.showUrl(false, bu)
27022702

2703+
this.saveCache('', 'URL_BASE', baseUrl)
27032704
this.saveCache('', 'projectHost', this.projectHost)
27042705
},
27052706

@@ -3136,7 +3137,6 @@ https://github.com/Tencent/APIJSON/issues
31363137
commentObj = JSONResponse.updateStandard({}, mapReq2);
31373138
}
31383139

3139-
31403140
var callback = function (randomName, constConfig, constJson) {
31413141
// 用现成的测试过的更好,Response 与 Request 严格对应
31423142
// var mapReq = {};
@@ -3169,6 +3169,7 @@ https://github.com/Tencent/APIJSON/issues
31693169
// commentObj = JSONResponse.updateStandard({}, mapReq2);
31703170
// }
31713171

3172+
const userId = App.User.id;
31723173
const methods = App.methods;
31733174
const method = App.isShowMethod() ? App.method : null;
31743175
const extName = App.exTxt.name;
@@ -3178,6 +3179,7 @@ https://github.com/Tencent/APIJSON/issues
31783179
const req = isExportRandom && btnIndex <= 0 ? {
31793180
format: false,
31803181
'Random': {
3182+
userId: userId,
31813183
toId: 0,
31823184
chainGroupId: cgId,
31833185
chainId: cId,
@@ -3187,6 +3189,8 @@ https://github.com/Tencent/APIJSON/issues
31873189
config: config
31883190
},
31893191
'TestRecord': {
3192+
'userId': userId,
3193+
'documentId': documentId,
31903194
'host': StringUtil.isEmpty(baseUrl, true) ? null : baseUrl,
31913195
'chainGroupId': cgId,
31923196
'chainId': cId,
@@ -3198,6 +3202,7 @@ https://github.com/Tencent/APIJSON/issues
31983202
format: false,
31993203
'Document': isEditResponse ? null : {
32003204
'id': did == null ? undefined : did,
3205+
'userId': userId,
32013206
'project': StringUtil.isEmpty(project, true) ? null : project,
32023207
// 'testAccountId': currentAccountId,
32033208
// 'chainGroupId': cgId,
@@ -3213,6 +3218,7 @@ https://github.com/Tencent/APIJSON/issues
32133218
'detail': App.getExtraComment() || ((App.currentRemoteItem || {}).Document || {}).detail,
32143219
},
32153220
'TestRecord': isEditResponse != true && did != null ? null : {
3221+
'userId': userId,
32163222
// 'chainGroupId': cgId,
32173223
'documentId': isEditResponse ? did : undefined,
32183224
'randomId': 0,
@@ -7184,12 +7190,12 @@ https://github.com/Tencent/APIJSON/issues
71847190
if (res == null) {
71857191
res = {}
71867192
} else {
7187-
var time = res.config == null || res.config.metadata == null ? 0 : (res.config.metadata.startTime || 0)
7188-
if (time < this.lastReqTime) {
7193+
var time = res.config == null || res.config.metadata == null ? null : res.config.metadata.startTime;
7194+
if (time != null && time > 0 && time < this.lastReqTime) {
71897195
return
71907196
}
71917197

7192-
this.lastReqTime = time
7198+
this.lastReqTime = time == null || time <= 0 ? 0 : time;
71937199
}
71947200

71957201
if (DEBUG) {
@@ -7514,8 +7520,9 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
75147520

75157521
var project = (this.projectHost || {}).project
75167522

7517-
if (isFilter && type == 'caseGroup') {
7523+
if (isFilter && (type == 'caseGroup' || type == 'chainGroup')) {
75187524
this.isCaseGroupEditable = true
7525+
// this.isChainGroupEditable = true
75197526
}
75207527

75217528
var obj = event.srcElement ? event.srcElement : event.target;

0 commit comments

Comments
 (0)