Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
826e8fa5
提交
826e8fa5
authored
1月 21, 2022
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(base): 优化!使代码更简洁了
上级
fb244ef8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
3 行删除
+24
-3
CheckPointActuator.java
...a/org/matrix/actuators/checkpoint/CheckPointActuator.java
+24
-3
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/checkpoint/CheckPointActuator.java
浏览文件 @
826e8fa5
...
@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONException;
...
@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONException;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jayway.jsonpath.Configuration
;
import
com.jayway.jsonpath.Configuration
;
import
com.jayway.jsonpath.DocumentContext
;
import
com.jayway.jsonpath.JsonPath
;
import
com.jayway.jsonpath.JsonPath
;
import
com.jayway.jsonpath.PathNotFoundException
;
import
com.jayway.jsonpath.PathNotFoundException
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
...
@@ -21,6 +22,8 @@ import javax.script.ScriptEngine;
...
@@ -21,6 +22,8 @@ import javax.script.ScriptEngine;
import
javax.script.ScriptException
;
import
javax.script.ScriptException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.function.BiFunction
;
import
java.util.function.Function
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
...
@@ -122,21 +125,35 @@ public class CheckPointActuator implements Actuator {
...
@@ -122,21 +125,35 @@ public class CheckPointActuator implements Actuator {
return
jsEngine
;
return
jsEngine
;
}
}
/**
*
* @param jsonObject 这个Object 是由 Configuration.defaultConfiguration().jsonProvider().parse(“json字符串”); 这个方法转换过来的 请不要乱传
* @return
*/
public
String
completeJsonPathExpression
(
JsonPathCheckPoint
jsonPathCheckPoint
,
Object
jsonObject
)
{
public
String
completeJsonPathExpression
(
JsonPathCheckPoint
jsonPathCheckPoint
,
Object
jsonObject
)
{
String
result
=
jsonPathCheckPoint
.
getExpression
();
String
result
=
jsonPathCheckPoint
.
getExpression
();
//todo 李迪凡 先将result中的动态变量都还原出来 (先后顺序不能乱)得先还原动态变量
//todo 李迪凡 先将result中的动态变量都还原出来 (先后顺序不能乱)得先还原动态变量
//将jsonPath都还原出来
//将jsonPath都还原出来
String
regex
=
"(?=\\{)(.*?)(?<=})"
;
String
jsonPathRegex
=
"\\{(\\s)*\\$.*?}"
;
result
=
regexExpression
(
result
,
jsonPathRegex
,
jsonObject
,
(
o
,
s
)
->
JSON
.
toJSONString
(
JsonPath
.
read
(
o
,
s
.
substring
(
1
,
s
.
length
()
-
1
))));
return
result
;
}
public
static
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
(
result
);
while
(
mat
.
find
())
{
while
(
mat
.
find
())
{
String
group
=
mat
.
group
();
String
group
=
mat
.
group
();
String
read
=
JSON
.
toJSONString
(
JsonPath
.
read
(
jsonObject
,
group
.
substring
(
1
,
group
.
length
()
-
1
))
);
String
read
=
biFunction
.
apply
(
sourceContent
,
group
);
result
=
mat
.
replaceAll
(
read
);
result
=
mat
.
replaceAll
(
read
);
}
}
return
result
;
return
result
;
}
}
public
CheckPointResultDetail
containCheck
(
ContainCheckPoint
containCheckPoint
,
String
responseBody
)
{
public
CheckPointResultDetail
containCheck
(
ContainCheckPoint
containCheckPoint
,
String
responseBody
)
{
if
(
responseBody
.
contains
(
containCheckPoint
.
getValue
()))
{
if
(
responseBody
.
contains
(
containCheckPoint
.
getValue
()))
{
return
new
CheckPointResultDetail
(
return
new
CheckPointResultDetail
(
...
@@ -205,9 +222,13 @@ public class CheckPointActuator implements Actuator {
...
@@ -205,9 +222,13 @@ public class CheckPointActuator implements Actuator {
}
else
{
}
else
{
return
new
CheckPointResultDetail
(
return
new
CheckPointResultDetail
(
true
,
true
,
String
.
format
(
"异常检查点,检查未通过,Http请求错误,错误码:%d,请求结果:%s"
,
httpResponseDetail
.
getStatusCode
(),
httpResponseDetail
.
getResponseBody
())
String
.
format
(
"异常检查点,检查未通过,Http请求错误,错误码:%d,请求结果:%s"
,
httpResponseDetail
.
getStatusCode
()
.
value
()
,
httpResponseDetail
.
getResponseBody
())
);
);
}
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论