Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Really my question should have been "How do I log method invocations such that a given users path through the application can easily be parsed out of the log file?". The question as it stands assumes getting the session id is the answer which may well not be the case. With this better phrased question in mind I have now discovered that as long as all business logic of concern is accessed via EJBs you can indeed log a given users path as follows:</p> <p>Create an interceptor class that has an EJB SessionContext injected in to it:</p> <pre><code>/** * SessionContext of this EJB; this will be injected by the EJB * Container because it's marked w/ @Resource */ @Resource private SessionContext context; </code></pre> <p>Add a method annotated with AroundInvoke that will intercept calls:</p> <pre><code>@AroundInvoke public Object log(InvocationContext ctx) throws Exception { String originName = Thread.currentThread().getName(); String currentUser = context.getCallerPrincipal().getName(); try{ String tracingName = currentUser + " " + originName; Thread.currentThread().setName(tracingName); return invocationContext.proceed(); }finally{ Thread.currentThread().setName(originName); } } </code></pre> <p>Note we use the session context to get hold of the user who has caused this action. We then change the name of the thread to hold that users name. All subsequent logging in this call stack will output the users name assuming loggin is configured to also output the thread name regardless of if they are in an EJB or just some POJO class.</p> <p>This thread renaming was inspired by Adam Bien's server independent thread tracking utility:</p> <p><a href="http://www.adam-bien.com/roller/abien/entry/server_independent_thread_tracking_utility" rel="nofollow">http://www.adam-bien.com/roller/abien/entry/server_independent_thread_tracking_utility</a></p> <p>Altering it to rename the thread to be the users name was a modification I made.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload