You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/03/01 17:42:21 UTC

svn commit: r382078 - /incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java

Author: jboynes
Date: Wed Mar  1 08:42:20 2006
New Revision: 382078

URL: http://svn.apache.org/viewcvs?rev=382078&view=rev
Log:
clean up flow around invoking the application

Modified:
    incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java

Modified: incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java?rev=382078&r1=382077&r2=382078&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java (original)
+++ incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java Wed Mar  1 08:42:20 2006
@@ -28,6 +28,7 @@
 
 import org.apache.tuscany.core.context.AggregateContext;
 import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.context.EventException;
 
 /**
  * Valve that can be added to a pipeline to
@@ -51,36 +52,38 @@
     public void invoke(Request request, Response response) throws IOException, ServletException {
         Object oldRequestId = request.getNote(REQUEST_ID);
         ModuleContext oldContext = CurrentModuleContext.getContext();
-        try {
-            // bind the current module context to the thread
-            BINDER.setContext((ModuleContext) moduleComponentContext);
 
-            // if we have not notified the runtime about this request, fire a request start event
-            if (oldRequestId == null) {
+        // bind the current module context to the thread
+        BINDER.setContext((ModuleContext) moduleComponentContext);
+        try {
+            if (oldRequestId != null) {
+                // the request has already been started, just invoke the next valve
+                next.invoke(request, response);
+            } else {
+                // tell the runtime a new request is starting
                 Object requestId = new Object();
+                try {
+                    moduleComponentContext.fireEvent(EventContext.REQUEST_START, requestId);
+                } catch (Exception e) {
+                    throw new ServletException(e.getMessage(), e);
+                }
                 request.setNote(REQUEST_ID, requestId);
-                moduleComponentContext.fireEvent(EventContext.REQUEST_START, requestId);
-            }
 
-            // invoke the next valve in the pipeline
-            next.invoke(request, response);
-        } catch (IOException e) {
-            // rethrow exception from next valve
-            throw e;
-        } catch (ServletException e) {
-            // rethrow exception from next valve
-            throw e;
-        } catch (Exception e) {
-            // wrap other (unchecked) exceptions potentially thrown by the runtime
-            throw new ServletException(e.getMessage(), e);
-        } finally {
-            // if we sent the request start notification, fire the request end event
-            if (oldRequestId == null) {
-                Object requestId = request.getNote(REQUEST_ID);
-                moduleComponentContext.fireEvent(EventContext.REQUEST_END, requestId);
-                request.removeNote(REQUEST_ID);
+                try {
+                    // invoke the next valve in the pipeline
+                    next.invoke(request, response);
+                } finally{
+                    // notify the runtime the request is ending
+                    request.removeNote(REQUEST_ID);
+                    try {
+                        moduleComponentContext.fireEvent(EventContext.REQUEST_END, requestId);
+                    } catch (Exception e) {
+                        // the application already did its work, log and ignore
+                        // todo log this exception
+                    }
+                }
             }
-
+        } finally {
             // restore the previous module context onto the thread
             BINDER.setContext(oldContext);
         }