]> source.dussan.org Git - vaadin-framework.git/commitdiff
transactionStart/End and requestStart/End should now always happen in pairs
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 1 Dec 2009 08:50:44 +0000 (08:50 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 1 Dec 2009 08:50:44 +0000 (08:50 +0000)
svn changeset:10114/svn branch:6.2

src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java

index 3d165c2d2e68950a4f91d705da5caa727297536a..5c1396b449df7bf200a3d8fa51ac6d130ae8536d 100644 (file)
@@ -313,6 +313,9 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                     (ResourceResponse) response);
         } else {
             Application application = null;
+            boolean transactionStarted = false;
+            boolean requestStarted = false;
+
             try {
                 // TODO What about PARAM_UNLOADBURST & redirectToApplication??
 
@@ -359,6 +362,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                 if (application instanceof PortletRequestListener) {
                     ((PortletRequestListener) application).onRequestStart(
                             request, response);
+                    requestStarted = true;
                 }
 
                 /* Start the newly created application */
@@ -369,6 +373,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                  * end is called in the finally block below.
                  */
                 applicationContext.startTransaction(application, request);
+                transactionStarted = true;
 
                 /* Notify listeners */
 
@@ -460,15 +465,17 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                 handleServiceException(request, response, application, e);
             } finally {
                 // Notifies transaction end
-                if (application != null) {
-                    ((PortletApplicationContext2) application.getContext())
-                            .endTransaction(application, request);
-
-                    if (application instanceof PortletRequestListener) {
+                try {
+                    if (transactionStarted) {
+                        ((PortletApplicationContext2) application.getContext())
+                                .endTransaction(application, request);
+                    }
+                } finally {
+                    if (requestStarted) {
                         ((PortletRequestListener) application).onRequestEnd(
                                 request, response);
-                    }
 
+                    }
                 }
             }
         }
index fc64ede5bd13f7b17309f03927224ae2cecce3d8..65b587183b8cb8608cfbf48f44ed295336c07aa9 100644 (file)
@@ -369,6 +369,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         }
 
         Application application = null;
+        boolean transactionStarted = false;
+        boolean requestStarted = false;
 
         try {
             // If a duplicate "close application" URL is received for an
@@ -414,6 +416,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
             if (application instanceof HttpServletRequestListener) {
                 ((HttpServletRequestListener) application).onRequestStart(
                         request, response);
+                requestStarted = true;
             }
 
             // Start the newly created application
@@ -424,6 +427,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
              * is called in the finally block below.
              */
             webApplicationContext.startTransaction(application, request);
+            transactionStarted = true;
 
             /* Handle the request */
             if (requestType == RequestType.FILE_UPLOAD) {
@@ -480,14 +484,19 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
             handleServiceException(request, response, application, e);
         } finally {
             // Notifies transaction end
-            if (application != null) {
-                ((WebApplicationContext) application.getContext())
-                        .endTransaction(application, request);
+            try {
+                if (transactionStarted) {
+                    ((WebApplicationContext) application.getContext())
+                            .endTransaction(application, request);
 
-                if (application instanceof HttpServletRequestListener) {
+                }
+
+            } finally {
+                if (requestStarted) {
                     ((HttpServletRequestListener) application).onRequestEnd(
                             request, response);
                 }
+
             }
 
         }