有没有办法从 CDI 拦截器检索会话 ID?

发布于 2025-01-12 11:34:16 字数 496 浏览 5 评论 0原文

我创建了一个标准 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇见了你 2025-01-19 11:34:16

是的。

因此,您需要创建一个安装在应用程序中的 @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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文