Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
081f4c52
Commit
081f4c52
authored
Aug 17, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决token 异常BUG
parent
e0ee325b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
47 deletions
+22
-47
JobUtils.java
...xecutor-plugin/src/main/java/com/byit/utils/JobUtils.java
+22
-47
No files found.
byit-myth-executor/myth-executor-plugin/src/main/java/com/byit/utils/JobUtils.java
View file @
081f4c52
...
...
@@ -6,13 +6,10 @@ import com.byit.dto.api.JavaCallbackLogDto;
import
com.byit.dto.executor.PluginBeanJobInfo
;
import
com.byit.dto.plugin.*
;
import
com.byit.dto.web.ResponseResult
;
import
com.byit.dto.web.ReturnResult
;
import
com.byit.executor.handler.interfaces.IJobHandler
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -27,9 +24,14 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
* @date: 2019/11/18 12:30
**/
@Slf4j
@SuppressWarnings
(
"all"
)
public
class
JobUtils
{
private
static
String
REQUEST_URL
;
private
static
String
TOKEN
;
/**
* 存储token
*/
private
static
final
ThreadLocal
<
String
>
TOKEN_THREADLOCAL
=
new
ThreadLocal
<
String
>();
private
static
final
String
REQUEST_ADD_JOB_RESOURCES_SUFFIX
=
"/job/addJob"
;
...
...
@@ -180,20 +182,30 @@ public class JobUtils {
REQUEST_URL
=
requestUrl
;
}
/**
* 存放token
* @param token
*/
public
static
void
setTOKEN
(
String
token
){
TOKEN
=
token
;
TOKEN
_THREADLOCAL
.
set
(
token
)
;
}
/**
* 构建http请求
* @param requestUrl
* @param body
* @return
*/
private
static
String
createHttpRequest
(
String
requestUrl
,
String
body
){
if
(
null
==
REQUEST_URL
||
REQUEST_URL
.
equals
(
""
)){
if
(
StringUtils
.
isBlank
(
REQUEST_URL
)){
throw
new
RuntimeException
(
"请求调度中心的地址尚未设置!"
);
}
if
(
null
==
TOKEN
||
TOKEN
.
equals
(
""
)){
String
token
=
TOKEN_THREADLOCAL
.
get
();
if
(
StringUtils
.
isBlank
(
token
)){
throw
new
RuntimeException
(
"请求的token尚未设置!"
);
}
HttpRequest
httpRequest
=
HttpRequest
.
post
(
REQUEST_URL
+
requestUrl
);
httpRequest
.
header
(
"token"
,
TOKEN
);
httpRequest
.
header
(
"token"
,
token
);
String
response
=
httpRequest
.
body
(
body
).
execute
().
body
();
return
response
;
}
...
...
@@ -236,16 +248,6 @@ public class JobUtils {
log
.
debug
(
"--------------------修改任务完成,添加结果为:{}------------------------"
,
httpRequest
);
return
JSON
.
parseObject
(
httpRequest
,
ResponseResult
.
class
);
}
public
static
void
main
(
String
[]
args
)
{
JobUtils
.
setTOKEN
(
"qqq"
);
JobUtils
.
setRequestUrl
(
"http://127.0.0.1:8998/myth-job-admin"
);
JavaCallbackLogDto
javaCallbackLogDto
=
new
JavaCallbackLogDto
();
javaCallbackLogDto
.
setLogId
(
"123"
);
javaCallbackLogDto
.
setReturnResult
(
ReturnResult
.
SUCCESS
);
JobUtils
.
javaUpdateStatusRunResult
(
javaCallbackLogDto
);
}
/**
* 发布一个工作流
* @param pluginPackage
...
...
@@ -256,7 +258,6 @@ public class JobUtils {
//发送请求 添加任务
String
response
=
createHttpRequest
(
REQUEST_FLOW_PUBLISH
,
"param="
+
JSON
.
toJSONString
(
pluginPackage
,
WriteClassName
));
//String addRequestResult = HttpUtil.post(requestUrl, JSON.toJSONString(pluginPackage, WriteClassName))
log
.
debug
(
"--------------------添加任务完成,添加结果为:{}------------------------"
,
response
);
return
JSON
.
parseObject
(
response
,
ResponseResult
.
class
);
}
...
...
@@ -722,29 +723,4 @@ public class JobUtils {
return
JSON
.
parseObject
(
response
,
ResponseResult
.
class
);
}
/**
* 判断当前的运行环境是什么 jar : table of Contents(目录)
* @return jar -->true 目录 -->false
*/
public
static
boolean
isJarRun
(){
boolean
flag
=
false
;
String
protocol
=
JobUtils
.
class
.
getResource
(
""
).
getProtocol
();
if
(
OPERATING_ENVIRONMENT_JAR
.
equals
(
protocol
)){
flag
=
true
;
}
else
if
(
OPERATING_ENVIRONMENT_FILE
.
equals
(
protocol
)){
flag
=
false
;
}
return
flag
;
}
public
static
String
filePath
(){
String
path
=
JobUtils
.
class
.
getProtectionDomain
().
getCodeSource
().
getLocation
().
getFile
();
try
{
path
=
URLDecoder
.
decode
(
path
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
(
);
}
return
path
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment