Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
fuyue82
o2oa
提交
76656af1
o2oa
项目概览
fuyue82
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
76656af1
编写于
3月 01, 2019
作者:
R
roo00
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加invoke异步/同步调用功能.
上级
6530f1a6
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
490 addition
and
731 deletion
+490
-731
o2server/x_base_core_project/src/main/java/com/x/base/core/project/connection/HttpConnection.java
...va/com/x/base/core/project/connection/HttpConnection.java
+10
-10
o2server/x_base_core_project/src/main/java/com/x/base/core/project/scripting/ScriptingEngine.java
...va/com/x/base/core/project/scripting/ScriptingEngine.java
+19
-1
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ScriptHelperFactory.java
...ocessplatform/service/processing/ScriptHelperFactory.java
+1
-0
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ThisApplication.java
...x/processplatform/service/processing/ThisApplication.java
+7
-3
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/WebservicesClient.java
...processplatform/service/processing/WebservicesClient.java
+0
-41
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/ExecuteObject.java
...rm/service/processing/processor/invoke/ExecuteObject.java
+0
-33
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/InvokeExecutor.java
...m/service/processing/processor/invoke/InvokeExecutor.java
+45
-315
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/InvokeProcessor.java
.../service/processing/processor/invoke/InvokeProcessor.java
+299
-326
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/JaxrsObject.java
...form/service/processing/processor/invoke/JaxrsObject.java
+57
-0
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/JaxwsObject.java
...form/service/processing/processor/invoke/JaxwsObject.java
+37
-0
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/SyncJaxrsInvokeQueue.java
...ice/processing/processor/invoke/SyncJaxrsInvokeQueue.java
+2
-2
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/SyncJaxwsInvokeQueue.java
...ice/processing/processor/invoke/SyncJaxwsInvokeQueue.java
+13
-0
未找到文件。
o2server/x_base_core_project/src/main/java/com/x/base/core/project/connection/HttpConnection.java
浏览文件 @
76656af1
...
...
@@ -23,16 +23,16 @@ import com.x.base.core.project.tools.ListTools;
public
class
HttpConnection
{
p
rivate
static
String
Access_Control_Allow_Credentials
=
"Access-Control-Allow-Credentials"
;
p
rivate
static
String
Access_Control_Allow_Credentials_Value
=
"true"
;
p
rivate
static
String
Access_Control_Allow_Headers
=
"Access-Control-Allow-Headers"
;
p
rivate
static
String
Access_Control_Allow_Headers_Value
=
"x-requested-with, x-request, x-token,Content-Type, x-cipher"
;
p
rivate
static
String
Access_Control_Allow_Methods
=
"Access-Control-Allow-Methods"
;
p
rivate
static
String
Access_Control_Allow_Methods_Value
=
"GET, POST, OPTIONS, PUT, DELETE, HEAD, TRACE"
;
p
rivate
static
String
Cache_Control
=
"Cache-Control"
;
p
rivate
static
String
Cache_Control_Value
=
"no-cache, no-transform"
;
p
rivate
static
String
Content_Type
=
"Content-Type"
;
p
rivate
static
String
Content_Type_Value
=
"application/json;charset=UTF-8"
;
p
ublic
static
final
String
Access_Control_Allow_Credentials
=
"Access-Control-Allow-Credentials"
;
p
ublic
static
final
String
Access_Control_Allow_Credentials_Value
=
"true"
;
p
ublic
static
final
String
Access_Control_Allow_Headers
=
"Access-Control-Allow-Headers"
;
p
ublic
static
final
String
Access_Control_Allow_Headers_Value
=
"x-requested-with, x-request, x-token,Content-Type, x-cipher"
;
p
ublic
static
final
String
Access_Control_Allow_Methods
=
"Access-Control-Allow-Methods"
;
p
ublic
static
final
String
Access_Control_Allow_Methods_Value
=
"GET, POST, OPTIONS, PUT, DELETE, HEAD, TRACE"
;
p
ublic
static
final
String
Cache_Control
=
"Cache-Control"
;
p
ublic
static
final
String
Cache_Control_Value
=
"no-cache, no-transform"
;
p
ublic
static
final
String
Content_Type
=
"Content-Type"
;
p
ublic
static
final
String
Content_Type_Value
=
"application/json;charset=UTF-8"
;
public
static
String
getAsString
(
String
address
,
List
<
NameValuePair
>
heads
)
throws
Exception
{
HttpURLConnection
connection
=
prepare
(
address
,
heads
);
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/scripting/ScriptingEngine.java
浏览文件 @
76656af1
...
...
@@ -31,7 +31,10 @@ public class ScriptingEngine {
public
static
final
String
BINDINGNAME__LOOKUP
=
"lookup"
;
public
static
final
String
BINDINGNAME_APPLICATIONS
=
"applications"
;
public
static
final
String
BINDINGNAME_PARAMETER
=
"parameter"
;
public
static
final
String
BINDINGNAME_PARAMETERS
=
"parameters"
;
public
static
final
String
BINDINGNAME_EFFECTIVEPERSON
=
"effectivePerson"
;
public
static
final
String
BINDINGNAME_JAXRSRESPONSE
=
"jaxrsResponse"
;
public
static
final
String
BINDINGNAME_JAXWSRESPONSE
=
"jaxwsResponse"
;
public
ScriptingEngine
(
ScriptEngine
scriptEngine
)
{
this
.
scriptEngine
=
scriptEngine
;
...
...
@@ -84,11 +87,26 @@ public class ScriptingEngine {
return
this
;
}
public
ScriptingEngine
bindingJaxrsResponse
(
Object
o
)
{
this
.
scriptEngine
.
put
(
BINDINGNAME_JAXRSRESPONSE
,
o
);
return
this
;
}
public
ScriptingEngine
bindingJaxwsResponse
(
Object
o
)
{
this
.
scriptEngine
.
put
(
BINDINGNAME_JAXWSRESPONSE
,
o
);
return
this
;
}
public
ScriptingEngine
bindingParameter
(
Object
o
)
{
this
.
scriptEngine
.
put
(
BINDINGNAME_PARAMETER
,
o
);
return
this
;
}
public
ScriptingEngine
bindingParameters
(
Object
o
)
{
this
.
scriptEngine
.
put
(
BINDINGNAME_PARAMETERS
,
o
);
return
this
;
}
public
Object
eval
(
String
scriptText
)
throws
Exception
{
StringBuffer
sb
=
new
StringBuffer
();
try
{
...
...
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ScriptHelperFactory.java
浏览文件 @
76656af1
...
...
@@ -4,6 +4,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
com.x.base.core.project.gson.XGsonBuilder
;
import
com.x.base.core.project.webservices.WebservicesClient
;
import
com.x.organization.core.express.Organization
;
import
com.x.processplatform.core.entity.content.Data
;
import
com.x.processplatform.core.entity.content.Task
;
...
...
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ThisApplication.java
浏览文件 @
76656af1
...
...
@@ -8,7 +8,8 @@ import com.x.base.core.project.logger.LoggerFactory;
import
com.x.base.core.project.message.MessageConnector
;
import
com.x.collaboration.core.message.Collaboration
;
import
com.x.processplatform.service.processing.processor.embed.SyncEmbedQueue
;
import
com.x.processplatform.service.processing.processor.invoke.SyncInvokeQueue
;
import
com.x.processplatform.service.processing.processor.invoke.SyncJaxrsInvokeQueue
;
import
com.x.processplatform.service.processing.processor.invoke.SyncJaxwsInvokeQueue
;
import
com.x.processplatform.service.processing.schedule.Delay
;
import
com.x.processplatform.service.processing.schedule.Expire
;
import
com.x.processplatform.service.processing.schedule.Reorganize
;
...
...
@@ -18,7 +19,9 @@ public class ThisApplication {
protected
static
Context
context
;
public
static
SyncInvokeQueue
syncInvokeQueue
=
new
SyncInvokeQueue
();
public
static
SyncJaxrsInvokeQueue
syncJaxrsInvokeQueue
=
new
SyncJaxrsInvokeQueue
();
public
static
SyncJaxwsInvokeQueue
syncJaxwsInvokeQueue
=
new
SyncJaxwsInvokeQueue
();
public
static
SyncEmbedQueue
syncEmbedQueue
=
new
SyncEmbedQueue
();
...
...
@@ -32,7 +35,8 @@ public class ThisApplication {
ScriptHelperFactory
.
initialScriptText
=
Config
.
initialScriptText
();
Collaboration
.
start
(
context
());
MessageConnector
.
start
(
context
());
context
().
startQueue
(
syncInvokeQueue
);
context
().
startQueue
(
syncJaxrsInvokeQueue
);
context
().
startQueue
(
syncJaxwsInvokeQueue
);
context
().
startQueue
(
syncEmbedQueue
);
if
(
BooleanUtils
.
isTrue
(
Config
.
processPlatform
().
getUrge
().
getEnable
()))
{
context
.
schedule
(
Urge
.
class
,
Config
.
processPlatform
().
getUrge
().
getCron
());
...
...
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/WebservicesClient.java
已删除
100644 → 0
浏览文件 @
6530f1a6
package
com.x.processplatform.service.processing
;
import
org.apache.cxf.endpoint.Client
;
import
org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory
;
import
com.google.gson.JsonElement
;
public
class
WebservicesClient
{
public
Object
[]
jaxws
(
String
wsdl
,
String
method
,
Object
...
objects
)
{
Object
[]
result
=
null
;
try
{
JaxWsDynamicClientFactory
dcf
=
JaxWsDynamicClientFactory
.
newInstance
();
Client
client
=
dcf
.
createClient
(
wsdl
);
result
=
client
.
invoke
(
method
,
objects
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
public
JsonElement
jaxrsGet
(
String
applicationName
,
String
uri
)
throws
Exception
{
Class
<?>
clz
=
Class
.
forName
(
"com.x.base.core.project."
+
applicationName
);
return
ThisApplication
.
context
().
applications
().
getQuery
(
clz
,
uri
).
getData
();
}
public
JsonElement
jaxrsPut
(
String
applicationName
,
String
uri
,
Object
o
)
throws
Exception
{
Class
<?>
clz
=
Class
.
forName
(
"com.x.base.core.project."
+
applicationName
);
return
ThisApplication
.
context
().
applications
().
putQuery
(
clz
,
uri
,
o
).
getData
();
}
public
JsonElement
jaxrsPost
(
String
applicationName
,
String
uri
,
Object
o
)
throws
Exception
{
Class
<?>
clz
=
Class
.
forName
(
"com.x.base.core.project."
+
applicationName
);
return
ThisApplication
.
context
().
applications
().
postQuery
(
clz
,
uri
,
o
).
getData
();
}
public
JsonElement
jaxrsDelete
(
String
applicationName
,
String
uri
,
Object
o
)
throws
Exception
{
Class
<?>
clz
=
Class
.
forName
(
"com.x.base.core.project."
+
applicationName
);
return
ThisApplication
.
context
().
applications
().
deleteQuery
(
clz
,
uri
).
getData
();
}
}
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/ExecuteObject.java
已删除
100644 → 0
浏览文件 @
6530f1a6
package
com.x.processplatform.service.processing.processor.invoke
;
import
com.x.processplatform.core.entity.element.Invoke
;
import
com.x.processplatform.service.processing.processor.AeiObjects
;
public
class
ExecuteObject
{
public
ExecuteObject
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
{
this
.
aeiObjects
=
aeiObjects
;
this
.
invoke
=
invoke
;
}
private
AeiObjects
aeiObjects
;
private
Invoke
invoke
;
public
AeiObjects
getAeiObjects
()
{
return
aeiObjects
;
}
public
void
setAeiObjects
(
AeiObjects
aeiObjects
)
{
this
.
aeiObjects
=
aeiObjects
;
}
public
Invoke
getInvoke
()
{
return
invoke
;
}
public
void
setInvoke
(
Invoke
invoke
)
{
this
.
invoke
=
invoke
;
}
}
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/InvokeExecutor.java
浏览文件 @
76656af1
package
com.x.processplatform.service.processing.processor.invoke
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Objects
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.connection.ActionResponse
;
import
com.x.base.core.project.exception.RunningException
;
import
com.x.base.core.project.gson.XGsonBuilder
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.http.HttpToken
;
import
com.x.base.core.project.bean.NameValuePair
;
import
com.x.base.core.project.connection.CipherConnectionAction
;
import
com.x.base.core.project.connection.HttpConnection
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.processplatform.core.entity.element.Invoke
;
import
com.x.processplatform.service.processing.BindingPair
;
import
com.x.processplatform.service.processing.ScriptHelper
;
import
com.x.processplatform.service.processing.ScriptHelperFactory
;
import
com.x.processplatform.service.processing.ThisApplication
;
import
com.x.processplatform.service.processing.WebservicesClient
;
import
com.x.processplatform.service.processing.WrapScriptObject
;
import
com.x.processplatform.service.processing.processor.AeiObjects
;
import
com.x.base.core.project.webservices.WebservicesClient
;
public
class
InvokeExecutor
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
InvokeExecutor
.
class
);
public
void
execute
(
ExecuteObject
o
)
throws
Exception
{
switch
(
o
.
getInvoke
().
getInvokeMode
())
{
case
jaxws:
this
.
jaxws
(
o
.
getAeiObjects
(),
o
.
getInvoke
());
break
;
case
jaxrs:
this
.
jaxrs
(
o
.
getAeiObjects
(),
o
.
getInvoke
());
break
;
default
:
break
;
}
}
private
void
jaxws
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
if
(
BooleanUtils
.
isTrue
(
invoke
.
getInternal
()))
{
this
.
jaxwsInternal
(
aeiObjects
,
invoke
);
}
else
{
this
.
jaxwsExternal
(
aeiObjects
,
invoke
);
}
}
private
void
jaxwsInternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
}
private
void
jaxwsExternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
Object
[]
parameters
=
this
.
jaxwsEvalParameters
(
aeiObjects
,
invoke
);
WebservicesClient
client
=
new
WebservicesClient
();
Object
response
=
client
.
jaxws
(
invoke
.
getJaxwsAddress
(),
invoke
.
getJaxwsMethod
(),
parameters
);
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsResponseScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsResponseScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"response"
,
response
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxwsResponseScript
(),
invoke
.
getJaxwsResponseScriptText
());
}
}
private
Object
[]
jaxwsEvalParameters
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
List
<?>
parameters
=
new
ArrayList
<>();
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsParameterScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsParameterScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"parameters"
,
parameters
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxwsParameterScript
(),
invoke
.
getJaxwsParameterScriptText
());
}
return
parameters
.
toArray
();
}
private
void
jaxrs
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
if
(
BooleanUtils
.
isTrue
(
invoke
.
getInternal
()))
{
this
.
jaxrsInternal
(
aeiObjects
,
invoke
);
}
else
{
this
.
jaxrsExternal
(
aeiObjects
,
invoke
);
}
}
private
void
jaxrsInternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
ActionResponse
resp
=
null
;
Class
<?>
clz
=
Class
.
forName
(
"com.x.base.core.project."
+
invoke
.
getInternalProject
());
String
uri
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
String
body
=
null
;
switch
(
StringUtils
.
lowerCase
(
invoke
.
getJaxrsMethod
()))
{
public
String
execute
(
JaxrsObject
o
)
throws
Exception
{
String
result
=
""
;
switch
(
StringUtils
.
lowerCase
(
o
.
getMethod
()))
{
case
"post"
:
body
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
resp
=
ThisApplication
.
context
().
applications
().
postQuery
(
clz
,
uri
,
body
);
result
=
this
.
jaxrsHttpPost
(
o
);
break
;
case
"put"
:
body
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
resp
=
ThisApplication
.
context
().
applications
().
putQuery
(
clz
,
uri
,
body
);
result
=
this
.
jaxrsHttpPut
(
o
);
break
;
case
"get"
:
res
p
=
ThisApplication
.
context
().
applications
().
getQuery
(
clz
,
uri
);
res
ult
=
this
.
jaxrsHttpGet
(
o
);
break
;
case
"delete"
:
res
p
=
ThisApplication
.
context
().
applications
().
deleteQuery
(
clz
,
uri
);
res
ult
=
this
.
jaxrsHttpDelete
(
o
);
break
;
case
"head"
:
// resp = ThisApplication.context().applications().headQuery(clz,
// uri);
break
;
case
"options"
:
// result = this.httpOptions(business, attributes, work, data,
// invoke);
break
;
case
"patch"
:
// result = this.httpPatch(business, attributes, work, data,
// invoke);
break
;
case
"trace"
:
// result = this.httpTrace(business, attributes, work, data,
// invoke);
break
;
default
:
throw
new
Exception
(
"unknown http method "
+
invoke
.
getJaxrsMethod
());
}
/** 进行错误监测 */
if
(!
Objects
.
equals
(
resp
.
getType
(),
ActionResponse
.
Type
.
success
))
{
throw
new
RunningException
(
"invoke url:{} not success, because:{}, work:{}."
,
uri
,
resp
.
getMessage
(),
aeiObjects
.
getWork
().
getId
());
}
WrapScriptObject
jaxrsResponse
=
new
WrapScriptObject
();
// LinkedHashMap<?, ?> map = resp.getData(LinkedHashMap.class);
jaxrsResponse
.
set
(
XGsonBuilder
.
toJson
(
resp
.
getData
()));
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"jaxrsResponse"
,
jaxrsResponse
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsResponseScript
(),
invoke
.
getJaxrsResponseScriptText
());
}
}
private
void
jaxrsExternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
result
;
switch
(
StringUtils
.
lowerCase
(
invoke
.
getJaxrsMethod
()))
{
case
"post"
:
result
=
this
.
httpPost
(
aeiObjects
,
invoke
);
break
;
case
"put"
:
result
=
this
.
httpPut
(
aeiObjects
,
invoke
);
break
;
case
"get"
:
result
=
this
.
httpGet
(
aeiObjects
,
invoke
);
break
;
case
"delete"
:
result
=
this
.
httpDelete
(
aeiObjects
,
invoke
);
break
;
case
"head"
:
result
=
this
.
httpHead
(
aeiObjects
,
invoke
);
break
;
case
"options"
:
result
=
this
.
httpOptions
(
aeiObjects
,
invoke
);
break
;
case
"patch"
:
result
=
this
.
httpPatch
(
aeiObjects
,
invoke
);
break
;
case
"trace"
:
result
=
this
.
httpTrace
(
aeiObjects
,
invoke
);
break
;
default
:
throw
new
Exception
(
"unknown http method "
+
invoke
.
getJaxrsMethod
());
}
WrapScriptObject
jaxrsResponse
=
new
WrapScriptObject
();
jaxrsResponse
.
set
(
result
);
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"jaxrsResponse"
,
jaxrsResponse
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsResponseScript
(),
invoke
.
getJaxrsResponseScriptText
());
}
}
private
String
jaxrsUrl
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
url
=
invoke
.
getJaxrsAddress
();
Map
<
String
,
String
>
parameters
=
new
HashMap
<>();
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsParameterScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsParameterScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"parameters"
,
parameters
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsParameterScript
(),
invoke
.
getJaxrsParameterScriptText
());
}
for
(
Entry
<
String
,
String
>
entry
:
parameters
.
entrySet
())
{
url
=
StringUtils
.
replace
(
url
,
"{"
+
entry
.
getKey
()
+
"}"
,
entry
.
getValue
());
}
return
url
;
}
private
String
jaxrsEvalBody
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
JaxrsBody
jaxrsBody
=
new
JaxrsBody
();
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsBodyScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsBodyScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"jaxrsBody"
,
jaxrsBody
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsBodyScript
(),
invoke
.
getJaxrsBodyScriptText
());
}
return
jaxrsBody
.
get
();
}
private
String
httpPost
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
true
,
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"POST"
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
Object
o
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
connection
.
connect
();
this
.
doOutput
(
connection
,
o
);
return
this
.
readResultString
(
connection
);
}
private
String
httpPut
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
invoke
.
getJaxrsWithCipher
(),
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"PUT"
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
Object
o
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
connection
.
connect
();
this
.
doOutput
(
connection
,
o
);
return
this
.
readResultString
(
connection
);
}
private
String
httpGet
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
invoke
.
getJaxrsWithCipher
(),
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"GET"
);
connection
.
setDoOutput
(
false
);
connection
.
setDoInput
(
true
);
connection
.
connect
();
return
this
.
readResultString
(
connection
);
}
private
String
httpDelete
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
invoke
.
getJaxrsWithCipher
(),
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"DELETE"
);
connection
.
setDoOutput
(
false
);
connection
.
setDoInput
(
true
);
connection
.
connect
();
return
this
.
readResultString
(
connection
);
}
private
String
httpHead
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
invoke
.
getJaxrsWithCipher
(),
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"HEAD"
);
connection
.
setDoOutput
(
false
);
connection
.
setDoInput
(
true
);
connection
.
connect
();
return
this
.
readResultString
(
connection
);
}
private
String
httpOptions
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
invoke
.
getJaxrsWithCipher
(),
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"OPTIONS"
);
connection
.
setDoOutput
(
false
);
connection
.
setDoInput
(
true
);
connection
.
connect
();
return
this
.
readResultString
(
connection
);
}
private
String
httpPatch
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
invoke
.
getJaxrsWithCipher
(),
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"PATCH"
);
connection
.
setDoOutput
(
false
);
connection
.
setDoInput
(
true
);
connection
.
connect
();
return
this
.
readResultString
(
connection
);
}
private
String
httpTrace
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
HttpURLConnection
connection
=
this
.
prepareConnection
(
address
,
invoke
.
getJaxrsWithCipher
(),
invoke
.
getJaxrsContentType
());
connection
.
setRequestMethod
(
"TRACE"
);
connection
.
setDoOutput
(
false
);
connection
.
setDoInput
(
true
);
connection
.
connect
();
return
this
.
readResultString
(
connection
);
return
result
;
}
public
class
JaxrsBody
{
private
String
value
;
private
String
get
()
{
return
Objects
.
toString
(
value
,
""
);
public
Object
execute
(
JaxwsObject
o
)
throws
Exception
{
WebservicesClient
client
=
new
WebservicesClient
();
return
client
.
jaxws
(
o
.
getAddress
(),
o
.
getMethod
(),
o
.
getParameters
());
}
public
void
set
(
String
value
)
throws
Exception
{
this
.
value
=
value
;
private
String
jaxrsHttpPost
(
JaxrsObject
jaxrsObject
)
throws
Exception
{
if
(
jaxrsObject
.
getInternal
())
{
return
CipherConnectionAction
.
post
(
true
,
jaxrsObject
.
getAddress
(),
jaxrsObject
.
getBody
()).
getData
()
.
toString
();
}
else
{
List
<
NameValuePair
>
heads
=
new
ArrayList
<>();
heads
.
add
(
new
NameValuePair
(
HttpConnection
.
Content_Type
,
jaxrsObject
.
getContentType
()));
return
HttpConnection
.
postAsString
(
jaxrsObject
.
getAddress
(),
heads
,
jaxrsObject
.
getBody
());
}
}
private
HttpURLConnection
prepareConnection
(
String
address
,
boolean
withCipher
,
String
contentType
)
throws
Exception
{
try
{
URL
url
=
new
URL
(
address
);
HttpURLConnection
httpUrlConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpUrlConnection
.
setUseCaches
(
false
);
httpUrlConnection
.
setRequestProperty
(
"Content-Type"
,
contentType
);
if
(
BooleanUtils
.
isTrue
(
withCipher
))
{
EffectivePerson
effectivePerson
=
EffectivePerson
.
cipher
(
Config
.
token
().
getCipher
());
httpUrlConnection
.
setRequestProperty
(
HttpToken
.
X_Token
,
effectivePerson
.
getToken
());
}
return
httpUrlConnection
;
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"prepareConnection error"
,
e
);
private
String
jaxrsHttpPut
(
JaxrsObject
jaxrsObject
)
throws
Exception
{
if
(
jaxrsObject
.
getInternal
())
{
return
CipherConnectionAction
.
post
(
true
,
jaxrsObject
.
getAddress
(),
jaxrsObject
.
getBody
()).
getData
()
.
toString
();
}
else
{
List
<
NameValuePair
>
heads
=
new
ArrayList
<>();
heads
.
add
(
new
NameValuePair
(
HttpConnection
.
Content_Type
,
jaxrsObject
.
getContentType
()));
return
HttpConnection
.
postAsString
(
jaxrsObject
.
getAddress
(),
heads
,
jaxrsObject
.
getBody
());
}
}
private
void
doOutput
(
HttpURLConnection
connection
,
Object
data
)
throws
Exception
{
try
(
OutputStream
output
=
connection
.
getOutputStream
())
{
if
(
null
!=
data
)
{
if
(
data
instanceof
String
)
{
IOUtils
.
write
(
data
.
toString
(),
output
,
StandardCharsets
.
UTF_8
);
private
String
jaxrsHttpGet
(
JaxrsObject
jaxrsObject
)
throws
Exception
{
if
(
jaxrsObject
.
getInternal
())
{
return
CipherConnectionAction
.
get
(
true
,
jaxrsObject
.
getAddress
()).
getData
().
toString
();
}
else
{
IOUtils
.
write
(
XGsonBuilder
.
toJson
(
data
),
output
,
StandardCharsets
.
UTF_8
);
}
output
.
flush
();
}
List
<
NameValuePair
>
heads
=
new
ArrayList
<>();
heads
.
add
(
new
NameValuePair
(
HttpConnection
.
Content_Type
,
jaxrsObject
.
getContentType
()));
return
HttpConnection
.
getAsString
(
jaxrsObject
.
getAddress
(),
heads
);
}
}
private
String
readResultString
(
HttpURLConnection
connection
)
throws
Exception
{
String
result
=
""
;
try
(
InputStream
input
=
connection
.
getInputStream
())
{
result
=
IOUtils
.
toString
(
input
,
StandardCharsets
.
UTF_8
);
private
String
jaxrsHttpDelete
(
JaxrsObject
jaxrsObject
)
throws
Exception
{
if
(
jaxrsObject
.
getInternal
())
{
return
CipherConnectionAction
.
delete
(
true
,
jaxrsObject
.
getAddress
()).
getData
().
toString
();
}
else
{
List
<
NameValuePair
>
heads
=
new
ArrayList
<>();
heads
.
add
(
new
NameValuePair
(
HttpConnection
.
Content_Type
,
jaxrsObject
.
getContentType
()));
return
HttpConnection
.
deleteAsString
(
jaxrsObject
.
getAddress
(),
heads
);
}
return
result
;
}
}
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/InvokeProcessor.java
浏览文件 @
76656af1
package
com.x.processplatform.service.processing.processor.invoke
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Objects
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
com.x.base.core.container.EntityManagerContainer
;
import
com.x.base.core.project.Application
;
import
com.x.base.core.project.connection.ActionResponse
;
import
com.x.base.core.project.connection.CipherConnectionAction
;
import
com.x.base.core.project.exception.RunningException
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.scripting.ScriptingEngine
;
import
com.x.base.core.project.tools.StringTools
;
import
com.x.processplatform.core.entity.content.Work
;
import
com.x.processplatform.core.entity.element.Invoke
;
import
com.x.processplatform.core.entity.element.Route
;
import
com.x.processplatform.service.processing.BindingPair
;
import
com.x.processplatform.service.processing.ScriptHelper
;
import
com.x.processplatform.service.processing.ScriptHelperFactory
;
import
com.x.processplatform.service.processing.ThisApplication
;
import
com.x.processplatform.service.processing.WrapScriptObject
;
import
com.x.processplatform.service.processing.processor.AeiObjects
;
public
class
InvokeProcessor
extends
AbstractInvokeProcessor
{
...
...
@@ -30,21 +45,15 @@ public class InvokeProcessor extends AbstractInvokeProcessor {
@Override
protected
List
<
Work
>
executing
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
List
<
Work
>
results
=
new
ArrayList
<>();
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
ThisApplication
.
syncInvokeQueue
.
send
(
new
ExecuteObject
(
aeiObjects
,
invoke
));
}
else
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
executor
.
execute
(
new
ExecuteObject
(
aeiObjects
,
invoke
));
// switch (invoke.getInvokeMode()) {
// case jaxws:
// this.jaxws(aeiObjects, invoke);
// break;
// case jaxrs:
// this.jaxrs(aeiObjects, invoke);
// break;
// default:
// break;
// }
switch
(
invoke
.
getInvokeMode
())
{
case
jaxws:
this
.
jaxws
(
aeiObjects
,
invoke
);
break
;
case
jaxrs:
this
.
jaxrs
(
aeiObjects
,
invoke
);
break
;
default
:
break
;
}
results
.
add
(
aeiObjects
.
getWork
());
return
results
;
...
...
@@ -57,317 +66,281 @@ public class InvokeProcessor extends AbstractInvokeProcessor {
return
results
;
}
// private void jaxws(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// if (BooleanUtils.isTrue(invoke.getInternal())) {
// this.jaxwsInternal(aeiObjects, invoke);
// } else {
// this.jaxwsExternal(aeiObjects, invoke);
// }
// }
//
// private void jaxwsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// }
//
// private void jaxwsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// Object[] parameters = this.jaxwsEvalParameters(aeiObjects, invoke);
// WebservicesClient client = new WebservicesClient();
// Object response = client.jaxws(invoke.getJaxwsAddress(), invoke.getJaxwsMethod(), parameters);
// if ((StringUtils.isNotEmpty(invoke.getJaxwsResponseScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxwsResponseScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects, new BindingPair("response", response));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsResponseScript(),
// invoke.getJaxwsResponseScriptText());
// }
// }
//
// private Object[] jaxwsEvalParameters(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// List<?> parameters = new ArrayList<>();
// if ((StringUtils.isNotEmpty(invoke.getJaxwsParameterScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxwsParameterScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("parameters", parameters));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsParameterScript(),
// invoke.getJaxwsParameterScriptText());
// }
// return parameters.toArray();
// }
//
// private void jaxrs(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// if (BooleanUtils.isTrue(invoke.getInternal())) {
// this.jaxrsInternal(aeiObjects, invoke);
// } else {
// this.jaxrsExternal(aeiObjects, invoke);
// }
// }
//
// private void jaxrsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// ActionResponse resp = null;
// Class<?> clz = Class.forName("com.x.base.core.project." + invoke.getInternalProject());
// String uri = this.jaxrsUrl(aeiObjects, invoke);
// String body = null;
// switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
// case "post":
// body = this.jaxrsEvalBody(aeiObjects, invoke);
// resp = ThisApplication.context().applications().postQuery(clz, uri, body);
// break;
// case "put":
// body = this.jaxrsEvalBody(aeiObjects, invoke);
// resp = ThisApplication.context().applications().putQuery(clz, uri, body);
// break;
// case "get":
// resp = ThisApplication.context().applications().getQuery(clz, uri);
// break;
// case "delete":
// resp = ThisApplication.context().applications().deleteQuery(clz, uri);
// break;
// case "head":
// // resp = ThisApplication.context().applications().headQuery(clz,
// // uri);
// break;
// case "options":
// // result = this.httpOptions(business, attributes, work, data,
// // invoke);
// break;
// case "patch":
// // result = this.httpPatch(business, attributes, work, data,
// // invoke);
// break;
// case "trace":
// // result = this.httpTrace(business, attributes, work, data,
// // invoke);
// break;
// default:
// throw new Exception("unknown http method " + invoke.getJaxrsMethod());
// }
// /** 进行错误监测 */
// if (!Objects.equals(resp.getType(), ActionResponse.Type.success)) {
// throw new RunningException("invoke url:{} not success, because:{}, work:{}.", uri, resp.getMessage(),
// aeiObjects.getWork().getId());
// }
// WrapScriptObject jaxrsResponse = new WrapScriptObject();
// // LinkedHashMap<?, ?> map = resp.getData(LinkedHashMap.class);
// jaxrsResponse.set(gson.toJson(resp.getData()));
// if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("jaxrsResponse", jaxrsResponse));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
// invoke.getJaxrsResponseScriptText());
// }
// }
//
// private void jaxrsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String result;
// switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
// case "post":
// result = this.httpPost(aeiObjects, invoke);
// break;
// case "put":
// result = this.httpPut(aeiObjects, invoke);
// break;
// case "get":
// result = this.httpGet(aeiObjects, invoke);
// break;
// case "delete":
// result = this.httpDelete(aeiObjects, invoke);
// break;
// case "head":
// result = this.httpHead(aeiObjects, invoke);
// break;
// case "options":
// result = this.httpOptions(aeiObjects, invoke);
// break;
// case "patch":
// result = this.httpPatch(aeiObjects, invoke);
// break;
// case "trace":
// result = this.httpTrace(aeiObjects, invoke);
// break;
// default:
// throw new Exception("unknown http method " + invoke.getJaxrsMethod());
// }
// WrapScriptObject jaxrsResponse = new WrapScriptObject();
// jaxrsResponse.set(result);
// if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("jaxrsResponse", jaxrsResponse));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
// invoke.getJaxrsResponseScriptText());
// }
// }
//
// private String jaxrsUrl(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String url = invoke.getJaxrsAddress();
// Map<String, String> parameters = new HashMap<>();
// if ((StringUtils.isNotEmpty(invoke.getJaxrsParameterScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxrsParameterScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("parameters", parameters));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsParameterScript(),
// invoke.getJaxrsParameterScriptText());
// }
// for (Entry<String, String> entry : parameters.entrySet()) {
// url = StringUtils.replace(url, "{" + entry.getKey() + "}", entry.getValue());
// }
// return url;
// }
//
// private String jaxrsEvalBody(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// JaxrsBody jaxrsBody = new JaxrsBody();
// if ((StringUtils.isNotEmpty(invoke.getJaxrsBodyScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxrsBodyScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects, new BindingPair("jaxrsBody", jaxrsBody));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsBodyScript(),
// invoke.getJaxrsBodyScriptText());
//
// }
// return jaxrsBody.get();
// }
//
// private String httpPost(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, true, invoke.getJaxrsContentType());
// connection.setRequestMethod("POST");
// connection.setDoOutput(true);
// connection.setDoInput(true);
// Object o = this.jaxrsEvalBody(aeiObjects, invoke);
// connection.connect();
// this.doOutput(connection, o);
// return this.readResultString(connection);
// }
//
// private String httpPut(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("PUT");
// connection.setDoOutput(true);
// connection.setDoInput(true);
// Object o = this.jaxrsEvalBody(aeiObjects, invoke);
// connection.connect();
// this.doOutput(connection, o);
// return this.readResultString(connection);
// }
//
// private String httpGet(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("GET");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
//
// }
//
// private String httpDelete(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("DELETE");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpHead(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("HEAD");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpOptions(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("OPTIONS");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpPatch(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("PATCH");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpTrace(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("TRACE");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// public class JaxrsBody {
//
// private String value;
//
// private String get() {
// return Objects.toString(value, "");
// }
//
// public void set(String value) throws Exception {
// this.value = value;
// }
//
// }
//
// private HttpURLConnection prepareConnection(String address, boolean withCipher, String contentType)
// throws Exception {
// try {
// URL url = new URL(address);
// HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
// httpUrlConnection.setUseCaches(false);
// httpUrlConnection.setRequestProperty("Content-Type", contentType);
// if (BooleanUtils.isTrue(withCipher)) {
// EffectivePerson effectivePerson = EffectivePerson.cipher(Config.token().getCipher());
// httpUrlConnection.setRequestProperty(HttpToken.X_Token, effectivePerson.getToken());
// }
// return httpUrlConnection;
// } catch (Exception e) {
// throw new Exception("prepareConnection error", e);
// }
// }
//
// private void doOutput(HttpURLConnection connection, Object data) throws Exception {
// try (OutputStream output = connection.getOutputStream()) {
// if (null != data) {
// if (data instanceof String) {
// IOUtils.write(data.toString(), output, StandardCharsets.UTF_8);
// } else {
// IOUtils.write(XGsonBuilder.toJson(data), output, StandardCharsets.UTF_8);
// }
// output.flush();
// }
// }
// }
//
// private String readResultString(HttpURLConnection connection) throws Exception {
// String result = "";
// try (InputStream input = connection.getInputStream()) {
// result = IOUtils.toString(input, StandardCharsets.UTF_8);
// }
// return result;
// }
private
void
jaxws
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
if
(
BooleanUtils
.
isTrue
(
invoke
.
getInternal
()))
{
this
.
jaxwsInternal
(
aeiObjects
,
invoke
);
}
else
{
this
.
jaxwsExternal
(
aeiObjects
,
invoke
);
}
}
private
void
jaxwsInternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
}
private
void
jaxwsExternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
Object
[]
parameters
=
this
.
jaxwsEvalParameters
(
aeiObjects
,
invoke
);
JaxwsObject
jaxwsObject
=
new
JaxwsObject
();
jaxwsObject
.
setAddress
(
invoke
.
getJaxwsAddress
());
jaxwsObject
.
setMethod
(
invoke
.
getJaxwsMethod
());
jaxwsObject
.
setParameters
(
parameters
);
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
ThisApplication
.
syncJaxwsInvokeQueue
.
send
(
jaxwsObject
);
}
else
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
Object
response
=
executor
.
execute
(
jaxwsObject
);
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsResponseScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsResponseScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
ScriptingEngine
.
BINDINGNAME_JAXWSRESPONSE
,
response
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxwsResponseScript
(),
invoke
.
getJaxwsResponseScriptText
());
}
}
}
private
Object
[]
jaxwsEvalParameters
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
List
<?>
parameters
=
new
ArrayList
<>();
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsParameterScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxwsParameterScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
ScriptingEngine
.
BINDINGNAME_PARAMETERS
,
parameters
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxwsParameterScript
(),
invoke
.
getJaxwsParameterScriptText
());
}
return
parameters
.
toArray
();
}
private
void
jaxrs
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
if
(
BooleanUtils
.
isTrue
(
invoke
.
getInternal
()))
{
this
.
jaxrsInternal
(
aeiObjects
,
invoke
);
}
else
{
this
.
jaxrsExternal
(
aeiObjects
,
invoke
);
}
}
private
void
jaxrsInternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
ActionResponse
resp
=
null
;
Class
<?>
clz
=
Class
.
forName
(
"com.x.base.core.project."
+
invoke
.
getInternalProject
());
String
uri
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
String
body
=
""
;
switch
(
StringUtils
.
lowerCase
(
invoke
.
getJaxrsMethod
()))
{
case
"post"
:
body
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
JaxrsObject
jaxrsObject
=
new
JaxrsObject
();
Application
application
=
ThisApplication
.
context
().
applications
().
randomWithWeight
(
clz
);
jaxrsObject
.
setAddress
(
StringTools
.
JoinUrl
(
application
.
getUrlRoot
()
+
CipherConnectionAction
.
trim
(
uri
)));
jaxrsObject
.
setBody
(
body
);
jaxrsObject
.
setInternal
(
invoke
.
getInternal
());
jaxrsObject
.
setMethod
(
"post"
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
resp
=
ThisApplication
.
context
().
applications
().
postQuery
(
clz
,
uri
,
body
);
}
break
;
case
"put"
:
body
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
JaxrsObject
jaxrsObject
=
new
JaxrsObject
();
Application
application
=
ThisApplication
.
context
().
applications
().
randomWithWeight
(
clz
);
jaxrsObject
.
setAddress
(
StringTools
.
JoinUrl
(
application
.
getUrlRoot
()
+
CipherConnectionAction
.
trim
(
uri
)));
jaxrsObject
.
setBody
(
body
);
jaxrsObject
.
setInternal
(
invoke
.
getInternal
());
jaxrsObject
.
setMethod
(
"put"
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
resp
=
ThisApplication
.
context
().
applications
().
putQuery
(
clz
,
uri
,
body
);
}
break
;
case
"get"
:
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
JaxrsObject
jaxrsObject
=
new
JaxrsObject
();
Application
application
=
ThisApplication
.
context
().
applications
().
randomWithWeight
(
clz
);
jaxrsObject
.
setAddress
(
StringTools
.
JoinUrl
(
application
.
getUrlRoot
()
+
CipherConnectionAction
.
trim
(
uri
)));
jaxrsObject
.
setInternal
(
invoke
.
getInternal
());
jaxrsObject
.
setMethod
(
"get"
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
resp
=
ThisApplication
.
context
().
applications
().
getQuery
(
clz
,
uri
);
}
break
;
case
"delete"
:
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
JaxrsObject
jaxrsObject
=
new
JaxrsObject
();
Application
application
=
ThisApplication
.
context
().
applications
().
randomWithWeight
(
clz
);
jaxrsObject
.
setAddress
(
StringTools
.
JoinUrl
(
application
.
getUrlRoot
()
+
CipherConnectionAction
.
trim
(
uri
)));
jaxrsObject
.
setInternal
(
invoke
.
getInternal
());
jaxrsObject
.
setMethod
(
"delete"
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
resp
=
ThisApplication
.
context
().
applications
().
deleteQuery
(
clz
,
uri
);
}
break
;
case
"head"
:
break
;
case
"options"
:
break
;
case
"patch"
:
break
;
case
"trace"
:
break
;
default
:
throw
new
Exception
(
"unknown http method "
+
invoke
.
getJaxrsMethod
());
}
/** 进行错误监测 */
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
if
(!
Objects
.
equals
(
resp
.
getType
(),
ActionResponse
.
Type
.
success
))
{
throw
new
RunningException
(
"invoke url:{} not success, because:{}, work:{}."
,
uri
,
resp
.
getMessage
(),
aeiObjects
.
getWork
().
getId
());
}
WrapScriptObject
jaxrsResponse
=
new
WrapScriptObject
();
// LinkedHashMap<?, ?> map = resp.getData(LinkedHashMap.class);
jaxrsResponse
.
set
(
gson
.
toJson
(
resp
.
getData
()));
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
ScriptingEngine
.
BINDINGNAME_JAXRSRESPONSE
,
jaxrsResponse
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsResponseScript
(),
invoke
.
getJaxrsResponseScriptText
());
}
}
}
private
void
jaxrsExternal
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
result
=
""
;
String
address
=
this
.
jaxrsUrl
(
aeiObjects
,
invoke
);
String
body
=
""
;
JaxrsObject
jaxrsObject
=
null
;
switch
(
StringUtils
.
lowerCase
(
invoke
.
getJaxrsMethod
()))
{
case
"post"
:
body
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
jaxrsObject
=
new
JaxrsObject
();
jaxrsObject
.
setMethod
(
"post"
);
jaxrsObject
.
setInternal
(
false
);
jaxrsObject
.
setAddress
(
address
);
jaxrsObject
.
setBody
(
body
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
result
=
executor
.
execute
(
jaxrsObject
);
}
break
;
case
"put"
:
body
=
this
.
jaxrsEvalBody
(
aeiObjects
,
invoke
);
jaxrsObject
=
new
JaxrsObject
();
jaxrsObject
.
setMethod
(
"put"
);
jaxrsObject
.
setInternal
(
false
);
jaxrsObject
.
setAddress
(
address
);
jaxrsObject
.
setBody
(
body
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
result
=
executor
.
execute
(
jaxrsObject
);
}
break
;
case
"get"
:
jaxrsObject
=
new
JaxrsObject
();
jaxrsObject
.
setMethod
(
"get"
);
jaxrsObject
.
setInternal
(
false
);
jaxrsObject
.
setAddress
(
address
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
result
=
executor
.
execute
(
jaxrsObject
);
}
break
;
case
"delete"
:
jaxrsObject
=
new
JaxrsObject
();
jaxrsObject
.
setMethod
(
"delete"
);
jaxrsObject
.
setInternal
(
false
);
jaxrsObject
.
setAddress
(
address
);
jaxrsObject
.
setContentType
(
invoke
.
getJaxrsContentType
());
if
(
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
ThisApplication
.
syncJaxrsInvokeQueue
.
send
(
jaxrsObject
);
}
else
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
result
=
executor
.
execute
(
jaxrsObject
);
}
break
;
case
"head"
:
break
;
case
"options"
:
break
;
case
"patch"
:
break
;
case
"trace"
:
break
;
default
:
throw
new
Exception
(
"unknown http method "
+
invoke
.
getJaxrsMethod
());
}
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getAsync
()))
{
WrapScriptObject
jaxrsResponse
=
new
WrapScriptObject
();
jaxrsResponse
.
set
(
result
);
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsResponseScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
ScriptingEngine
.
BINDINGNAME_JAXRSRESPONSE
,
jaxrsResponse
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsResponseScript
(),
invoke
.
getJaxrsResponseScriptText
());
}
}
}
private
String
jaxrsUrl
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
String
url
=
invoke
.
getJaxrsAddress
();
Map
<
String
,
String
>
parameters
=
new
HashMap
<>();
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsParameterScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsParameterScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"parameters"
,
parameters
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsParameterScript
(),
invoke
.
getJaxrsParameterScriptText
());
}
for
(
Entry
<
String
,
String
>
entry
:
parameters
.
entrySet
())
{
url
=
StringUtils
.
replace
(
url
,
"{"
+
entry
.
getKey
()
+
"}"
,
entry
.
getValue
());
}
return
url
;
}
private
String
jaxrsEvalBody
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
JaxrsBody
jaxrsBody
=
new
JaxrsBody
();
if
((
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsBodyScript
()))
||
(
StringUtils
.
isNotEmpty
(
invoke
.
getJaxrsBodyScriptText
())))
{
ScriptHelper
scriptHelper
=
ScriptHelperFactory
.
create
(
aeiObjects
,
new
BindingPair
(
"jaxrsBody"
,
jaxrsBody
));
scriptHelper
.
eval
(
aeiObjects
.
getWork
().
getApplication
(),
invoke
.
getJaxrsBodyScript
(),
invoke
.
getJaxrsBodyScriptText
());
}
return
jaxrsBody
.
get
();
}
public
class
JaxrsBody
{
private
String
value
;
private
String
get
()
{
return
Objects
.
toString
(
value
,
""
);
}
public
void
set
(
String
value
)
throws
Exception
{
this
.
value
=
value
;
}
}
@Override
protected
void
arrivingCommitted
(
AeiObjects
aeiObjects
,
Invoke
invoke
)
throws
Exception
{
...
...
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/JaxrsObject.java
0 → 100644
浏览文件 @
76656af1
package
com.x.processplatform.service.processing.processor.invoke
;
import
com.x.base.core.project.gson.GsonPropertyObject
;
public
class
JaxrsObject
extends
GsonPropertyObject
{
private
String
method
;
private
String
body
;
private
String
address
;
private
String
contentType
;
private
Boolean
internal
;
public
String
getMethod
()
{
return
method
;
}
public
void
setMethod
(
String
method
)
{
this
.
method
=
method
;
}
public
String
getBody
()
{
return
body
;
}
public
void
setBody
(
String
body
)
{
this
.
body
=
body
;
}
public
String
getContentType
()
{
return
contentType
;
}
public
void
setContentType
(
String
contentType
)
{
this
.
contentType
=
contentType
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
public
Boolean
getInternal
()
{
return
internal
;
}
public
void
setInternal
(
Boolean
internal
)
{
this
.
internal
=
internal
;
}
}
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/JaxwsObject.java
0 → 100644
浏览文件 @
76656af1
package
com.x.processplatform.service.processing.processor.invoke
;
import
com.x.base.core.project.gson.GsonPropertyObject
;
public
class
JaxwsObject
extends
GsonPropertyObject
{
private
String
method
;
private
String
address
;
private
Object
[]
parameters
;
public
String
getMethod
()
{
return
method
;
}
public
void
setMethod
(
String
method
)
{
this
.
method
=
method
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
public
Object
[]
getParameters
()
{
return
parameters
;
}
public
void
setParameters
(
Object
[]
parameters
)
{
this
.
parameters
=
parameters
;
}
}
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/SyncInvokeQueue.java
→
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/Sync
Jaxrs
InvokeQueue.java
浏览文件 @
76656af1
...
...
@@ -2,10 +2,10 @@ package com.x.processplatform.service.processing.processor.invoke;
import
com.x.base.core.project.queue.AbstractQueue
;
public
class
Sync
InvokeQueue
extends
AbstractQueue
<
Execute
Object
>
{
public
class
Sync
JaxrsInvokeQueue
extends
AbstractQueue
<
Jaxrs
Object
>
{
@Override
protected
void
execute
(
Execute
Object
o
)
throws
Exception
{
protected
void
execute
(
Jaxrs
Object
o
)
throws
Exception
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
executor
.
execute
(
o
);
}
...
...
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/invoke/SyncJaxwsInvokeQueue.java
0 → 100644
浏览文件 @
76656af1
package
com.x.processplatform.service.processing.processor.invoke
;
import
com.x.base.core.project.queue.AbstractQueue
;
public
class
SyncJaxwsInvokeQueue
extends
AbstractQueue
<
JaxwsObject
>
{
@Override
protected
void
execute
(
JaxwsObject
o
)
throws
Exception
{
InvokeExecutor
executor
=
new
InvokeExecutor
();
executor
.
execute
(
o
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录