geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r534953 - in /geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6: JettyWebAppContext.java handler/UserTransactionHandler.java
Date Thu, 03 May 2007 18:28:15 GMT
Author: djencks
Date: Thu May  3 11:28:14 2007
New Revision: 534953

URL: http://svn.apache.org/viewvc?view=rev&rev=534953
Log:
GERONIMO-3137 untested fix for jetty, rollback a leftover tx on exit

Added:
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java
  (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java?view=diff&rev=534953&r1=534952&r2=534953
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
Thu May  3 11:28:14 2007
@@ -53,6 +53,7 @@
 import org.apache.geronimo.jetty6.handler.JettySecurityHandler;
 import org.apache.geronimo.jetty6.handler.LifecycleCommand;
 import org.apache.geronimo.jetty6.handler.ThreadClassloaderHandler;
+import org.apache.geronimo.jetty6.handler.UserTransactionHandler;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.ObjectNameUtil;
 import org.apache.geronimo.management.J2EEApplication;
@@ -200,6 +201,7 @@
             next = new ThreadClassloaderHandler(next, classLoader);
 
             next = new InstanceContextHandler(next, unshareableResources, applicationManagedSecurityResources,
trackedConnectionAssociator);
+            next = new UserTransactionHandler(next, userTransaction);
             webAppContext.setHandler(next);
 
             //install another component context handler for the lifecycle chain

Added: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java?view=auto&rev=534953
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java
Thu May  3 11:28:14 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.jetty6.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.mortbay.jetty.handler.AbstractHandler;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class UserTransactionHandler extends AbstractImmutableHandler {
+
+    private final UserTransaction userTransaction;
+
+    public UserTransactionHandler(AbstractHandler next, UserTransaction userTransaction)
{
+        super(next);
+        this.userTransaction = userTransaction;
+    }
+
+    public void handle(String target, HttpServletRequest request, HttpServletResponse response,
int dispatch) throws IOException, ServletException {
+        boolean active = isActive();
+        try {
+            next.handle(target, request, response, dispatch);
+        } finally {
+            if (!active && isActive()) {
+                try {
+                    userTransaction.rollback();
+                } catch (SystemException e) {
+                    throw new ServletException("Error rolling back transaction left open
by user program", e);
+                }
+            }
+        }
+    }
+
+    public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception {
+        boolean active = isActive();
+        try {
+            super.lifecycleCommand(lifecycleCommand);
+        } finally {
+            if (!active && isActive()) {
+                try {
+                    userTransaction.rollback();
+                } catch (SystemException e) {
+                    throw new ServletException("Error rolling back transaction left open
by user program", e);
+                }
+            }
+        }
+    }
+
+    private boolean isActive() throws ServletException {
+        try {
+            return !(userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION
+                    || userTransaction.getStatus() == Status.STATUS_COMMITTED);
+        } catch (SystemException e) {
+            throw new ServletException("Could not determine transaction status", e);
+        }
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/handler/UserTransactionHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message