Get http session / request in hibernate interceptor

I want to to implement an audit logging module to my existing system and I want to save actual logged user information and it's only the httpSession.

I'm using hibernate/spring/struts 2, and in order to get actual logged user information and call saveLog service I need the ServletContext to find those service bean or get the httpServletRequest...

I have been searching and seems binding the session to ThreadLocal usign Filter is the only way? something like this or this (last answer)

is there other suggestion? is this a commun pattern or a good practice ?

Answers


Spring can bind current request to the thread out of the box. If you use DispatcherServlet, it's done automatically, otherwise you need to declare RequestContextFilter.

Then you can access request properties via RequestContextHolder.


Need Your Help

REST API Create Virtual Machine Deployment: How to create a VM with AD DC?

azure dns virtual-machine

API Here: http://msdn.microsoft.com/en-us/library/windowsazure/jj157194

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.