有没有干净的方法将上下文数据传递给@Asynchronous ejb 调用? [英] Is there clean way to pass context data to @Asynchronous ejb call?
本文介绍了有没有干净的方法将上下文数据传递给@Asynchronous ejb 调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在wildfly中,我异步执行无状态ejb方法(它用@Asynchronous注解映射).在调用方法中,我在线程本地中有一些上下文信息.将此数据传递给异步方法的最佳方法是什么?我不想向异步方法签名添加其他参数.
In wildfly I execute stateless ejb method asynchronously (it is mapped with @Asynchronous annotation). In the calling method I have some context information in thread local. What is the best way to pass this data to async method? I don't want to add additional parameter to async method signature.
推荐答案
有一点丑陋的管道可以解决如下(wildfly 8.x.x):
With a bit of ugly plumbing it can be resolved as follows (wildfly 8.x.x):
if (SecurityContextAssociation.getSecurityContext()==null)
SecurityContextAssociation.setSecurityContext(new JBossSecurityContext("background-job"));
SecurityContext current = SecurityContextAssociation.getSecurityContext();
final Object cred = current.getUtil().getCredential();
final Subject s = current.getUtil().getSubject();
final Principal up = current.getUtil().getUserPrincipal();
boolean needToUpdatePrincipal=true;
if (up instanceof TenantPrincipal) {
if (t.getTenantName().equals(((TenantPrincipal) up).getAdditonalField())) {
needToUpdatePrincipal=false;
}
}
if (needToUpdatePrincipal) {
TenantPrincipal tp=new TenantPrincipal(up.getName());
tp.setAdditionalField(t.getTenantName());
current.getUtil().createSubjectInfo(
, cred, (Subject) s);
}
基本上,您需要创建自己的 Principal 类并在其实例的附加字段中设置上下文数据.
Basically you need to create your own Principal class and set context data in the additional field of its instance.
这篇关于有没有干净的方法将上下文数据传递给@Asynchronous ejb 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文