|
@@ -76,7 +76,10 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
|
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(setting.getUrl(), HttpMethod.POST,
|
|
|
requestEntity, String.class);
|
|
|
log.info("[execute][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity);
|
|
|
+
|
|
|
+ // TODO @jason:建议把请求和失败,放在两个 try catch 里处理。
|
|
|
// 4. 处理请求返回
|
|
|
+ // TODO @jason:返回结果,要不统一用 CommonResult,符合这个规范。这样,就可以验证 code 为 0 了。必须符合这个规范~~
|
|
|
if (CollUtil.isNotEmpty(setting.getResponse()) && responseEntity.getStatusCode().is2xxSuccessful()
|
|
|
&& StrUtil.isNotEmpty(responseEntity.getBody())) {
|
|
|
// 4.1 获取需要更新的流程变量
|
|
@@ -86,15 +89,15 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
|
|
|
processInstanceService.updateProcessInstanceVariables(processInstanceId, updateVariables);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} catch (RestClientException e) {
|
|
|
log.error("[execute][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 从请求返回值获取需要更新的流程变量。优先从 data 字段获取,如果 data 字段不存在,从根节点获取。
|
|
|
+ * 从请求返回值获取需要更新的流程变量
|
|
|
+ *
|
|
|
+ * 优先从 data 字段获取,如果 data 字段不存在,从根节点获取
|
|
|
*
|
|
|
* @param responseBody 请求返回报文体
|
|
|
* @param responseSettings 返回设置
|
|
@@ -103,18 +106,21 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
|
|
|
private Map<String, Object> getNeedUpdatedVariablesFromResponse(String responseBody,
|
|
|
List<KeyValue<String, String>> responseSettings) {
|
|
|
Map<String, Object> updateVariables = new HashMap<>();
|
|
|
+ // TODO @jason:这里 if return 更简洁一点;
|
|
|
+ // TODO @jason:JSONUtil => JsonUtils,尽量包一层
|
|
|
if (JSONUtil.isTypeJSONObject(responseBody)) {
|
|
|
JSONObject dataObj = null;
|
|
|
if (JSONUtil.parseObj(responseBody).getObj(PARSE_RESPONSE_FIELD) instanceof JSONObject) {
|
|
|
dataObj = (JSONObject) JSONUtil.parseObj(responseBody).getObj(PARSE_RESPONSE_FIELD);
|
|
|
}
|
|
|
JSONObject updateObj = dataObj == null ? JSONUtil.parseObj(responseBody) : dataObj;
|
|
|
- responseSettings.forEach(respSetting -> {
|
|
|
- if (StrUtil.isNotEmpty(respSetting.getKey()) && updateObj.containsKey(respSetting.getValue())) {
|
|
|
- updateVariables.put(respSetting.getKey(), updateObj.get(respSetting.getValue()));
|
|
|
+ responseSettings.forEach(responseSetting -> {
|
|
|
+ if (StrUtil.isNotEmpty(responseSetting.getKey()) && updateObj.containsKey(responseSetting.getValue())) {
|
|
|
+ updateVariables.put(responseSetting.getKey(), updateObj.get(responseSetting.getValue()));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
return updateVariables;
|
|
|
}
|
|
|
+
|
|
|
}
|