Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To log userid information through MDC

Status
Not open for further replies.

17957

Programmer
Sep 5, 2008
1
US
This class implements the doFilter method in the Filter interface.
The below given code snippet explains how diagnostic data is put to the MDC.

try {
HttpServletRequest req = (HttpServletRequest) servletRequest;
HttpServletResponse res = (HttpServletResponse) servletResponse;
HttpSession session = req.getSession();
UserSecurityImplementation userSecurity =
(UserSecurityImplementation)session.getAttribute(USER_SECURITY_KEY);
if (userSecurity != null) {
MDC.put(“USER_ID”, userSecurity.getUserId());
}
Chain.doFilter(request,response)
}
finally {
MDC.remove(“USER_ID”);
}

After one EJB has finished serving first request and before removing the
MDC from UI layer for the same request, is it possible that the bean (and in
turn the running thread) be allocated to next request? This will cause the
previous user id information to be logged erraneously. Will this happen?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top