Skip to content

Commit 33dc3d8

Browse files
committed
Java:MultiDataSource 解决代理接口对 PARAM, FORM, DATA 传参转发到目标服务额外多出部分 body 参数
1 parent deb16c1 commit 33dc3d8

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,49 @@ public String delegate(
12371237

12381238
body = obj.toJSONString();
12391239
}
1240+
else if ("PARAM".equals(type) || "FORM".equals(type)) {
1241+
body = null; // 居然把 GET param 和 POST form 的也取到
1242+
}
1243+
else if (body != null && "DATA".equals(type)) { // if (StringUtil.isNotEmpty(body, true)) {
1244+
int index = body.indexOf("%24_type=");
1245+
if (index < 0) {
1246+
index = body.indexOf("$_type=");
1247+
}
1248+
if (index < 0) {
1249+
index = body.indexOf("%24_record=");
1250+
}
1251+
if (index < 0) {
1252+
index = body.indexOf("$_record=");
1253+
}
1254+
if (index < 0) {
1255+
index = body.indexOf("%24_delegate_id=");
1256+
}
1257+
if (index < 0) {
1258+
index = body.indexOf("$_delegate_id=");
1259+
}
1260+
if (index < 0) {
1261+
index = body.indexOf("%24_delegate_url=");
1262+
}
1263+
if (index < 0) {
1264+
index = body.indexOf("$_delegate_url=");
1265+
}
1266+
if (index < 0) {
1267+
index = body.indexOf("%24_headers=");
1268+
}
1269+
if (index < 0) {
1270+
index = body.indexOf("$_headers=");
1271+
}
1272+
if (index < 0) {
1273+
index = body.indexOf("%24_except_headers=");
1274+
}
1275+
if (index < 0) {
1276+
index = body.indexOf("$_except_headers=");
1277+
}
1278+
1279+
if (index >= 0) {
1280+
body = body.substring(0, index);
1281+
}
1282+
}
12401283

12411284
Enumeration<String> names = httpServletRequest.getHeaderNames();
12421285
HttpHeaders headers = null;
@@ -1398,7 +1441,8 @@ else if (names != null) {
13981441

13991442
for (Entry<String, String[]> e : set) {
14001443
if (e != null) {
1401-
url += ((first ? "" : "&") + e.getKey() + "=" + ( e.getValue() == null || e.getValue().length <= 0 ? "" : StringUtil.getString(e.getValue()[0]) ));
1444+
String[] vals = e.getValue();
1445+
url += ((first ? "" : "&") + e.getKey() + "=" + ( vals == null || vals.length <= 0 ? "" : StringUtil.getString(vals[0]) ));
14021446
first = false;
14031447
}
14041448
}

0 commit comments

Comments
 (0)