Commits

Anonymous committed 1edcd70

WW-239: making SessionMap synchronize access to the Session

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@5573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (2)

src/java/com/opensymphony/webwork/dispatcher/ServletDispatcher.java

             proxy.execute();
         } catch (Exception e) {
             try {
-				// send a http 500 INTERNAL SERVER ERROR to use the servlet defined error handler
-
-				// make the exception availible to the web.xml defined error page
-				request.setAttribute ("javax.servlet.error.exception", e);
-				
-				// for compatibility 
-				request.setAttribute ("javax.servlet.jsp.jspException", e);
-
-				// send the error response
-				response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
-
-/*
-                response.setContentType("text/html");
-                response.setLocale(Configuration.getLocale());
-
-                PrintWriter writer = response.getWriter();
-                writer.write("Error executing action: " + e.getMessage());
-                writer.println("<pre>\n");
-                e.printStackTrace(response.getWriter());
-                writer.print("</pre>\n");
-*/
+                // send a http 500 INTERNAL SERVER ERROR to use the servlet defined error handler
+                // make the exception availible to the web.xml defined error page
+                request.setAttribute("javax.servlet.error.exception", e);
+
+                // for compatibility 
+                request.setAttribute("javax.servlet.jsp.jspException", e);
+
+                // send the error response
+                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+
+                /*
+                                response.setContentType("text/html");
+                                response.setLocale(Configuration.getLocale());
+
+                                PrintWriter writer = response.getWriter();
+                                writer.write("Error executing action: " + e.getMessage());
+                                writer.println("<pre>\n");
+                                e.printStackTrace(response.getWriter());
+                                writer.print("</pre>\n");
+                */
                 log.error("Could not execute action", e);
             } catch (IOException e1) {
             }

src/java/com/opensymphony/webwork/dispatcher/SessionMap.java

     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void clear() {
-        entries = null;
-        session.invalidate();
+        synchronized (session) {
+            entries = null;
+            session.invalidate();
+        }
     }
 
     public Set entrySet() {
-        if (entries == null) {
-            entries = new HashSet();
+        synchronized (session) {
+            if (entries == null) {
+                entries = new HashSet();
 
-            Enumeration enum = session.getAttributeNames();
+                Enumeration enum = session.getAttributeNames();
 
-            while (enum.hasMoreElements()) {
-                final String key = enum.nextElement().toString();
-                final Object value = session.getAttribute(key);
-                entries.add(new Map.Entry() {
-                        public boolean equals(Object obj) {
-                            Map.Entry entry = (Map.Entry) obj;
+                while (enum.hasMoreElements()) {
+                    final String key = enum.nextElement().toString();
+                    final Object value = session.getAttribute(key);
+                    entries.add(new Map.Entry() {
+                            public boolean equals(Object obj) {
+                                Map.Entry entry = (Map.Entry) obj;
 
-                            return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue()));
-                        }
+                                return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue()));
+                            }
 
-                        public int hashCode() {
-                            return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode());
-                        }
+                            public int hashCode() {
+                                return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode());
+                            }
 
-                        public Object getKey() {
-                            return key;
-                        }
+                            public Object getKey() {
+                                return key;
+                            }
 
-                        public Object getValue() {
-                            return value;
-                        }
+                            public Object getValue() {
+                                return value;
+                            }
 
-                        public Object setValue(Object obj) {
-                            session.setAttribute(key.toString(), obj);
+                            public Object setValue(Object obj) {
+                                session.setAttribute(key.toString(), obj);
 
-                            return value;
-                        }
-                    });
+                                return value;
+                            }
+                        });
+                }
             }
         }
 
     }
 
     public Object get(Object key) {
-        return session.getAttribute(key.toString());
+        synchronized (session) {
+            return session.getAttribute(key.toString());
+        }
     }
 
     public Object put(Object key, Object value) {
-        entries = null;
-        session.setAttribute(key.toString(), value);
+        synchronized (session) {
+            entries = null;
+            session.setAttribute(key.toString(), value);
 
-        return get(key);
+            return get(key);
+        }
     }
 
     public Object remove(Object key) {
-        entries = null;
+        synchronized (session) {
+            entries = null;
 
-        Object value = get(key);
-        session.removeAttribute(key.toString());
+            Object value = get(key);
+            session.removeAttribute(key.toString());
 
-        return value;
+            return value;
+        }
     }
 }