Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
abf4b164
提交
abf4b164
authored
4月 25, 2022
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(base): 修改了path的正则匹配
上级
319a46f1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
10 行删除
+20
-10
HttpClientActuator.java
...a/org/matrix/actuators/httpclient/HttpClientActuator.java
+3
-4
CompleteExpressionUtil.java
...ava/org/matrix/actuators/util/CompleteExpressionUtil.java
+17
-6
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/httpclient/HttpClientActuator.java
浏览文件 @
abf4b164
...
@@ -140,8 +140,7 @@ public class HttpClientActuator implements Actuator {
...
@@ -140,8 +140,7 @@ public class HttpClientActuator implements Actuator {
completeHttpRequestDetail
(
httpRequestDetail
,
envId
,
projectId
);
completeHttpRequestDetail
(
httpRequestDetail
,
envId
,
projectId
);
CloseableHttpResponse
response
=
null
;
CloseableHttpResponse
response
=
null
;
Long
startTime
=
LocalDateTime
.
now
().
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
Long
startTime
=
LocalDateTime
.
now
().
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
String
url
=
initUrlString
(
httpRequestDetail
);
String
url
=
initUrlString
(
httpRequestDetail
,
envId
,
projectId
);
HttpRequestBase
requestBase
=
initHttpRequestBase
(
url
,
httpRequestDetail
.
getMethod
());
HttpRequestBase
requestBase
=
initHttpRequestBase
(
url
,
httpRequestDetail
.
getMethod
());
if
(
requestBase
instanceof
HttpEntityEnclosingRequestBase
)
{
if
(
requestBase
instanceof
HttpEntityEnclosingRequestBase
)
{
HttpEntity
httpRequestBase
=
initHttpEntity
(
httpRequestDetail
);
HttpEntity
httpRequestBase
=
initHttpEntity
(
httpRequestDetail
);
...
@@ -274,7 +273,7 @@ public class HttpClientActuator implements Actuator {
...
@@ -274,7 +273,7 @@ public class HttpClientActuator implements Actuator {
}
}
public
String
initUrlString
(
HttpRequestDetail
httpRequestDetail
)
{
public
String
initUrlString
(
HttpRequestDetail
httpRequestDetail
,
Long
envId
,
Long
projectId
)
{
String
url
=
httpRequestDetail
.
getUrl
();
String
url
=
httpRequestDetail
.
getUrl
();
try
{
try
{
if
(
httpRequestDetail
.
getRequestType
()
==
HttpRequestType
.
QUERY
)
{
if
(
httpRequestDetail
.
getRequestType
()
==
HttpRequestType
.
QUERY
)
{
...
@@ -297,7 +296,7 @@ public class HttpClientActuator implements Actuator {
...
@@ -297,7 +296,7 @@ public class HttpClientActuator implements Actuator {
List
<
RequestBody
>
requestBodies
=
httpRequestDetail
.
getRequestBodies
();
List
<
RequestBody
>
requestBodies
=
httpRequestDetail
.
getRequestBodies
();
Map
<
String
,
String
>
requestMap
=
Map
<
String
,
String
>
requestMap
=
requestBodies
.
stream
().
collect
(
Collectors
.
toMap
(
RequestBody:
:
getKey
,
RequestBody:
:
getValue
));
requestBodies
.
stream
().
collect
(
Collectors
.
toMap
(
RequestBody:
:
getKey
,
RequestBody:
:
getValue
));
url
=
completeExpressionUtil
.
completePathVariable
(
url
,
requestMap
);
url
=
completeExpressionUtil
.
completePathVariable
(
url
,
requestMap
,
envId
,
projectId
);
}
}
}
catch
(
URISyntaxException
e
)
{
}
catch
(
URISyntaxException
e
)
{
throw
new
HttpRequestException
(
String
.
format
(
"URL格式不正确,不正确的URL为: %s"
,
url
));
throw
new
HttpRequestException
(
String
.
format
(
"URL格式不正确,不正确的URL为: %s"
,
url
));
...
...
kt-base/src/main/java/org/matrix/actuators/util/CompleteExpressionUtil.java
浏览文件 @
abf4b164
...
@@ -9,6 +9,7 @@ import org.matrix.actuators.move.MoveActuator;
...
@@ -9,6 +9,7 @@ import org.matrix.actuators.move.MoveActuator;
import
org.matrix.actuators.sql.SqlExpActuator
;
import
org.matrix.actuators.sql.SqlExpActuator
;
import
org.matrix.util.SpringUtils
;
import
org.matrix.util.SpringUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -31,7 +32,7 @@ public class CompleteExpressionUtil {
...
@@ -31,7 +32,7 @@ public class CompleteExpressionUtil {
public
static
final
String
DYNAMIC_VARIABLE_REG
=
"\\$\\{(((?!(pre|mid|aft)[0-9]+\\.).)*?)}(\\[(.*?)])?"
;
public
static
final
String
DYNAMIC_VARIABLE_REG
=
"\\$\\{(((?!(pre|mid|aft)[0-9]+\\.).)*?)}(\\[(.*?)])?"
;
public
static
final
String
PATH_REG
=
"(?<=
\\{)(.+?)(?=\\})
"
;
public
static
final
String
PATH_REG
=
"(?<=
[^(\\$)])\\{(.+?)\\}
"
;
public
String
completeVariable
(
String
expression
,
Long
envId
,
Long
projectId
)
{
public
String
completeVariable
(
String
expression
,
Long
envId
,
Long
projectId
)
{
String
result
=
expression
;
String
result
=
expression
;
...
@@ -50,12 +51,23 @@ public class CompleteExpressionUtil {
...
@@ -50,12 +51,23 @@ public class CompleteExpressionUtil {
return
result
;
return
result
;
}
}
public
String
completePathVariable
(
String
expression
,
Map
<
String
,
String
>
source
)
{
public
String
completePathVariable
(
String
expression
,
Map
<
String
,
String
>
source
,
Long
envId
,
Long
projectId
)
{
String
result
=
expression
;
String
result
=
expression
;
result
=
regexExpression
(
result
=
regexExpression
(
result
,
PATH_REG
,
result
,
PATH_REG
,
source
,
(
o
,
s
)
->
source
,
(
o
,
s
)
->{
((
Map
<
String
,
String
>)
o
).
get
(
s
));
if
(
o
instanceof
Map
){
String
value
=
((
Map
<
String
,
String
>)
o
).
get
(
s
.
substring
(
1
,
s
.
length
()-
1
));
if
(
value
!=
null
&&!
""
.
equals
(
value
)){
completeVariable
(
value
,
envId
,
projectId
);
return
value
;
}
else
{
return
""
;
}
}
else
{
return
""
;
}
});
return
result
;
return
result
;
}
}
...
@@ -83,9 +95,8 @@ public class CompleteExpressionUtil {
...
@@ -83,9 +95,8 @@ public class CompleteExpressionUtil {
}
}
public
String
regexExpression
(
String
expression
,
String
regex
,
Object
sourceContent
,
BiFunction
<
Object
,
String
,
String
>
biFunction
){
public
String
regexExpression
(
String
expression
,
String
regex
,
Object
sourceContent
,
BiFunction
<
Object
,
String
,
String
>
biFunction
){
String
result
=
expression
;
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Matcher
mat
=
pattern
.
matcher
(
result
);
Matcher
mat
=
pattern
.
matcher
(
expression
);
StringBuffer
sBuffer
=
new
StringBuffer
();
StringBuffer
sBuffer
=
new
StringBuffer
();
while
(
mat
.
find
())
{
while
(
mat
.
find
())
{
String
group
=
mat
.
group
();
String
group
=
mat
.
group
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论