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?
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.