Do not time out demo.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / WebCmsSessionImpl.java
index ac4b35336bed9e77da980920fdc19430689cd16e..b30b00323eab91659404831e7b7560e6325f8825 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.cms.internal.kernel;
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Hashtable;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -10,11 +11,14 @@ import javax.servlet.http.HttpSession;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.auth.WebCmsSession;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.http.HttpContext;
 import org.osgi.service.useradmin.Authorization;
 
 public class WebCmsSessionImpl implements WebCmsSession {
+       private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
        private final static Log log = LogFactory.getLog(WebCmsSessionImpl.class);
 
        private final String id;
@@ -24,9 +28,14 @@ public class WebCmsSessionImpl implements WebCmsSession {
 
        private ServiceRegistration<WebCmsSession> serviceRegistration;
 
-       public WebCmsSessionImpl(String id, Authorization authorization) {
-               this.id = id;
+       public WebCmsSessionImpl(String sessionId, Authorization authorization) {
+               this.id = sessionId;
                this.authorization = authorization;
+               // register as service
+               Hashtable<String, String> props = new Hashtable<>();
+               props.put(WebCmsSession.CMS_DN, authorization.getName());
+               props.put(WebCmsSession.CMS_SESSION_ID, sessionId);
+               serviceRegistration = bc.registerService(WebCmsSession.class, this, props);
        }
 
        public void cleanUp() {
@@ -40,7 +49,10 @@ public class WebCmsSessionImpl implements WebCmsSession {
                return authorization;
        }
 
-       @Override
+       public ServiceRegistration<WebCmsSession> getServiceRegistration() {
+               return serviceRegistration;
+       }
+
        public void addHttpSession(HttpServletRequest request) {
                subHttpSessions.add(new SubHttpSession(request));
        }
@@ -49,10 +61,6 @@ public class WebCmsSessionImpl implements WebCmsSession {
                return id;
        }
 
-       public void setServiceRegistration(ServiceRegistration<WebCmsSession> serviceRegistration) {
-               this.serviceRegistration = serviceRegistration;
-       }
-
        public String toString() {
                return "CMS Session #" + id;
        }
@@ -60,16 +68,16 @@ public class WebCmsSessionImpl implements WebCmsSession {
        static class SubHttpSession {
                private final HttpSession httpSession;
                private final String sessionId;
-//             private final String originalURI;
-//             private final String servletPath;
+               // private final String originalURI;
+               // private final String servletPath;
 
                private final Date start = new Date();
 
                public SubHttpSession(HttpServletRequest request) {
                        this.httpSession = request.getSession();
                        this.sessionId = httpSession.getId();
-//                     this.originalURI = request.getRequestURI();
-//                     this.servletPath = request.getServletPath();
+                       // this.originalURI = request.getRequestURI();
+                       // this.servletPath = request.getServletPath();
                }
 
                public Date getStart() {
@@ -79,7 +87,7 @@ public class WebCmsSessionImpl implements WebCmsSession {
                public void cleanUp() {
                        try {
                                httpSession.setAttribute(HttpContext.AUTHORIZATION, null);
-                               //httpSession.setMaxInactiveInterval(1);
+                               // httpSession.setMaxInactiveInterval(1);
                        } catch (Exception e) {
                                log.warn("Could not clean up " + sessionId, e);
                        }