SessionPerRequestFilter and FORWARD dispatching

2 views
Skip to first unread message

Patrick Lightbody

unread,
Aug 5, 2009, 3:40:10 PM8/5/09
to warp...@googlegroups.com
I'm trying to do some things where I have a filter that intercepts
some URLs and, depending on some conditions, issues a servlet FORWARD:

filterConfig.getServletContext().getRequestDispatcher(destPath).forward(req,
res);

When doing this, however, I was getting this error with any code that
tried to touch Hibernate:

org.hibernate.HibernateException: No session currently bound to
execution context

Not a big surprise though, since my web.xml originally was just:

<filter-mapping>
<filter-name>sessionPerRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Which means it's only binding to incoming requests, and if my other
filter is catching the request before then and then forwarding it,
Warp/Hibernate never got the change to initialize in the way it was
expected. So I figured the easy fix was:

<filter-mapping>
<filter-name>sessionPerRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

Unfortunately - and this is where I'm stuck - I got this error:

org.hibernate.SessionException: Session was already closed
at org.hibernate.impl.SessionImpl.close(SessionImpl.java:275)
at com.wideplay.warp.hibernate.SessionPerRequestFilter.doFilter(SessionPerRequestFilter.java:56)

I figure it has something to do with the fact that
SessionPerRequestFilter is being "double processes" (once for the
request and once for the forward), but I'm not quite sure. I tried to
debug but couldn't get too far.

Any suggestions?

Patrick

--
On-demand, low-cost load testing using real browsers
http://browsermob.com

Patrick Lightbody
Founder, BrowserMob
+1 (415) 830-5488

Dhanji R. Prasanna

unread,
Aug 5, 2009, 7:33:33 PM8/5/09
to warp...@googlegroups.com
Are you using Guice Servlet too?

btw, forward will not go through the filter chain again...

Dhanji.

jordi

unread,
Aug 5, 2009, 7:45:39 PM8/5/09
to warp...@googlegroups.com
maybe hibernate properties? you should have this:

hibernate.current_session_context_class=managed

Patrick Lightbody

unread,
Aug 6, 2009, 6:39:29 PM8/6/09
to warp...@googlegroups.com
Not using Guice Servlet. Actually, the forward will go through any
filter that is configured to use <dispatcher>FORWARD</dispatcher>.

I ended up solving the problem by just placing my filter _below_ the
Warp filter (it was above it before).

Dhanji R. Prasanna

unread,
Aug 6, 2009, 7:20:12 PM8/6/09
to warp...@googlegroups.com
Cool! Glad that worked out. PersistenceFilter needs to be at the top most of the time (and it's pretty inexpensive, so it's ok). You only maybe want Sitemesh above it.

Yea, we don't support forward() properly in Guice Servlet, yet. =(

Dhanji.
Reply all
Reply to author
Forward
0 new messages