1 package org
.argeo
.server
.jcr
.mvc
;
3 import javax
.jcr
.Session
;
5 import org
.apache
.commons
.logging
.Log
;
6 import org
.apache
.commons
.logging
.LogFactory
;
7 import org
.springframework
.ui
.ModelMap
;
8 import org
.springframework
.web
.context
.request
.RequestAttributes
;
9 import org
.springframework
.web
.context
.request
.WebRequest
;
10 import org
.springframework
.web
.context
.request
.WebRequestInterceptor
;
12 public class OpenSessionInViewJcrInterceptor
implements WebRequestInterceptor
,
14 private final static Log log
= LogFactory
15 .getLog(OpenSessionInViewJcrInterceptor
.class);
17 private Session session
;
19 public void preHandle(WebRequest request
) throws Exception
{
20 if (log
.isTraceEnabled())
21 log
.trace("preHandle: " + request
);
22 // Authentication auth = SecurityContextHolder.getContext()
23 // .getAuthentication();
25 // log.debug("auth=" + auth + ", authenticated="
26 // + auth.isAuthenticated() + ", name=" + auth.getName());
28 // log.debug("No auth");
30 // FIXME: find a safer way to initialize
31 // FIXME: not really needed to initialize here
32 // session.getRepository();
33 request
.setAttribute(REQUEST_ATTR_SESSION
, session
,
34 RequestAttributes
.SCOPE_REQUEST
);
37 public void postHandle(WebRequest request
, ModelMap model
) throws Exception
{
38 // if (log.isDebugEnabled())
39 // log.debug("postHandle: " + request);
42 public void afterCompletion(WebRequest request
, Exception ex
)
44 if (log
.isTraceEnabled())
45 log
.trace("afterCompletion: " + request
);
46 // FIXME: only close session that were open
50 public void setSession(Session session
) {
51 this.session
= session
;