|
|
@ -2,6 +2,7 @@ package com.xxl.job.executor.service.jobhandler;
|
|
|
|
|
|
|
|
|
|
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
|
|
|
|
|
import com.xxl.job.core.util.GsonTool;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@ -13,6 +14,7 @@ import java.io.InputStreamReader;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -72,6 +74,8 @@ public class SampleXxlJob {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 3、命令行任务
|
|
|
|
* 3、命令行任务
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 参数示例:"ls -a" 或者 "pwd"
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@XxlJob("commandJobHandler")
|
|
|
|
@XxlJob("commandJobHandler")
|
|
|
|
public void commandJobHandler() throws Exception {
|
|
|
|
public void commandJobHandler() throws Exception {
|
|
|
@ -128,15 +132,20 @@ public class SampleXxlJob {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 4、跨平台Http任务
|
|
|
|
* 4、跨平台Http任务
|
|
|
|
|
|
|
|
*
|
|
|
|
* 参数示例:
|
|
|
|
* 参数示例:
|
|
|
|
* "url: http://www.baidu.com\n" +
|
|
|
|
* <pre>
|
|
|
|
* "method: get\n" +
|
|
|
|
* {
|
|
|
|
* "data: content\n";
|
|
|
|
* "url": "http://www.baidu.com",
|
|
|
|
|
|
|
|
* "method": "get",
|
|
|
|
|
|
|
|
* "data": "hello world"
|
|
|
|
|
|
|
|
* }
|
|
|
|
|
|
|
|
* </pre>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@XxlJob("httpJobHandler")
|
|
|
|
@XxlJob("httpJobHandler")
|
|
|
|
public void httpJobHandler() throws Exception {
|
|
|
|
public void httpJobHandler() throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
// param parse
|
|
|
|
// param
|
|
|
|
String param = XxlJobHelper.getJobParam();
|
|
|
|
String param = XxlJobHelper.getJobParam();
|
|
|
|
if (param==null || param.trim().length()==0) {
|
|
|
|
if (param==null || param.trim().length()==0) {
|
|
|
|
XxlJobHelper.log("param["+ param +"] invalid.");
|
|
|
|
XxlJobHelper.log("param["+ param +"] invalid.");
|
|
|
@ -145,20 +154,19 @@ public class SampleXxlJob {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String[] httpParams = param.split("\n");
|
|
|
|
// param parse
|
|
|
|
String url = null;
|
|
|
|
String url;
|
|
|
|
String method = null;
|
|
|
|
String method;
|
|
|
|
String data = null;
|
|
|
|
String data;
|
|
|
|
for (String httpParam: httpParams) {
|
|
|
|
try {
|
|
|
|
if (httpParam.startsWith("url:")) {
|
|
|
|
Map<String, String> paramMap =GsonTool.fromJson(param, Map.class);
|
|
|
|
url = httpParam.substring(httpParam.indexOf("url:") + 4).trim();
|
|
|
|
url = paramMap.get("url");
|
|
|
|
}
|
|
|
|
method = paramMap.get("method");
|
|
|
|
if (httpParam.startsWith("method:")) {
|
|
|
|
data = paramMap.get("data");
|
|
|
|
method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase();
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
XxlJobHelper.log(e);
|
|
|
|
if (httpParam.startsWith("data:")) {
|
|
|
|
XxlJobHelper.handleFail();
|
|
|
|
data = httpParam.substring(httpParam.indexOf("data:") + 5).trim();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// param valid
|
|
|
|
// param valid
|
|
|
|