use of org.pdown.rest.entity.DownInfo in project proxyee-down by monkeyWie.
the class HttpDownAppCallback method commonHook.
private void commonHook(HttpDownBootstrap httpDownBootstrap, String event, boolean async) {
DownInfo downInfo = findDownInfo(httpDownBootstrap);
Map<String, Object> taskInfo = buildTaskInfo(downInfo);
if (taskInfo != null) {
// 遍历扩展模块是否有对应的处理
List<ExtensionInfo> extensionInfos = ExtensionContent.get();
for (ExtensionInfo extensionInfo : extensionInfos) {
if (extensionInfo.getMeta().isEnabled()) {
if (extensionInfo.getHookScript() != null && !StringUtils.isEmpty(extensionInfo.getHookScript().getScript())) {
Event e = extensionInfo.getHookScript().hasEvent(event, HttpDownUtil.getUrl(httpDownBootstrap.getRequest()));
if (e != null) {
try {
// 执行钩子函数
Object result = ExtensionUtil.invoke(extensionInfo, e, taskInfo, async);
if (result != null) {
ObjectMapper objectMapper = new ObjectMapper();
String temp = objectMapper.writeValueAsString(result);
TaskForm taskForm = objectMapper.readValue(temp, TaskForm.class);
if (taskForm.getRequest() != null) {
httpDownBootstrap.setRequest(HttpDownUtil.buildRequest(taskForm.getRequest().getMethod(), taskForm.getRequest().getUrl(), taskForm.getRequest().getHeads(), taskForm.getRequest().getBody()));
}
if (taskForm.getResponse() != null) {
httpDownBootstrap.setResponse(taskForm.getResponse());
}
if (taskForm.getData() != null) {
downInfo.setData(taskForm.getData());
}
HttpDownContent.getInstance().save();
}
} catch (Exception ex) {
LOGGER.error("An hook exception occurred while " + event + "()", ex);
}
}
}
}
}
}
}
Aggregations