From 239200e52c5e5b69c559fd6c485a26d5c97b9d6d Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sun, 29 Mar 2020 02:35:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=94=A8HTTP=E4=BB=BB=E5=8A=A1Handler?= =?UTF-8?q?=EF=BC=88httpJobHandler=EF=BC=89=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=A4=BA=E4=BE=8B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=A6=82=E4=B8=8B=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 27 +++++++--- .../frameless/jobhandler/HttpJobHandler.java | 51 +++++++++++++++---- .../jboot/jobhandler/HttpJobHandler.java | 49 ++++++++++++++++-- .../jfinal/jobhandler/HttpJobHandler.java | 49 ++++++++++++++++-- .../nutz/jobhandler/HttpJobHandler.java | 49 ++++++++++++++++-- .../service/jobhandler/SampleXxlJob.java | 49 ++++++++++++++++-- .../service/jobhandler/SampleXxlJob.java | 49 ++++++++++++++++-- 7 files changed, 285 insertions(+), 38 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index f6d58099..7b5177ce 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -766,7 +766,7 @@ public ReturnT execute(String param) { - demoJobHandler:简单示例任务,任务内部模拟耗时任务逻辑,用户可在线体验Rolling Log等功能; - shardingJobHandler:分片示例任务,任务内部模拟处理分片参数,可参考熟悉分片任务; -- httpJobHandler:通用HTTP任务Handler;业务方只需要提供HTTP链接即可,不限制语言、平台; +- httpJobHandler:通用HTTP任务Handler;业务方只需要提供HTTP链接等信息即可,不限制语言、平台; - commandJobHandler:通用命令行任务Handler;业务方只需要提供命令行即可;如 “pwd”命令; @@ -1261,7 +1261,12 @@ API服务请求参考代码:com.xxl.job.executor.ExecutorBizTest ### 5.17 跨平台 & 跨语言 跨平台、跨语言主要体现在以下两个方面: - 1、提供Java、Python、PHP……等十来种任务模式,可参考章节 “5.5 任务 "运行模式" ”;理论上可扩展任意语言任务模式; -- 2、提供基于HTTP的任务Handler(Bean任务,JobHandler="HttpJobHandler");业务方只需要提供HTTP链接即可,不限制语言、平台; +- 2、提供基于HTTP的任务Handler(Bean任务,JobHandler="httpJobHandler");业务方只需要提供HTTP链接等相关信息即可,不限制语言、平台; +``` +url: http://www.xxx.com +method: get 或 post +data: post-data +``` ### 5.18 任务失败告警 默认提供邮件失败告警,可扩展短信、钉钉等方式。如果需要新增一种告警方式,只需要新增一个实现 "com.xxl.job.admin.core.alarm.JobAlarm" 接口的告警实现即可。可以参考默认提供邮箱告警实现 "EmailJobAlarm"。 @@ -1718,12 +1723,18 @@ public ReturnT execute(String param) { - 11、修复bootstrap.min.css.map 404问题; - 12、XxlJob注解扫描方式优化,支持查找父类以及接口和基于类代理等常见情况; - 13、执行器优雅停机优化,修复任务线程中断未join导致回调丢失的问题; -- 14、[迭代中]自定义失败重试时间间隔; -- 15、[迭代中]任务复制功能;点击复制是弹出新建任务弹框,并初始化被复制任务信息; -- 16、[迭代中]新增执行器描述、任务描述属性; -- 17、[迭代中]任务执行一次的时候指定IP; -- 18、[迭代中]任务日志支持单个清理和状态转移,方便触发子任务; -- 19、[迭代中]任务结果丢失处理:针对长期处于运行中的任务(设置过期时间时,运行超过"过期时间+1min";未设置超时时间时,运行超过"30min"),主动检测该执行器是否在线,如果不在线主动标记失败; +- 14、通用HTTP任务Handler(httpJobHandler)优化,扩展自定义参数信息,示例参数如下; +``` +url: http://www.xxx.com +method: get 或 post +data: post-data +``` +- 15、[迭代中]自定义失败重试时间间隔; +- 16、[迭代中]任务复制功能;点击复制是弹出新建任务弹框,并初始化被复制任务信息; +- 17、[迭代中]新增执行器描述、任务描述属性; +- 18、[迭代中]任务执行一次的时候指定IP; +- 19、[迭代中]任务日志支持单个清理和状态转移,方便触发子任务; +- 20、[迭代中]任务结果丢失处理:针对长期处于运行中的任务(设置过期时间时,运行超过"过期时间+1min";未设置超时时间时,运行超过"30min"),主动检测该执行器是否在线,如果不在线主动标记失败; ### TODO LIST diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xuxueli/executor/sample/frameless/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xuxueli/executor/sample/frameless/jobhandler/HttpJobHandler.java index a8748a88..eeb8e3cd 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xuxueli/executor/sample/frameless/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xuxueli/executor/sample/frameless/jobhandler/HttpJobHandler.java @@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.log.XxlJobLogger; import java.io.BufferedReader; +import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Arrays; /** * 跨平台Http任务 @@ -19,10 +21,35 @@ public class HttpJobHandler extends IJobHandler { @Override public ReturnT execute(String param) throws Exception { - // valid + // param parse if (param==null || param.trim().length()==0) { - XxlJobLogger.log("URL Empty"); - return FAIL; + XxlJobLogger.log("param["+ param +"] invalid."); + return ReturnT.FAIL; + } + 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 valid + if (url==null || url.trim().length()==0) { + XxlJobLogger.log("url["+ url +"] invalid."); + return ReturnT.FAIL; + } + if (method==null || !Arrays.asList("GET", "POST").contains(method)) { + XxlJobLogger.log("method["+ method +"] invalid."); + return ReturnT.FAIL; } // request @@ -30,11 +57,11 @@ public class HttpJobHandler extends IJobHandler { BufferedReader bufferedReader = null; try { // connection - URL realUrl = new URL(param); + URL realUrl = new URL(url); connection = (HttpURLConnection) realUrl.openConnection(); // connection setting - connection.setRequestMethod("GET"); + connection.setRequestMethod(method); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); @@ -47,12 +74,18 @@ public class HttpJobHandler extends IJobHandler { // do connection connection.connect(); - //Map> map = connection.getHeaderFields(); + // data + if (data!=null && data.trim().length()>0) { + DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); + dataOutputStream.write(data.getBytes("UTF-8")); + dataOutputStream.flush(); + dataOutputStream.close(); + } // valid StatusCode int statusCode = connection.getResponseCode(); if (statusCode != 200) { - throw new RuntimeException("Http Request StatusCode("+ statusCode +") Invalid."); + throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid."); } // result @@ -65,10 +98,10 @@ public class HttpJobHandler extends IJobHandler { String responseMsg = result.toString(); XxlJobLogger.log(responseMsg); - return SUCCESS; + return ReturnT.SUCCESS; } catch (Exception e) { XxlJobLogger.log(e); - return FAIL; + return ReturnT.FAIL; } finally { try { if (bufferedReader != null) { diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java index 2796ecd7..08a5d015 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java @@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.log.XxlJobLogger; import java.io.BufferedReader; +import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Arrays; /** * 跨平台Http任务 @@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler { @Override public ReturnT execute(String param) throws Exception { + // param parse + if (param==null || param.trim().length()==0) { + XxlJobLogger.log("param["+ param +"] invalid."); + return ReturnT.FAIL; + } + 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 valid + if (url==null || url.trim().length()==0) { + XxlJobLogger.log("url["+ url +"] invalid."); + return ReturnT.FAIL; + } + if (method==null || !Arrays.asList("GET", "POST").contains(method)) { + XxlJobLogger.log("method["+ method +"] invalid."); + return ReturnT.FAIL; + } + // request HttpURLConnection connection = null; BufferedReader bufferedReader = null; try { // connection - URL realUrl = new URL(param); + URL realUrl = new URL(url); connection = (HttpURLConnection) realUrl.openConnection(); // connection setting - connection.setRequestMethod("GET"); + connection.setRequestMethod(method); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); @@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler { // do connection connection.connect(); - //Map> map = connection.getHeaderFields(); + // data + if (data!=null && data.trim().length()>0) { + DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); + dataOutputStream.write(data.getBytes("UTF-8")); + dataOutputStream.flush(); + dataOutputStream.close(); + } // valid StatusCode int statusCode = connection.getResponseCode(); @@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler { String responseMsg = result.toString(); XxlJobLogger.log(responseMsg); - return SUCCESS; + return ReturnT.SUCCESS; } catch (Exception e) { XxlJobLogger.log(e); - return FAIL; + return ReturnT.FAIL; } finally { try { if (bufferedReader != null) { diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java index b8b61f9e..414d8e25 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java @@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.log.XxlJobLogger; import java.io.BufferedReader; +import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Arrays; /** * 跨平台Http任务 @@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler { @Override public ReturnT execute(String param) throws Exception { + // param parse + if (param==null || param.trim().length()==0) { + XxlJobLogger.log("param["+ param +"] invalid."); + return ReturnT.FAIL; + } + 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 valid + if (url==null || url.trim().length()==0) { + XxlJobLogger.log("url["+ url +"] invalid."); + return ReturnT.FAIL; + } + if (method==null || !Arrays.asList("GET", "POST").contains(method)) { + XxlJobLogger.log("method["+ method +"] invalid."); + return ReturnT.FAIL; + } + // request HttpURLConnection connection = null; BufferedReader bufferedReader = null; try { // connection - URL realUrl = new URL(param); + URL realUrl = new URL(url); connection = (HttpURLConnection) realUrl.openConnection(); // connection setting - connection.setRequestMethod("GET"); + connection.setRequestMethod(method); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); @@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler { // do connection connection.connect(); - //Map> map = connection.getHeaderFields(); + // data + if (data!=null && data.trim().length()>0) { + DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); + dataOutputStream.write(data.getBytes("UTF-8")); + dataOutputStream.flush(); + dataOutputStream.close(); + } // valid StatusCode int statusCode = connection.getResponseCode(); @@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler { String responseMsg = result.toString(); XxlJobLogger.log(responseMsg); - return SUCCESS; + return ReturnT.SUCCESS; } catch (Exception e) { XxlJobLogger.log(e); - return FAIL; + return ReturnT.FAIL; } finally { try { if (bufferedReader != null) { diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java index 895afccc..c09dd590 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java @@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.log.XxlJobLogger; import java.io.BufferedReader; +import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Arrays; /** * 跨平台Http任务 @@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler { @Override public ReturnT execute(String param) throws Exception { + // param parse + if (param==null || param.trim().length()==0) { + XxlJobLogger.log("param["+ param +"] invalid."); + return ReturnT.FAIL; + } + 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 valid + if (url==null || url.trim().length()==0) { + XxlJobLogger.log("url["+ url +"] invalid."); + return ReturnT.FAIL; + } + if (method==null || !Arrays.asList("GET", "POST").contains(method)) { + XxlJobLogger.log("method["+ method +"] invalid."); + return ReturnT.FAIL; + } + // request HttpURLConnection connection = null; BufferedReader bufferedReader = null; try { // connection - URL realUrl = new URL(param); + URL realUrl = new URL(url); connection = (HttpURLConnection) realUrl.openConnection(); // connection setting - connection.setRequestMethod("GET"); + connection.setRequestMethod(method); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); @@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler { // do connection connection.connect(); - //Map> map = connection.getHeaderFields(); + // data + if (data!=null && data.trim().length()>0) { + DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); + dataOutputStream.write(data.getBytes("UTF-8")); + dataOutputStream.flush(); + dataOutputStream.close(); + } // valid StatusCode int statusCode = connection.getResponseCode(); @@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler { String responseMsg = result.toString(); XxlJobLogger.log(responseMsg); - return SUCCESS; + return ReturnT.SUCCESS; } catch (Exception e) { XxlJobLogger.log(e); - return FAIL; + return ReturnT.FAIL; } finally { try { if (bufferedReader != null) { diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java index f87b7773..bde06693 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java @@ -11,9 +11,11 @@ import org.springframework.stereotype.Component; import java.io.BufferedInputStream; import java.io.BufferedReader; +import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Arrays; import java.util.concurrent.TimeUnit; /** @@ -111,20 +113,55 @@ public class SampleXxlJob { /** * 4、跨平台Http任务 + * 参数示例: + * "url: http://www.baidu.com\n" + + * "method: get\n" + + * "data: content\n"; */ @XxlJob("httpJobHandler") public ReturnT httpJobHandler(String param) throws Exception { + // param parse + if (param==null || param.trim().length()==0) { + XxlJobLogger.log("param["+ param +"] invalid."); + return ReturnT.FAIL; + } + 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 valid + if (url==null || url.trim().length()==0) { + XxlJobLogger.log("url["+ url +"] invalid."); + return ReturnT.FAIL; + } + if (method==null || !Arrays.asList("GET", "POST").contains(method)) { + XxlJobLogger.log("method["+ method +"] invalid."); + return ReturnT.FAIL; + } + // request HttpURLConnection connection = null; BufferedReader bufferedReader = null; try { // connection - URL realUrl = new URL(param); + URL realUrl = new URL(url); connection = (HttpURLConnection) realUrl.openConnection(); // connection setting - connection.setRequestMethod("GET"); + connection.setRequestMethod(method); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); @@ -137,7 +174,13 @@ public class SampleXxlJob { // do connection connection.connect(); - //Map> map = connection.getHeaderFields(); + // data + if (data!=null && data.trim().length()>0) { + DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); + dataOutputStream.write(data.getBytes("UTF-8")); + dataOutputStream.flush(); + dataOutputStream.close(); + } // valid StatusCode int statusCode = connection.getResponseCode(); diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java index f87b7773..bde06693 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java @@ -11,9 +11,11 @@ import org.springframework.stereotype.Component; import java.io.BufferedInputStream; import java.io.BufferedReader; +import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Arrays; import java.util.concurrent.TimeUnit; /** @@ -111,20 +113,55 @@ public class SampleXxlJob { /** * 4、跨平台Http任务 + * 参数示例: + * "url: http://www.baidu.com\n" + + * "method: get\n" + + * "data: content\n"; */ @XxlJob("httpJobHandler") public ReturnT httpJobHandler(String param) throws Exception { + // param parse + if (param==null || param.trim().length()==0) { + XxlJobLogger.log("param["+ param +"] invalid."); + return ReturnT.FAIL; + } + 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 valid + if (url==null || url.trim().length()==0) { + XxlJobLogger.log("url["+ url +"] invalid."); + return ReturnT.FAIL; + } + if (method==null || !Arrays.asList("GET", "POST").contains(method)) { + XxlJobLogger.log("method["+ method +"] invalid."); + return ReturnT.FAIL; + } + // request HttpURLConnection connection = null; BufferedReader bufferedReader = null; try { // connection - URL realUrl = new URL(param); + URL realUrl = new URL(url); connection = (HttpURLConnection) realUrl.openConnection(); // connection setting - connection.setRequestMethod("GET"); + connection.setRequestMethod(method); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); @@ -137,7 +174,13 @@ public class SampleXxlJob { // do connection connection.connect(); - //Map> map = connection.getHeaderFields(); + // data + if (data!=null && data.trim().length()>0) { + DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); + dataOutputStream.write(data.getBytes("UTF-8")); + dataOutputStream.flush(); + dataOutputStream.close(); + } // valid StatusCode int statusCode = connection.getResponseCode();