有没有办法从 CDI 拦截器检索会话 ID?
我创建了一个标准 CDI (WELD) 拦截器来记录方法调用:
@MyInterceptorBinding
@Interceptor
public class MyInterceptor implements Serializable {
@AroundInvoke
public Object interceptMethod(InvocationContext ctx) throws Exception {
// Do some Logging Operations
try {
Object result = ctx.proceed();
return result;
} catch (Exception e) {
throw e;
}
}
}
我还想记录调用该方法的会话 id(也记录请求 id 会很棒!)。
有什么办法吗?
I have created a standard CDI (WELD) interceptor to log method calls:
@MyInterceptorBinding
@Interceptor
public class MyInterceptor implements Serializable {
@AroundInvoke
public Object interceptMethod(InvocationContext ctx) throws Exception {
// Do some Logging Operations
try {
Object result = ctx.proceed();
return result;
} catch (Exception e) {
throw e;
}
}
}
I would like to log also the session id from which the method is called (log also the request id would be great!).
Is there any way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
因此,您需要创建一个安装在应用程序中的 @WebFilter,将会话 ID 存储在 requestScoped bean 中。然后,您可以将所述 requestScoped bean 注入您的拦截器并检索它。
Yes.
So you would need to create a
@WebFilter
installed in your app that stored the session id in a requestScoped bean. You could then inject said requestScoped bean into your interceptor and retrieve it.