Thread:
 Handling multiple filter requests for a single Use... 
 rdleeper   22 Sep 2005, 23:09 
 Re: Handling multiple filter requests for a sin... 
 claan   22 Nov 2005, 08:39 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: claan (22 Nov 2005, 08:39) Replies: 0, Views: 28579
Subject: Re: Handling multiple filter requests for a single User...
<code>

>        try {
>            HttpServletRequest httpRequest = (HttpServletRequest)
request;
>            Object val = httpRequest.getAttribute(
INIT_REQ_ATTR_NAME );
>            initialRequest = ( val == null );
>            httpRequest.setAttribute( INIT_REQ_ATTR_NAME,
>INIT_REQ_ATTR_NAME );

>            chain.doFilter(request, response);

>            HibernateUtil.commitTransaction();

>        }
>        catch (RuntimeException ex) {
>            log.debug("Rolling back the database transaction.");
>            HibernateUtil.rollbackTransaction(); // Also closes the
session
>            // Just rollback and let others handle the exception, e.g.
>for display
>            throw ex;

>        }
>        finally {
>            // No matter what happens, close the Session.
>            if ( initialRequest ) {
>                HibernateUtil.closeSession();
>            }
>        }
>    }

>    public void destroy() {}
>}

</code>

>For those using struts, you can filter on the action servlet and also
>jsp files at the same time and ensure that you will have only one
Session.

Now, here's one for the STRUTS guys out there, how do you catch 
exceptions thrown from an Action class in the filter as STRUTS 
captures it before it reaches the filter... thus making the rollback 
unreachable?

Should you extend the RequestProcessor and take it from there?

Any ideas?

Regards
ace
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]