From b6880474c3e6564ed47beccfe5658cf696efa7c2 Mon Sep 17 00:00:00 2001 From: liuyuefeng Date: Mon, 18 Dec 2023 10:47:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/java3y/austin/support/utils/ContentHolderUtil.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/ContentHolderUtil.java b/austin-support/src/main/java/com/java3y/austin/support/utils/ContentHolderUtil.java index 56c4698..c1b8cd3 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/ContentHolderUtil.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/ContentHolderUtil.java @@ -5,6 +5,7 @@ import org.springframework.util.PropertyPlaceholderHelper; import java.text.MessageFormat; import java.util.Map; +import java.util.Objects; /** * @author 3y @@ -43,6 +44,10 @@ public class ContentHolderUtil { @Override public String resolvePlaceholder(String placeholderName) { + if (Objects.isNull(paramMap)) { + String errorStr = MessageFormat.format("template:{0} require param:{1},but not exist! paramMap:{2}", template, placeholderName, paramMap); + throw new IllegalArgumentException(errorStr); + } String value = paramMap.get(placeholderName); if (StringUtils.isEmpty(value)) { String errorStr = MessageFormat.format("template:{0} require param:{1},but not exist! paramMap:{2}", template, placeholderName, paramMap); From 847d74b324592387bf6ff1b6b144a949f2a738e5 Mon Sep 17 00:00:00 2001 From: leesin9527 <2269196662@qq.com> Date: Mon, 25 Dec 2023 20:17:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BB=99xxl-job=E7=9A=84cookie=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cron/xxl/constants/XxlJobConstant.java | 4 +++ .../xxl/service/impl/CronTaskServiceImpl.java | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/constants/XxlJobConstant.java b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/constants/XxlJobConstant.java index 4ca8c1c..eda127f 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/constants/XxlJobConstant.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/constants/XxlJobConstant.java @@ -37,6 +37,10 @@ public class XxlJobConstant { * 立即执行的任务 延迟时间(秒数) */ public static final Integer DELAY_TIME = 10; + /** + * 请求 xxl-job-admin 需要用到的 cookie + */ + public static final String COOKIE_PREFIX = "xxl_job_cookie_"; private XxlJobConstant() { } diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java index fef0aa8..8c9fc6d 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/service/impl/CronTaskServiceImpl.java @@ -2,6 +2,7 @@ package com.java3y.austin.cron.xxl.service.impl; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; @@ -14,7 +15,9 @@ import com.java3y.austin.cron.xxl.entity.XxlJobInfo; import com.java3y.austin.cron.xxl.service.CronTaskService; import com.xxl.job.core.biz.model.ReturnT; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.net.HttpCookie; @@ -39,6 +42,9 @@ public class CronTaskServiceImpl implements CronTaskService { @Value("${xxl.job.admin.addresses}") private String xxlAddresses; + @Autowired + private StringRedisTemplate redisTemplate; + @Override public BasicResultVO saveCronTask(XxlJobInfo xxlJobInfo) { @@ -65,6 +71,7 @@ public class CronTaskServiceImpl implements CronTaskService { log.error("CronTaskService#saveTask fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e) , JSON.toJSONString(xxlJobInfo), JSON.toJSONString(returnT)); } + invalidateCookie(); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(returnT)); } @@ -87,6 +94,7 @@ public class CronTaskServiceImpl implements CronTaskService { log.error("CronTaskService#deleteCronTask fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e) , JSON.toJSONString(params), JSON.toJSONString(returnT)); } + invalidateCookie(); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(returnT)); } @@ -109,6 +117,7 @@ public class CronTaskServiceImpl implements CronTaskService { log.error("CronTaskService#startCronTask fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e) , JSON.toJSONString(params), JSON.toJSONString(returnT)); } + invalidateCookie(); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(returnT)); } @@ -131,6 +140,7 @@ public class CronTaskServiceImpl implements CronTaskService { log.error("CronTaskService#stopCronTask fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e) , JSON.toJSONString(params), JSON.toJSONString(returnT)); } + invalidateCookie(); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(returnT)); } @@ -156,6 +166,7 @@ public class CronTaskServiceImpl implements CronTaskService { log.error("CronTaskService#getGroupId fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e) , JSON.toJSONString(params), JSON.toJSONString(response.body())); } + invalidateCookie(); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(response.body())); } @@ -177,6 +188,7 @@ public class CronTaskServiceImpl implements CronTaskService { log.error("CronTaskService#createGroup fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e) , JSON.toJSONString(params), JSON.toJSONString(returnT)); } + invalidateCookie(); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(returnT)); } @@ -186,6 +198,11 @@ public class CronTaskServiceImpl implements CronTaskService { * @return String */ private String getCookie() { + String cachedCookie = redisTemplate.opsForValue().get(XxlJobConstant.COOKIE_PREFIX + xxlUserName); + if (StrUtil.isNotBlank(cachedCookie)) { + return cachedCookie; + } + Map params = MapUtil.newHashMap(); params.put("userName", xxlUserName); params.put("password", xxlPassword); @@ -201,6 +218,7 @@ public class CronTaskServiceImpl implements CronTaskService { for (HttpCookie cookie : cookies) { sb.append(cookie.toString()); } + redisTemplate.opsForValue().set(XxlJobConstant.COOKIE_PREFIX + xxlUserName, sb.toString()); return sb.toString(); } } catch (Exception e) { @@ -209,4 +227,11 @@ public class CronTaskServiceImpl implements CronTaskService { } return null; } + + /** + * 清除缓存的 cookie + */ + private void invalidateCookie() { + redisTemplate.delete(XxlJobConstant.COOKIE_PREFIX + xxlUserName); + } }