public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
// In the beginning of every http request, we should create a new threaded transaction
final ScmSyncConfigurationPlugin plugin;
try {
plugin = ScmSyncConfigurationPlugin.getInstance();
} catch(Throwable t){
LOG.log(Level.SEVERE, "Error when retrieving ScmSyncConfig plugin instance => No filtering enabled on current request", t);
return;
}
if(plugin != null){
plugin.startThreadedTransaction();
try {
// Providing current ServletRequest in ScmSyncConfigurationDataProvider's thread local
// in order to be able to access it from everywhere inside this call
ScmSyncConfigurationDataProvider.provideRequestDuring((HttpServletRequest)request, new Callable() {
public Object call() throws Exception {
try {
// Handling "normally" http request
chain.doFilter(request, response);
}finally{
// In the end of http request, we should commit current transaction
plugin.getTransaction().commit();
}
return null;
}
});