Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
239200e5
提交
239200e5
authored
3月 28, 2020
作者:
xuxueli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
通用HTTP任务Handler(httpJobHandler)优化,扩展自定义参数信息,示例参数如下;
上级
ffcc82f2
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
285 行增加
和
38 行删除
+285
-38
XXL-JOB官方文档.md
doc/XXL-JOB官方文档.md
+19
-8
HttpJobHandler.java
.../executor/sample/frameless/jobhandler/HttpJobHandler.java
+42
-9
HttpJobHandler.java
...ueli/executor/sample/jboot/jobhandler/HttpJobHandler.java
+44
-5
HttpJobHandler.java
...eli/executor/sample/jfinal/jobhandler/HttpJobHandler.java
+44
-5
HttpJobHandler.java
...xueli/executor/sample/nutz/jobhandler/HttpJobHandler.java
+44
-5
SampleXxlJob.java
...com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
+46
-3
SampleXxlJob.java
...com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
+46
-3
没有找到文件。
doc/XXL-JOB官方文档.md
浏览文件 @
239200e5
...
@@ -766,7 +766,7 @@ public ReturnT<String> execute(String param) {
...
@@ -766,7 +766,7 @@ public ReturnT<String> execute(String param) {
-
demoJobHandler:简单示例任务,任务内部模拟耗时任务逻辑,用户可在线体验Rolling Log等功能;
-
demoJobHandler:简单示例任务,任务内部模拟耗时任务逻辑,用户可在线体验Rolling Log等功能;
-
shardingJobHandler:分片示例任务,任务内部模拟处理分片参数,可参考熟悉分片任务;
-
shardingJobHandler:分片示例任务,任务内部模拟处理分片参数,可参考熟悉分片任务;
-
httpJobHandler:通用HTTP任务Handler;业务方只需要提供HTTP链接即可,不限制语言、平台;
-
httpJobHandler:通用HTTP任务Handler;业务方只需要提供HTTP链接
等信息
即可,不限制语言、平台;
-
commandJobHandler:通用命令行任务Handler;业务方只需要提供命令行即可;如 “pwd”命令;
-
commandJobHandler:通用命令行任务Handler;业务方只需要提供命令行即可;如 “pwd”命令;
...
@@ -1261,7 +1261,12 @@ API服务请求参考代码:com.xxl.job.executor.ExecutorBizTest
...
@@ -1261,7 +1261,12 @@ API服务请求参考代码:com.xxl.job.executor.ExecutorBizTest
### 5.17 跨平台 & 跨语言
### 5.17 跨平台 & 跨语言
跨平台、跨语言主要体现在以下两个方面:
跨平台、跨语言主要体现在以下两个方面:
-
1、提供Java、Python、PHP……等十来种任务模式,可参考章节 “5.5 任务 "运行模式" ”;理论上可扩展任意语言任务模式;
-
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 任务失败告警
### 5.18 任务失败告警
默认提供邮件失败告警,可扩展短信、钉钉等方式。如果需要新增一种告警方式,只需要新增一个实现 "com.xxl.job.admin.core.alarm.JobAlarm" 接口的告警实现即可。可以参考默认提供邮箱告警实现 "EmailJobAlarm"。
默认提供邮件失败告警,可扩展短信、钉钉等方式。如果需要新增一种告警方式,只需要新增一个实现 "com.xxl.job.admin.core.alarm.JobAlarm" 接口的告警实现即可。可以参考默认提供邮箱告警实现 "EmailJobAlarm"。
...
@@ -1718,12 +1723,18 @@ public ReturnT<String> execute(String param) {
...
@@ -1718,12 +1723,18 @@ public ReturnT<String> execute(String param) {
- 11、修复bootstrap.min.css.map 404问题;
- 11、修复bootstrap.min.css.map 404问题;
- 12、XxlJob注解扫描方式优化,支持查找父类以及接口和基于类代理等常见情况;
- 12、XxlJob注解扫描方式优化,支持查找父类以及接口和基于类代理等常见情况;
- 13、执行器优雅停机优化,修复任务线程中断未join导致回调丢失的问题;
- 13、执行器优雅停机优化,修复任务线程中断未join导致回调丢失的问题;
-
14、
[
迭代中
]
自定义失败重试时间间隔;
- 14、通用HTTP任务Handler(httpJobHandler)优化,扩展自定义参数信息,示例参数如下;
-
15、
[
迭代中
]
任务复制功能;点击复制是弹出新建任务弹框,并初始化被复制任务信息;
```
-
16、
[
迭代中
]
新增执行器描述、任务描述属性;
url: http://www.xxx.com
-
17、
[
迭代中
]
任务执行一次的时候指定IP;
method: get 或 post
-
18、
[
迭代中
]
任务日志支持单个清理和状态转移,方便触发子任务;
data: post-data
-
19、
[
迭代中
]
任务结果丢失处理:针对长期处于运行中的任务(设置过期时间时,运行超过"过期时间+1min";未设置超时时间时,运行超过"30min"),主动检测该执行器是否在线,如果不在线主动标记失败;
```
-
15、
[
迭代中
]
自定义失败重试时间间隔;
-
16、
[
迭代中
]
任务复制功能;点击复制是弹出新建任务弹框,并初始化被复制任务信息;
-
17、
[
迭代中
]
新增执行器描述、任务描述属性;
-
18、
[
迭代中
]
任务执行一次的时候指定IP;
-
19、
[
迭代中
]
任务日志支持单个清理和状态转移,方便触发子任务;
-
20、
[
迭代中
]
任务结果丢失处理:针对长期处于运行中的任务(设置过期时间时,运行超过"过期时间+1min";未设置超时时间时,运行超过"30min"),主动检测该执行器是否在线,如果不在线主动标记失败;
### TODO LIST
### TODO LIST
...
...
xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xuxueli/executor/sample/frameless/jobhandler/HttpJobHandler.java
浏览文件 @
239200e5
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
import
com.xxl.job.core.log.XxlJobLogger
;
import
com.xxl.job.core.log.XxlJobLogger
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Arrays
;
/**
/**
* 跨平台Http任务
* 跨平台Http任务
...
@@ -19,10 +21,35 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -19,10 +21,35 @@ public class HttpJobHandler extends IJobHandler {
@Override
@Override
public
ReturnT
<
String
>
execute
(
String
param
)
throws
Exception
{
public
ReturnT
<
String
>
execute
(
String
param
)
throws
Exception
{
//
valid
//
param parse
if
(
param
==
null
||
param
.
trim
().
length
()==
0
)
{
if
(
param
==
null
||
param
.
trim
().
length
()==
0
)
{
XxlJobLogger
.
log
(
"URL Empty"
);
XxlJobLogger
.
log
(
"param["
+
param
+
"] invalid."
);
return
FAIL
;
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
// request
...
@@ -30,11 +57,11 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -30,11 +57,11 @@ public class HttpJobHandler extends IJobHandler {
BufferedReader
bufferedReader
=
null
;
BufferedReader
bufferedReader
=
null
;
try
{
try
{
// connection
// connection
URL
realUrl
=
new
URL
(
param
);
URL
realUrl
=
new
URL
(
url
);
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
// connection setting
// connection setting
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
method
);
connection
.
setDoOutput
(
true
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setUseCaches
(
false
);
...
@@ -47,12 +74,18 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -47,12 +74,18 @@ public class HttpJobHandler extends IJobHandler {
// do connection
// do connection
connection
.
connect
();
connection
.
connect
();
//Map<String, List<String>> 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
// valid StatusCode
int
statusCode
=
connection
.
getResponseCode
();
int
statusCode
=
connection
.
getResponseCode
();
if
(
statusCode
!=
200
)
{
if
(
statusCode
!=
200
)
{
throw
new
RuntimeException
(
"Http Request StatusCode("
+
statusCode
+
") Invalid."
);
throw
new
RuntimeException
(
"Http Request StatusCode("
+
statusCode
+
") Invalid."
);
}
}
// result
// result
...
@@ -65,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -65,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
String
responseMsg
=
result
.
toString
();
String
responseMsg
=
result
.
toString
();
XxlJobLogger
.
log
(
responseMsg
);
XxlJobLogger
.
log
(
responseMsg
);
return
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
XxlJobLogger
.
log
(
e
);
XxlJobLogger
.
log
(
e
);
return
FAIL
;
return
ReturnT
.
FAIL
;
}
finally
{
}
finally
{
try
{
try
{
if
(
bufferedReader
!=
null
)
{
if
(
bufferedReader
!=
null
)
{
...
...
xxl-job-executor-samples/xxl-job-executor-sample-jboot/src/main/java/com/xuxueli/executor/sample/jboot/jobhandler/HttpJobHandler.java
浏览文件 @
239200e5
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
import
com.xxl.job.core.log.XxlJobLogger
;
import
com.xxl.job.core.log.XxlJobLogger
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Arrays
;
/**
/**
* 跨平台Http任务
* 跨平台Http任务
...
@@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler {
@Override
@Override
public
ReturnT
<
String
>
execute
(
String
param
)
throws
Exception
{
public
ReturnT
<
String
>
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
// request
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
BufferedReader
bufferedReader
=
null
;
BufferedReader
bufferedReader
=
null
;
try
{
try
{
// connection
// connection
URL
realUrl
=
new
URL
(
param
);
URL
realUrl
=
new
URL
(
url
);
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
// connection setting
// connection setting
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
method
);
connection
.
setDoOutput
(
true
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setUseCaches
(
false
);
...
@@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler {
// do connection
// do connection
connection
.
connect
();
connection
.
connect
();
//Map<String, List<String>> 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
// valid StatusCode
int
statusCode
=
connection
.
getResponseCode
();
int
statusCode
=
connection
.
getResponseCode
();
...
@@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
String
responseMsg
=
result
.
toString
();
String
responseMsg
=
result
.
toString
();
XxlJobLogger
.
log
(
responseMsg
);
XxlJobLogger
.
log
(
responseMsg
);
return
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
XxlJobLogger
.
log
(
e
);
XxlJobLogger
.
log
(
e
);
return
FAIL
;
return
ReturnT
.
FAIL
;
}
finally
{
}
finally
{
try
{
try
{
if
(
bufferedReader
!=
null
)
{
if
(
bufferedReader
!=
null
)
{
...
...
xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java
浏览文件 @
239200e5
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
import
com.xxl.job.core.log.XxlJobLogger
;
import
com.xxl.job.core.log.XxlJobLogger
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Arrays
;
/**
/**
* 跨平台Http任务
* 跨平台Http任务
...
@@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler {
@Override
@Override
public
ReturnT
<
String
>
execute
(
String
param
)
throws
Exception
{
public
ReturnT
<
String
>
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
// request
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
BufferedReader
bufferedReader
=
null
;
BufferedReader
bufferedReader
=
null
;
try
{
try
{
// connection
// connection
URL
realUrl
=
new
URL
(
param
);
URL
realUrl
=
new
URL
(
url
);
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
// connection setting
// connection setting
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
method
);
connection
.
setDoOutput
(
true
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setUseCaches
(
false
);
...
@@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler {
// do connection
// do connection
connection
.
connect
();
connection
.
connect
();
//Map<String, List<String>> 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
// valid StatusCode
int
statusCode
=
connection
.
getResponseCode
();
int
statusCode
=
connection
.
getResponseCode
();
...
@@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
String
responseMsg
=
result
.
toString
();
String
responseMsg
=
result
.
toString
();
XxlJobLogger
.
log
(
responseMsg
);
XxlJobLogger
.
log
(
responseMsg
);
return
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
XxlJobLogger
.
log
(
e
);
XxlJobLogger
.
log
(
e
);
return
FAIL
;
return
ReturnT
.
FAIL
;
}
finally
{
}
finally
{
try
{
try
{
if
(
bufferedReader
!=
null
)
{
if
(
bufferedReader
!=
null
)
{
...
...
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java
浏览文件 @
239200e5
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
...
@@ -5,9 +5,11 @@ import com.xxl.job.core.handler.IJobHandler;
import
com.xxl.job.core.log.XxlJobLogger
;
import
com.xxl.job.core.log.XxlJobLogger
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Arrays
;
/**
/**
* 跨平台Http任务
* 跨平台Http任务
...
@@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -19,16 +21,47 @@ public class HttpJobHandler extends IJobHandler {
@Override
@Override
public
ReturnT
<
String
>
execute
(
String
param
)
throws
Exception
{
public
ReturnT
<
String
>
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
// request
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
BufferedReader
bufferedReader
=
null
;
BufferedReader
bufferedReader
=
null
;
try
{
try
{
// connection
// connection
URL
realUrl
=
new
URL
(
param
);
URL
realUrl
=
new
URL
(
url
);
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
// connection setting
// connection setting
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
method
);
connection
.
setDoOutput
(
true
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setUseCaches
(
false
);
...
@@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -41,7 +74,13 @@ public class HttpJobHandler extends IJobHandler {
// do connection
// do connection
connection
.
connect
();
connection
.
connect
();
//Map<String, List<String>> 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
// valid StatusCode
int
statusCode
=
connection
.
getResponseCode
();
int
statusCode
=
connection
.
getResponseCode
();
...
@@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
...
@@ -59,10 +98,10 @@ public class HttpJobHandler extends IJobHandler {
String
responseMsg
=
result
.
toString
();
String
responseMsg
=
result
.
toString
();
XxlJobLogger
.
log
(
responseMsg
);
XxlJobLogger
.
log
(
responseMsg
);
return
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
XxlJobLogger
.
log
(
e
);
XxlJobLogger
.
log
(
e
);
return
FAIL
;
return
ReturnT
.
FAIL
;
}
finally
{
}
finally
{
try
{
try
{
if
(
bufferedReader
!=
null
)
{
if
(
bufferedReader
!=
null
)
{
...
...
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
浏览文件 @
239200e5
...
@@ -11,9 +11,11 @@ import org.springframework.stereotype.Component;
...
@@ -11,9 +11,11 @@ import org.springframework.stereotype.Component;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.InputStreamReader
;
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.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -111,20 +113,55 @@ public class SampleXxlJob {
...
@@ -111,20 +113,55 @@ public class SampleXxlJob {
/**
/**
* 4、跨平台Http任务
* 4、跨平台Http任务
* 参数示例:
* "url: http://www.baidu.com\n" +
* "method: get\n" +
* "data: content\n";
*/
*/
@XxlJob
(
"httpJobHandler"
)
@XxlJob
(
"httpJobHandler"
)
public
ReturnT
<
String
>
httpJobHandler
(
String
param
)
throws
Exception
{
public
ReturnT
<
String
>
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
// request
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
BufferedReader
bufferedReader
=
null
;
BufferedReader
bufferedReader
=
null
;
try
{
try
{
// connection
// connection
URL
realUrl
=
new
URL
(
param
);
URL
realUrl
=
new
URL
(
url
);
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
// connection setting
// connection setting
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
method
);
connection
.
setDoOutput
(
true
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setUseCaches
(
false
);
...
@@ -137,7 +174,13 @@ public class SampleXxlJob {
...
@@ -137,7 +174,13 @@ public class SampleXxlJob {
// do connection
// do connection
connection
.
connect
();
connection
.
connect
();
//Map<String, List<String>> 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
// valid StatusCode
int
statusCode
=
connection
.
getResponseCode
();
int
statusCode
=
connection
.
getResponseCode
();
...
...
xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
浏览文件 @
239200e5
...
@@ -11,9 +11,11 @@ import org.springframework.stereotype.Component;
...
@@ -11,9 +11,11 @@ import org.springframework.stereotype.Component;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.InputStreamReader
;
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.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -111,20 +113,55 @@ public class SampleXxlJob {
...
@@ -111,20 +113,55 @@ public class SampleXxlJob {
/**
/**
* 4、跨平台Http任务
* 4、跨平台Http任务
* 参数示例:
* "url: http://www.baidu.com\n" +
* "method: get\n" +
* "data: content\n";
*/
*/
@XxlJob
(
"httpJobHandler"
)
@XxlJob
(
"httpJobHandler"
)
public
ReturnT
<
String
>
httpJobHandler
(
String
param
)
throws
Exception
{
public
ReturnT
<
String
>
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
// request
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
BufferedReader
bufferedReader
=
null
;
BufferedReader
bufferedReader
=
null
;
try
{
try
{
// connection
// connection
URL
realUrl
=
new
URL
(
param
);
URL
realUrl
=
new
URL
(
url
);
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
// connection setting
// connection setting
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
method
);
connection
.
setDoOutput
(
true
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setUseCaches
(
false
);
...
@@ -137,7 +174,13 @@ public class SampleXxlJob {
...
@@ -137,7 +174,13 @@ public class SampleXxlJob {
// do connection
// do connection
connection
.
connect
();
connection
.
connect
();
//Map<String, List<String>> 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
// valid StatusCode
int
statusCode
=
connection
.
getResponseCode
();
int
statusCode
=
connection
.
getResponseCode
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论