diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 9d28f93c..3343b795 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1173,9 +1173,11 @@ public void demoJobHandler() throws Exception { - shardingJobHandler:分片示例任务,任务内部模拟处理分片参数,可参考熟悉分片任务; - httpJobHandler:通用HTTP任务Handler;业务方只需要提供HTTP链接等信息即可,不限制语言、平台。示例任务入参如下: ``` -url: http://www.xxx.com -method: get 或 post -data: post-data +{ + "url": "http://www.baidu.com", + "method": "get", + "data": "hello world" +} ``` - commandJobHandler:通用命令行任务Handler;业务方只需要提供命令行即可,命令及参数之间通过空格隔开;如任务参数 "ls la" 或 "pwd" 将会执行命令并输出数据; @@ -2442,8 +2444,16 @@ public void execute() { - 1、【升级】调度中心升级至 SpringBoot3 + JDK17; - 2、【升级】Docker镜像升级,镜像构建基于JDK17(openjdk:17-jdk-slim); - 3、【优化】IP获取逻辑优化,优先遍历网卡来获取可用IP; -- 4、【优化】通用命令行任务(“commandJobHandler”)优化,支持多参数执行,命令及参数之间通过空格隔开,如任务参数 "ls la" 或 "pwd" 将会执行命令并输出数据; -- 5、[规划中]登陆态Token生成逻辑优化,混淆登陆时间属性,降低token泄漏风险; +- 4、【优化】通用命令行任务(“commandJobHandler”)优化,支持多参数执行,命令及参数之间通过空格隔开;如任务参数 "ls la" 或 "pwd" 将会执行命令并输出数据; +- 5、【优化】通用HTTP任务(httpJobHandler)优化,任务参数格式调整为json格式;示例参数如下: +``` +{ + "url": "http://www.baidu.com", + "method": "get", + "data": "hello world" +} +``` +- 6、[规划中]登陆态Token生成逻辑优化,混淆登陆时间属性,降低token泄漏风险; ### TODO LIST - 1、调度隔离:调度中心针对不同执行器,各自维护不同的调度和远程触发组件。 diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xxl/job/executor/sample/frameless/jobhandler/SampleXxlJob.java b/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xxl/job/executor/sample/frameless/jobhandler/SampleXxlJob.java index 49e54f6e..27bb4001 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xxl/job/executor/sample/frameless/jobhandler/SampleXxlJob.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xxl/job/executor/sample/frameless/jobhandler/SampleXxlJob.java @@ -2,6 +2,7 @@ package com.xxl.job.executor.sample.frameless.jobhandler; import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.handler.annotation.XxlJob; +import com.xxl.job.core.util.GsonTool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,6 +13,7 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.Arrays; +import java.util.Map; import java.util.concurrent.TimeUnit; /** @@ -70,6 +72,8 @@ public class SampleXxlJob { /** * 3、命令行任务 + * + * 参数示例:"ls -a" 或者 "pwd" */ @XxlJob("commandJobHandler") public void commandJobHandler() throws Exception { @@ -126,15 +130,20 @@ public class SampleXxlJob { /** * 4、跨平台Http任务 + * * 参数示例: - * "url: http://www.baidu.com\n" + - * "method: get\n" + - * "data: content\n"; + *
+ * { + * "url": "http://www.baidu.com", + * "method": "get", + * "data": "hello world" + * } + **/ @XxlJob("httpJobHandler") public void httpJobHandler() throws Exception { - // param parse + // param String param = XxlJobHelper.getJobParam(); if (param==null || param.trim().length()==0) { XxlJobHelper.log("param["+ param +"] invalid."); @@ -143,20 +152,19 @@ public class SampleXxlJob { return; } - String[] httpParams = param.split("\n"); - String url = null; - String method = null; - String data = null; - for (String httpParam: httpParams) { - if (httpParam.startsWith("url:")) { - url = httpParam.substring(httpParam.indexOf("url:") + 4).trim(); - } - if (httpParam.startsWith("method:")) { - method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase(); - } - if (httpParam.startsWith("data:")) { - data = httpParam.substring(httpParam.indexOf("data:") + 5).trim(); - } + // param parse + String url; + String method; + String data; + try { + Map
+ * { + * "url": "http://www.baidu.com", + * "method": "get", + * "data": "hello world" + * } + **/ @XxlJob("httpJobHandler") public void httpJobHandler() throws Exception { - // param parse + // param String param = XxlJobHelper.getJobParam(); if (param==null || param.trim().length()==0) { XxlJobHelper.log("param["+ param +"] invalid."); @@ -145,20 +154,19 @@ public class SampleXxlJob { return; } - String[] httpParams = param.split("\n"); - String url = null; - String method = null; - String data = null; - for (String httpParam: httpParams) { - if (httpParam.startsWith("url:")) { - url = httpParam.substring(httpParam.indexOf("url:") + 4).trim(); - } - if (httpParam.startsWith("method:")) { - method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase(); - } - if (httpParam.startsWith("data:")) { - data = httpParam.substring(httpParam.indexOf("data:") + 5).trim(); - } + // param parse + String url; + String method; + String data; + try { + Map