X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Fruntime%2Forg.argeo.server.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fmvc%2Fjcr%2FOpenSessionInViewJcrInterceptor.java;fp=server%2Fruntime%2Forg.argeo.server.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fmvc%2Fjcr%2FOpenSessionInViewJcrInterceptor.java;h=77d2663d00e85d32b1eb25012534703457387a50;hb=615bcb2bf7937888af7631cb3319d8c55b275fa9;hp=0000000000000000000000000000000000000000;hpb=91e4bcfa8525708e310eebe6589525a73591efb8;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/mvc/jcr/OpenSessionInViewJcrInterceptor.java b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/mvc/jcr/OpenSessionInViewJcrInterceptor.java new file mode 100644 index 000000000..77d2663d0 --- /dev/null +++ b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/mvc/jcr/OpenSessionInViewJcrInterceptor.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.server.mvc.jcr; + +import javax.jcr.Session; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.ui.ModelMap; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.context.request.WebRequestInterceptor; + +/** @deprecated */ +public class OpenSessionInViewJcrInterceptor implements WebRequestInterceptor, + JcrMvcConstants { + private final static Log log = LogFactory + .getLog(OpenSessionInViewJcrInterceptor.class); + + private Session session; + + public void preHandle(WebRequest request) throws Exception { + if (log.isTraceEnabled()) + log.trace("preHandle: " + request); + // Authentication auth = SecurityContextHolder.getContext() + // .getAuthentication(); + // if (auth != null) + // log.debug("auth=" + auth + ", authenticated=" + // + auth.isAuthenticated() + ", name=" + auth.getName()); + // else + // log.debug("No auth"); + + // FIXME: find a safer way to initialize + // FIXME: not really needed to initialize here + // session.getRepository(); + request.setAttribute(REQUEST_ATTR_SESSION, session, + RequestAttributes.SCOPE_REQUEST); + } + + public void postHandle(WebRequest request, ModelMap model) throws Exception { + // if (log.isDebugEnabled()) + // log.debug("postHandle: " + request); + } + + public void afterCompletion(WebRequest request, Exception ex) + throws Exception { + if (log.isTraceEnabled()) + log.trace("afterCompletion: " + request); + // FIXME: only close session that were open + session.logout(); + } + + public void setSession(Session session) { + this.session = session; + } + +}