incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmatth...@apache.org
Subject svn commit: r1082942 - in /incubator/isis/trunk/viewer/scimpi: dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/ dispatcher/src/main/java/org/apache/isis/...
Date Fri, 18 Mar 2011 15:03:48 GMT
Author: rmatthews
Date: Fri Mar 18 15:03:48 2011
New Revision: 1082942

URL: http://svn.apache.org/viewvc?rev=1082942&view=rev
Log:
Session data is now serializable, so will persist across restarts of Tomcat etc.

Only session data is stored, so almost-simultaneous requests for the same session will not
interfere with each other.

Modified:
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/processor/Request.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java
    incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/DispatcherServlet.java
    incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/ServletRequestContext.java

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java?rev=1082942&r1=1082941&r2=1082942&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
Fri Mar 18 15:03:48 2011
@@ -23,6 +23,7 @@ package org.apache.isis.viewer.scimpi.di
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -206,10 +207,6 @@ public abstract class RequestContext {
         String referrer = getHeader("Referer"); // Note spelling mistake is intentional
         return referrer != null && referrer.contains("localhost");  // TODO need
to look for actual domain
     }
-    
-    public boolean isValid() {
-        return true;
-    }
 
     // //////////////////////////////////////////////////////////////////
     // Version
@@ -347,6 +344,9 @@ public abstract class RequestContext {
 
     public void addVariable(String name, Object value, Scope scope) {
         name = name != null ? name : RESULT;
+        if (scope == Scope.SESSION && !(value instanceof Serializable)) {
+            throw new ScimpiException("SESSION scoped variable (" + name + ") must be serializable:
" + value);
+        }
         removeExistingVariable(name);
         variables.get(scope).put(name, value);
     }
@@ -704,6 +704,8 @@ public abstract class RequestContext {
 
     public abstract String clearSession();
 
+    public abstract boolean isAborted();
+    
     public void setSession(AuthenticationSession session) {
         this.session = session;
     }
@@ -722,6 +724,15 @@ public abstract class RequestContext {
 
     public void setContentType(String string) {}
 
+    public void setSessionData(Map<String, Object> hashMap) {
+        variables.put(Scope.SESSION, hashMap);
+        setSession((AuthenticationSession) getVariable("_auth_session"));
+    }
+    
+    public Map<String, Object> getSessionData() {
+        return variables.get(Scope.SESSION);
+    }
+
     
     public boolean isDebugDisabled() {
         if (debugLevel == null) {

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java?rev=1082942&r1=1082941&r2=1082942&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
Fri Mar 18 15:03:48 2011
@@ -82,7 +82,7 @@ public class DebugView {
         Throwable cause = throwable.getCause();
         if (cause != null && cause != throwable) {
             writer.println("<tr><td colspan=\"2\" >" + cause.getMessage() + "<td></tr>");
-            debug.append(cause.getMessage());
+            debug.appendln(cause.getMessage());
             causingException(cause);
         }
     }

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/processor/Request.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/processor/Request.java?rev=1082942&r1=1082941&r2=1082942&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/processor/Request.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/processor/Request.java
Fri Mar 18 15:03:48 2011
@@ -81,6 +81,9 @@ public class Request implements PageWrit
                 String name = tag.getName();
                 ElementProcessor processor = processors.getFor(name);
                 process(tag, processor);
+                if (context.isAborted()) {
+                    return;
+                }
             }
         }
     }
@@ -201,7 +204,6 @@ public class Request implements PageWrit
             }
         }
         throw new ScimpiException("Empty tag not closed");
-
     }
 
     public void pushNewBuffer() {

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java?rev=1082942&r1=1082941&r2=1082942&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java
Fri Mar 18 15:03:48 2011
@@ -32,6 +32,7 @@ public class Secure extends AbstractElem
     public void process(Request request) {
         boolean isLoggedIn = !(IsisContext.getSession().getAuthenticationSession() instanceof
UserlessSession);
         if (!isLoggedIn) {
+            IsisContext.getMessageBroker().addWarning("You are not currently logged in! Please
log in so you can continue.");
             String view = request.getOptionalProperty(LOGIN_VIEW, "/login.shtml");
             request.getContext().redirectTo(view);
         }

Modified: incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/DispatcherServlet.java?rev=1082942&r1=1082941&r2=1082942&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/DispatcherServlet.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/DispatcherServlet.java
Fri Mar 18 15:03:48 2011
@@ -21,6 +21,7 @@ package org.apache.isis.viewer.scimpi.se
 
 import java.io.IOException;
 import java.util.Enumeration;
+import java.util.HashMap;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -52,17 +53,14 @@ public class DispatcherServlet extends H
     }
 
     private void process(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
-        // TODO: NOF's AuthenticationSession now has its own #getAttribute() and #setAttribute()
methods,
-        // so an alternative is to bind this info onto the AuthSession.
-        // The core/webapp will (hopefully) evolve to define a standard approach here...
         try {
-            ServletRequestContext context = null;
+            ServletRequestContext context = new ServletRequestContext();
             HttpSession httpSession = request.getSession(false);
             if (httpSession != null) {
-                context = (ServletRequestContext) httpSession.getAttribute("scimpi-context");
-            }
-            if (context == null || !context.isValid()) {
-                context = new ServletRequestContext();
+                HashMap<String, Object> data = (HashMap<String, Object>) httpSession.getAttribute("scimpi-context");
+                if (data != null) {
+                    context.setSessionData(data);
+                }
             }
             context.startRequest(request, response, getServletContext());
             dispatcher.process(context, request.getServletPath());
@@ -70,7 +68,6 @@ public class DispatcherServlet extends H
             LOG.error("servlet exception", e);
             throw e;
         }
-
     }
 
     @Override

Modified: incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/ServletRequestContext.java?rev=1082942&r1=1082941&r2=1082942&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/ServletRequestContext.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/servlet/src/main/java/org/apache/isis/viewer/scimpi/servlet/ServletRequestContext.java
Fri Mar 18 15:03:48 2011
@@ -25,6 +25,7 @@ import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.util.Enumeration;
+import java.util.Map;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.Cookie;
@@ -45,6 +46,7 @@ public class ServletRequestContext exten
     private HttpServletRequest request;
     private HttpServletResponse response;
     private ServletContext servletContext;
+    private boolean isAborted;
 
     public void append(DebugView view) {
         /*
@@ -202,8 +204,10 @@ public class ServletRequestContext exten
     }
     
     public void startHttpSession() {
+        addVariable("_auth_session", getSession(), Scope.SESSION);
         HttpSession httpSession = request.getSession(true);
-        httpSession.setAttribute("scimpi-context", this);
+        Map<String, Object> sessionData = getSessionData();
+        httpSession.setAttribute("scimpi-context", sessionData);
     }
 
     protected String getSessionId() {
@@ -217,6 +221,7 @@ public class ServletRequestContext exten
     
     public void redirectTo(String view) {
         try {
+            isAborted = true;
             getResponse().sendRedirect(view);
         } catch (IOException e) {
             throw new DispatchException(e);
@@ -225,6 +230,7 @@ public class ServletRequestContext exten
     
     public void raiseError(int status) {
         try {
+            isAborted = true;
             getResponse().sendError(status);
         } catch (IOException e) {
             throw new RuntimeException(e);
@@ -232,6 +238,10 @@ public class ServletRequestContext exten
         getResponse().setStatus(status);
     }
     
+    public boolean isAborted() {
+        return isAborted;
+    }
+    
     public void setContentType(String string) {
         getResponse().setContentType(string);
     }



Mime
View raw message