Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
o2oa
提交
75344a31
o2oa
项目概览
此号慢热型
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
5
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,发现更多精彩内容 >>
提交
75344a31
编写于
11月 11, 2020
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化invoke执行,尽量走缓存
上级
3ec57169
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
415 addition
and
223 deletion
+415
-223
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/jaxrs/work/BaseAction.java
...essplatform/service/processing/jaxrs/work/BaseAction.java
+149
-147
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute.java
...java/com/x/program/center/jaxrs/invoke/ActionExecute.java
+95
-76
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute2.java
...ava/com/x/program/center/jaxrs/invoke/ActionExecute2.java
+171
-0
未找到文件。
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/jaxrs/work/BaseAction.java
浏览文件 @
75344a31
...
@@ -29,11 +29,13 @@ abstract class BaseAction extends StandardJaxrsAction {
...
@@ -29,11 +29,13 @@ abstract class BaseAction extends StandardJaxrsAction {
work
.
getId
());
work
.
getId
());
if
(
ListTools
.
isNotEmpty
(
taskIds
))
{
if
(
ListTools
.
isNotEmpty
(
taskIds
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Task
.
class
);
business
.
entityManagerContainer
().
beginTransaction
(
Task
.
class
);
business
.
entityManagerContainer
().
delete
(
Task
.
class
,
taskIds
);
for
(
Task
o
:
business
.
entityManagerContainer
().
list
(
Task
.
class
,
taskIds
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
task_delete
(
o
);
}
}
}
business
.
entityManagerContainer
().
beginTransaction
(
Work
.
class
);
business
.
entityManagerContainer
().
beginTransaction
(
Work
.
class
);
business
.
entityManagerContainer
().
remove
(
work
,
CheckRemoveType
.
all
);
business
.
entityManagerContainer
().
remove
(
work
,
CheckRemoveType
.
all
);
business
.
entityManagerContainer
().
commit
();
return
false
;
return
false
;
}
else
{
}
else
{
deleteTask
(
business
,
work
.
getJob
());
deleteTask
(
business
,
work
.
getJob
());
...
...
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute.java
浏览文件 @
75344a31
package
com.x.program.center.jaxrs.invoke
;
package
com.x.program.center.jaxrs.invoke
;
import
java.util.Date
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
...
@@ -12,7 +11,6 @@ import javax.script.ScriptContext;
...
@@ -12,7 +11,6 @@ import javax.script.ScriptContext;
import
javax.script.SimpleScriptContext
;
import
javax.script.SimpleScriptContext
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
com.x.base.core.project.cache.CacheManager
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -21,7 +19,8 @@ import com.x.base.core.container.EntityManagerContainer;
...
@@ -21,7 +19,8 @@ import com.x.base.core.container.EntityManagerContainer;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.project.cache.Cache.CacheCategory
;
import
com.x.base.core.project.cache.Cache.CacheCategory
;
import
com.x.base.core.project.cache.Cache.CacheKey
;
import
com.x.base.core.project.cache.Cache.CacheKey
;
import
com.x.base.core.entity.annotation.CheckPersistType
;
import
com.x.base.core.project.cache.CacheManager
;
import
com.x.base.core.project.exception.ExceptionEntityNotExist
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.jaxrs.WoContentType
;
import
com.x.base.core.project.jaxrs.WoContentType
;
...
@@ -44,40 +43,33 @@ class ActionExecute extends BaseAction {
...
@@ -44,40 +43,33 @@ class ActionExecute extends BaseAction {
ActionResult
<
Object
>
execute
(
HttpServletRequest
request
,
EffectivePerson
effectivePerson
,
String
flag
,
ActionResult
<
Object
>
execute
(
HttpServletRequest
request
,
EffectivePerson
effectivePerson
,
String
flag
,
JsonElement
jsonElement
)
throws
Exception
{
JsonElement
jsonElement
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
ActionResult
<
Object
>
result
=
new
ActionResult
<>();
CacheCategory
cacheCategory
=
new
CacheCategory
(
Invoke
.
class
);
Invoke
invoke
=
emc
.
flag
(
flag
,
Invoke
.
class
);
Invoke
invoke
=
this
.
get
(
cacheCategory
,
flag
);
if
(
null
==
invoke
)
{
if
(
null
==
invoke
)
{
throw
new
ExceptionInvokeNotExist
(
flag
);
throw
new
ExceptionEntityNotExist
(
flag
,
Invoke
.
class
);
}
}
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getEnable
()))
{
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getEnable
()))
{
throw
new
ExceptionNotEnable
(
invoke
.
getName
());
throw
new
ExceptionNotEnable
(
invoke
.
getName
());
}
}
if
(
StringUtils
.
isNotEmpty
(
invoke
.
getRemoteAddrRegex
()))
{
if
(
StringUtils
.
isNotEmpty
(
invoke
.
getRemoteAddrRegex
()))
{
Matcher
matcher
=
Pattern
.
compile
(
invoke
.
getRemoteAddrRegex
()).
matcher
(
request
.
getRemoteAddr
());
Matcher
matcher
=
Pattern
.
compile
(
invoke
.
getRemoteAddrRegex
()).
matcher
(
request
.
getRemoteAddr
());
if
(!
matcher
.
find
())
{
if
(!
matcher
.
find
())
{
throw
new
ExceptionInvalidRemoteAddr
(
request
.
getRemoteAddr
(),
invoke
.
getName
());
throw
new
ExceptionInvalidRemoteAddr
(
request
.
getRemoteAddr
(),
invoke
.
getName
());
}
}
}
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastStartTime
(
new
Date
());
emc
.
commit
();
CacheCategory
cacheCategory
=
new
CacheCategory
(
Invoke
.
class
);
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute
.
class
,
invoke
.
getId
());
CompiledScript
compiledScript
=
null
;
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
compiledScript
=
(
CompiledScript
)
optional
.
get
();
}
else
{
compiledScript
=
ScriptFactory
.
compile
(
invoke
.
getText
());
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
compiledScript
);
}
ActionResult
<
Object
>
result
=
new
ActionResult
<>();
CompiledScript
compiledScript
=
this
.
getCompiledScript
(
cacheCategory
,
invoke
);
ScriptContext
scriptContext
=
new
SimpleScriptContext
();
ScriptContext
scriptContext
=
new
SimpleScriptContext
();
Bindings
bindings
=
scriptContext
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
Bindings
bindings
=
scriptContext
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
Resources
resources
=
new
Resources
();
Resources
resources
=
new
Resources
();
resources
.
setEntityManagerContainer
(
emc
);
// 此方法不用装载emc
// resources.setEntityManagerContainer(emc);
resources
.
setContext
(
ThisApplication
.
context
());
resources
.
setContext
(
ThisApplication
.
context
());
resources
.
setOrganization
(
new
Organization
(
ThisApplication
.
context
()));
resources
.
setOrganization
(
new
Organization
(
ThisApplication
.
context
()));
resources
.
setWebservicesClient
(
new
WebservicesClient
());
resources
.
setWebservicesClient
(
new
WebservicesClient
());
...
@@ -118,12 +110,37 @@ class ActionExecute extends BaseAction {
...
@@ -118,12 +110,37 @@ class ActionExecute extends BaseAction {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
ExceptionExecuteError
(
invoke
.
getName
(),
e
);
throw
new
ExceptionExecuteError
(
invoke
.
getName
(),
e
);
}
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastEndTime
(
new
Date
());
emc
.
check
(
invoke
,
CheckPersistType
.
all
);
emc
.
commit
();
return
result
;
return
result
;
}
}
private
Invoke
get
(
CacheCategory
cacheCategory
,
String
flag
)
throws
Exception
{
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute
.
class
,
flag
);
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
return
(
Invoke
)
optional
.
get
();
}
else
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Invoke
invoke
=
emc
.
flag
(
flag
,
Invoke
.
class
);
if
(
null
!=
invoke
)
{
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
invoke
);
}
return
invoke
;
}
}
}
private
CompiledScript
getCompiledScript
(
CacheCategory
cacheCategory
,
Invoke
invoke
)
throws
Exception
{
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute
.
class
,
"CompiledScript"
,
invoke
.
getId
());
CompiledScript
compiledScript
=
null
;
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
compiledScript
=
(
CompiledScript
)
optional
.
get
();
}
else
{
compiledScript
=
ScriptFactory
.
compile
(
invoke
.
getText
());
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
compiledScript
);
}
return
compiledScript
;
}
}
public
static
class
CustomResponse
{
public
static
class
CustomResponse
{
...
@@ -154,6 +171,8 @@ class ActionExecute extends BaseAction {
...
@@ -154,6 +171,8 @@ class ActionExecute extends BaseAction {
public
static
class
Wo
extends
WoValue
{
public
static
class
Wo
extends
WoValue
{
private
static
final
long
serialVersionUID
=
-
2253926744723217590L
;
}
}
public
static
class
Resources
extends
AbstractResources
{
public
static
class
Resources
extends
AbstractResources
{
...
...
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute2.java
0 → 100644
浏览文件 @
75344a31
package
com.x.program.center.jaxrs.invoke
;
import
java.util.Date
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.script.Bindings
;
import
javax.script.CompiledScript
;
import
javax.script.ScriptContext
;
import
javax.script.SimpleScriptContext
;
import
javax.servlet.http.HttpServletRequest
;
import
com.x.base.core.project.cache.CacheManager
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
com.google.gson.JsonElement
;
import
com.x.base.core.container.EntityManagerContainer
;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.project.cache.Cache.CacheCategory
;
import
com.x.base.core.project.cache.Cache.CacheKey
;
import
com.x.base.core.entity.annotation.CheckPersistType
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.jaxrs.WoContentType
;
import
com.x.base.core.project.jaxrs.WoSeeOther
;
import
com.x.base.core.project.jaxrs.WoTemporaryRedirect
;
import
com.x.base.core.project.jaxrs.WoText
;
import
com.x.base.core.project.jaxrs.WoValue
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.script.AbstractResources
;
import
com.x.base.core.project.script.ScriptFactory
;
import
com.x.base.core.project.webservices.WebservicesClient
;
import
com.x.organization.core.express.Organization
;
import
com.x.program.center.ThisApplication
;
import
com.x.program.center.core.entity.Invoke
;
class
ActionExecute2
extends
BaseAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ActionExecute2
.
class
);
ActionResult
<
Object
>
execute
(
HttpServletRequest
request
,
EffectivePerson
effectivePerson
,
String
flag
,
JsonElement
jsonElement
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
ActionResult
<
Object
>
result
=
new
ActionResult
<>();
Invoke
invoke
=
emc
.
flag
(
flag
,
Invoke
.
class
);
if
(
null
==
invoke
)
{
throw
new
ExceptionInvokeNotExist
(
flag
);
}
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getEnable
()))
{
throw
new
ExceptionNotEnable
(
invoke
.
getName
());
}
if
(
StringUtils
.
isNotEmpty
(
invoke
.
getRemoteAddrRegex
()))
{
Matcher
matcher
=
Pattern
.
compile
(
invoke
.
getRemoteAddrRegex
()).
matcher
(
request
.
getRemoteAddr
());
if
(!
matcher
.
find
())
{
throw
new
ExceptionInvalidRemoteAddr
(
request
.
getRemoteAddr
(),
invoke
.
getName
());
}
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastStartTime
(
new
Date
());
emc
.
commit
();
CacheCategory
cacheCategory
=
new
CacheCategory
(
Invoke
.
class
);
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute2
.
class
,
invoke
.
getId
());
CompiledScript
compiledScript
=
null
;
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
compiledScript
=
(
CompiledScript
)
optional
.
get
();
}
else
{
compiledScript
=
ScriptFactory
.
compile
(
invoke
.
getText
());
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
compiledScript
);
}
ScriptContext
scriptContext
=
new
SimpleScriptContext
();
Bindings
bindings
=
scriptContext
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
Resources
resources
=
new
Resources
();
resources
.
setEntityManagerContainer
(
emc
);
resources
.
setContext
(
ThisApplication
.
context
());
resources
.
setOrganization
(
new
Organization
(
ThisApplication
.
context
()));
resources
.
setWebservicesClient
(
new
WebservicesClient
());
resources
.
setApplications
(
ThisApplication
.
context
().
applications
());
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_RESOURCES
,
resources
);
bindings
.
put
(
"requestText"
,
gson
.
toJson
(
jsonElement
));
bindings
.
put
(
"request"
,
request
);
bindings
.
put
(
"effectivePerson"
,
effectivePerson
);
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_APPLICATIONS
,
ThisApplication
.
context
().
applications
());
CustomResponse
customResponse
=
new
CustomResponse
();
bindings
.
put
(
"customResponse"
,
customResponse
);
Wo
wo
=
new
Wo
();
try
{
ScriptFactory
.
initialServiceScriptText
().
eval
(
scriptContext
);
Object
o
=
compiledScript
.
eval
(
scriptContext
);
if
(
StringUtils
.
equals
(
"seeOther"
,
customResponse
.
type
))
{
WoSeeOther
woSeeOther
=
new
WoSeeOther
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woSeeOther
);
}
else
if
(
StringUtils
.
equals
(
"temporaryRedirect"
,
customResponse
.
type
))
{
WoTemporaryRedirect
woTemporaryRedirect
=
new
WoTemporaryRedirect
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woTemporaryRedirect
);
}
else
{
if
(
null
!=
customResponse
.
value
)
{
if
(
StringUtils
.
isNotEmpty
(
customResponse
.
contentType
))
{
result
.
setData
(
new
WoContentType
(
customResponse
.
value
,
customResponse
.
contentType
));
}
else
if
(
customResponse
.
value
instanceof
WoText
)
{
result
.
setData
(
customResponse
.
value
);
}
else
{
wo
.
setValue
(
customResponse
.
value
);
result
.
setData
(
wo
);
}
}
else
{
wo
.
setValue
(
o
);
result
.
setData
(
wo
);
}
}
}
catch
(
Exception
e
)
{
throw
new
ExceptionExecuteError
(
invoke
.
getName
(),
e
);
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastEndTime
(
new
Date
());
emc
.
check
(
invoke
,
CheckPersistType
.
all
);
emc
.
commit
();
return
result
;
}
}
public
static
class
CustomResponse
{
protected
String
type
=
null
;
protected
Object
value
;
protected
String
contentType
;
public
void
seeOther
(
String
url
)
{
this
.
type
=
"seeOther"
;
this
.
value
=
url
;
}
public
void
temporaryRedirect
(
String
url
)
{
this
.
type
=
"temporaryRedirect"
;
this
.
value
=
url
;
}
public
void
setBody
(
Object
obj
)
{
this
.
value
=
obj
;
}
public
void
setBody
(
Object
obj
,
String
contentType
)
{
this
.
value
=
obj
;
this
.
contentType
=
contentType
;
}
}
public
static
class
Wo
extends
WoValue
{
}
public
static
class
Resources
extends
AbstractResources
{
private
Organization
organization
;
public
Organization
getOrganization
()
{
return
organization
;
}
public
void
setOrganization
(
Organization
organization
)
{
this
.
organization
=
organization
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录