feat(sj_1.0.0):
1、Webhook告警、工作流回调请求密钥常量
This commit is contained in:
parent
e4fe69d870
commit
30221e8339
@ -5,6 +5,7 @@ import cn.hutool.http.HttpResponse;
|
|||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.aizuda.snailjob.common.core.alarm.AlarmContext;
|
import com.aizuda.snailjob.common.core.alarm.AlarmContext;
|
||||||
import com.aizuda.snailjob.common.core.alarm.attribute.WebhookAttribute;
|
import com.aizuda.snailjob.common.core.alarm.attribute.WebhookAttribute;
|
||||||
|
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||||
import com.aizuda.snailjob.common.core.enums.AlarmTypeEnum;
|
import com.aizuda.snailjob.common.core.enums.AlarmTypeEnum;
|
||||||
import com.aizuda.snailjob.common.core.enums.ContentTypeEnum;
|
import com.aizuda.snailjob.common.core.enums.ContentTypeEnum;
|
||||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||||
@ -39,7 +40,7 @@ public class WebhookAlarm extends AbstractAlarm<AlarmContext> {
|
|||||||
|
|
||||||
HttpRequest post = HttpUtil.createPost(webhookAttribute.getWebhookUrl());
|
HttpRequest post = HttpUtil.createPost(webhookAttribute.getWebhookUrl());
|
||||||
HttpRequest request = post.body(JsonUtil.toJsonString(webhookMessage), ContentTypeEnum.valueOf(webhookAttribute.getContentType()).getMediaType().toString())
|
HttpRequest request = post.body(JsonUtil.toJsonString(webhookMessage), ContentTypeEnum.valueOf(webhookAttribute.getContentType()).getMediaType().toString())
|
||||||
.header("secret", webhookAttribute.getSecret());
|
.header(SystemConstants.SECRET, webhookAttribute.getSecret());
|
||||||
HttpResponse execute = request.execute();
|
HttpResponse execute = request.execute();
|
||||||
if (execute.isOk()) {
|
if (execute.isOk()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -146,4 +146,9 @@ public interface SystemConstants {
|
|||||||
* 日志类型字段
|
* 日志类型字段
|
||||||
*/
|
*/
|
||||||
String JSON_FILED_LOG_TYPE = "logType" ;
|
String JSON_FILED_LOG_TYPE = "logType" ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Webhook告警、工作流回调请求密钥
|
||||||
|
*/
|
||||||
|
String SECRET = "secret" ;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CallbackWorkflowExecutor extends AbstractWorkflowExecutor {
|
public class CallbackWorkflowExecutor extends AbstractWorkflowExecutor {
|
||||||
|
|
||||||
private static final String SECRET = "secret";
|
|
||||||
private static final String CALLBACK_TIMEOUT = "10";
|
private static final String CALLBACK_TIMEOUT = "10";
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
private final JobTaskMapper jobTaskMapper;
|
private final JobTaskMapper jobTaskMapper;
|
||||||
@ -87,7 +86,7 @@ public class CallbackWorkflowExecutor extends AbstractWorkflowExecutor {
|
|||||||
String result = null;
|
String result = null;
|
||||||
|
|
||||||
HttpHeaders requestHeaders = new HttpHeaders();
|
HttpHeaders requestHeaders = new HttpHeaders();
|
||||||
requestHeaders.set(SECRET, decisionConfig.getSecret());
|
requestHeaders.set(SystemConstants.SECRET, decisionConfig.getSecret());
|
||||||
requestHeaders.setContentType(ContentTypeEnum.valueOf(decisionConfig.getContentType()).getMediaType());
|
requestHeaders.setContentType(ContentTypeEnum.valueOf(decisionConfig.getContentType()).getMediaType());
|
||||||
// 设置回调超时时间
|
// 设置回调超时时间
|
||||||
requestHeaders.set(RequestInterceptor.TIMEOUT_TIME, CALLBACK_TIMEOUT);
|
requestHeaders.set(RequestInterceptor.TIMEOUT_TIME, CALLBACK_TIMEOUT);
|
||||||
@ -101,7 +100,7 @@ public class CallbackWorkflowExecutor extends AbstractWorkflowExecutor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, String> uriVariables = new HashMap<>();
|
Map<String, String> uriVariables = new HashMap<>();
|
||||||
uriVariables.put(SECRET, decisionConfig.getSecret());
|
uriVariables.put(SystemConstants.SECRET, decisionConfig.getSecret());
|
||||||
|
|
||||||
ResponseEntity<String> response = buildRetryer(decisionConfig).call(
|
ResponseEntity<String> response = buildRetryer(decisionConfig).call(
|
||||||
() -> restTemplate.exchange(decisionConfig.getWebhook(), HttpMethod.POST,
|
() -> restTemplate.exchange(decisionConfig.getWebhook(), HttpMethod.POST,
|
||||||
|
Loading…
Reference in New Issue
Block a user