geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r536105 - in /geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat: ./ interceptor/ listener/ valve/
Date Tue, 08 May 2007 07:01:09 GMT
Author: jgenender
Date: Tue May  8 00:01:08 2007
New Revision: 536105

URL: http://svn.apache.org/viewvc?view=rev&rev=536105
Log:
Add User Transaction handling

Added:
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/UserTransactionBeforeAfter.java
Modified:
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?view=diff&rev=536105&r1=536104&r2=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Tue May  8 00:01:08 2007
@@ -38,8 +38,6 @@
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.ha.CatalinaCluster;
 import org.apache.catalina.valves.ValveBase;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.common.GeronimoSecurityException;
 import org.apache.geronimo.security.ContextManager;
@@ -51,6 +49,7 @@
 import org.apache.geronimo.tomcat.interceptor.ComponentContextBeforeAfter;
 import org.apache.geronimo.tomcat.interceptor.InstanceContextBeforeAfter;
 import org.apache.geronimo.tomcat.interceptor.PolicyContextBeforeAfter;
+import org.apache.geronimo.tomcat.interceptor.UserTransactionBeforeAfter;
 import org.apache.geronimo.tomcat.util.SecurityHolder;
 import org.apache.geronimo.tomcat.valve.DefaultSubjectValve;
 import org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve;
@@ -134,6 +133,9 @@
 
             }
         }
+        
+        //Set a UserTransactionBeforeAfter
+        interceptor = new UserTransactionBeforeAfter(interceptor, index++, ctx.getUserTransaction());
 
         //Set the BeforeAfters as a valve
         GeronimoBeforeAfterValve geronimoBAValve = new GeronimoBeforeAfterValve(interceptor,
index);

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java?view=diff&rev=536105&r1=536104&r2=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
Tue May  8 00:01:08 2007
@@ -20,9 +20,13 @@
 import javax.servlet.ServletResponse;
 
 public interface BeforeAfter {
-    
-    void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse);
 
-    void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse);
+    public static final int DEFAULT = 0;
+
+    public static final int DISPATCHED = 1;
+
+    void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch);
+
+    void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch);
 
 }

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java?view=diff&rev=536105&r1=536104&r2=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
Tue May  8 00:01:08 2007
@@ -33,17 +33,17 @@
         this.componentContext = componentContext;
     }
 
-    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch) {
         context[index] = RootContext.getComponentContext();
         RootContext.setComponentContext(componentContext);
         if (next != null) {
-            next.before(context, httpRequest, httpResponse);
+            next.before(context, httpRequest, httpResponse, 0);
         }
     }
 
-    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch) {
         if (next != null) {
-            next.after(context, httpRequest, httpResponse);
+            next.after(context, httpRequest, httpResponse, 0);
         }
         RootContext.setComponentContext((Context) context[index]);
     }

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java?view=diff&rev=536105&r1=536104&r2=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
Tue May  8 00:01:08 2007
@@ -43,7 +43,7 @@
         this.trackedConnectionAssociator = trackedConnectionAssociator;
     }
 
-    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch) {
         try {
             SharedConnectorInstanceContext newConnectorInstanceContext = new SharedConnectorInstanceContext(unshareableResources,
applicationManagedSecurityResources, false);
             SharedConnectorInstanceContext oldContext = (SharedConnectorInstanceContext)
trackedConnectionAssociator.enter(newConnectorInstanceContext);
@@ -56,13 +56,13 @@
             throw new RuntimeException(e);
         }
         if (next != null) {
-            next.before(context, httpRequest, httpResponse);
+            next.before(context, httpRequest, httpResponse, dispatch);
         }
     }
 
-    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch) {
         if (next != null) {
-            next.after(context, httpRequest, httpResponse);
+            next.after(context, httpRequest, httpResponse, dispatch);
         }
         try {
             SharedConnectorInstanceContext oldConnectorInstanceContext = (SharedConnectorInstanceContext)
context[oldIndex];

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java?view=diff&rev=536105&r1=536104&r2=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
Tue May  8 00:01:08 2007
@@ -44,7 +44,7 @@
         this.defaultSubject = defaultSubject;
     }
 
-    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch) {
 
         //Save the old
 
@@ -61,13 +61,13 @@
 
 
         if (next != null) {
-            next.before(context, httpRequest, httpResponse);
+            next.before(context, httpRequest, httpResponse, dispatch);
         }
     }
 
-    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch) {
         if (next != null) {
-            next.after(context, httpRequest, httpResponse);
+            next.after(context, httpRequest, httpResponse, dispatch);
         }
 
         //Replace the old

Added: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/UserTransactionBeforeAfter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/UserTransactionBeforeAfter.java?view=auto&rev=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/UserTransactionBeforeAfter.java
(added)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/interceptor/UserTransactionBeforeAfter.java
Tue May  8 00:01:08 2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.tomcat.interceptor;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class UserTransactionBeforeAfter implements BeforeAfter {
+    private static Log log = LogFactory.getLog(UserTransactionBeforeAfter.class);
+
+    private final UserTransaction userTransaction;
+
+    private final BeforeAfter next;
+
+    private final int index;
+
+    public UserTransactionBeforeAfter(BeforeAfter next, int index, UserTransaction userTransaction)
{
+        this.next = next;
+        this.index = index;
+        this.userTransaction = userTransaction;
+    }
+
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse,
int dispatch) {
+        if (next != null) {
+            next.after(context, httpRequest, httpResponse, dispatch);
+        }
+        
+        boolean active = (Boolean)context[index];
+        if ((!active && isMarkedRollback()) || (dispatch != DISPATCHED &&
isActive())) {
+            try {
+                userTransaction.rollback();
+            } catch (SystemException e) {
+                throw new RuntimeException("Error rolling back transaction left open by user
program", e);
+            }
+        }
+
+    }
+
+    public void before(Object[] context, ServletRequest request, ServletResponse response,
int dispatch) {
+        context[index] = isActive();
+        next.before(context, request, response, dispatch);
+    }
+
+    private boolean isActive() {
+        try {
+            return !(userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION || userTransaction.getStatus()
== Status.STATUS_COMMITTED);
+        } catch (SystemException e) {
+            log.error("Could not determine transaction status", e);
+            throw new RuntimeException("Could not determine transaction status", e);
+        }
+    }
+
+    private boolean isMarkedRollback() {
+        try {
+            return userTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK;
+        } catch (SystemException e) {
+            log.error("Could not determine transaction status", e);
+            throw new RuntimeException("Could not determine transaction status", e);
+        }
+    }
+}

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/listener/DispatchListener.java?view=diff&rev=536105&r1=536104&r2=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
Tue May  8 00:01:08 2007
@@ -70,7 +70,7 @@
             String wrapperName = getWrapperName(request, webContext);
             context[webContext.getContextCount()] = TomcatGeronimoRealm.setRequestWrapperName(wrapperName);
 
-            beforeAfter.before(context, request, response);
+            beforeAfter.before(context, request, response, BeforeAfter.DISPATCHED);
 
             stack.push(context);
         }
@@ -83,7 +83,7 @@
             Stack stack = (Stack) currentContext.get();
             Object context[] = (Object[]) stack.pop();
 
-            beforeAfter.after(context, request, response);
+            beforeAfter.after(context, request, response, BeforeAfter.DISPATCHED);
 
             TomcatGeronimoRealm.setRequestWrapperName((String) context[webContext.getContextCount()]);
         }

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java?view=diff&rev=536105&r1=536104&r2=536105
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
Tue May  8 00:01:08 2007
@@ -40,14 +40,14 @@
         Object context[] = new Object[contextIndexCount];
         
         if (beforeAfter != null){
-            beforeAfter.before(context, request, response);
+            beforeAfter.before(context, request, response, BeforeAfter.DEFAULT);
         }
         
         // Pass this request on to the next valve in our pipeline
         getNext().invoke(request, response);
         
         if (beforeAfter != null){
-            beforeAfter.after(context, request, response);
+            beforeAfter.after(context, request, response, 0);
         }
         
     }



Mime
View raw message