geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r374759 - in /geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat: ./ interceptor/ listener/ realm/ valve/
Date Fri, 03 Feb 2006 22:06:38 GMT
Author: jgenender
Date: Fri Feb  3 14:06:34 2006
New Revision: 374759

URL: http://svn.apache.org/viewcvs?rev=374759&view=rev
Log:
Added BeforeAfters for cross context and a listener

Added:
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
Removed:
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/ComponentContextValve.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/InstanceContextValve.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/PolicyContextValve.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/TransactionContextValve.java
Modified:
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=374759&r1=374758&r2=374759&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Fri Feb  3 14:06:34 2006
@@ -20,6 +20,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+
 import javax.naming.NamingException;
 import javax.security.auth.Subject;
 import javax.security.jacc.PolicyContext;
@@ -34,27 +35,28 @@
 import org.apache.catalina.cluster.CatalinaCluster;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
-import org.apache.catalina.valves.ValveBase;
 import org.apache.catalina.core.StandardContext;
+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.kernel.StoredObject;
+import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
 import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
 import org.apache.geronimo.naming.reference.KernelAwareReference;
-import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
 import org.apache.geronimo.security.ContextManager;
 import org.apache.geronimo.security.IdentificationPrincipal;
 import org.apache.geronimo.security.SubjectId;
 import org.apache.geronimo.security.deploy.DefaultPrincipal;
 import org.apache.geronimo.security.util.ConfigurationUtil;
+import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
+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.TransactionContextBeforeAfter;
 import org.apache.geronimo.tomcat.util.SecurityHolder;
-import org.apache.geronimo.tomcat.valve.ComponentContextValve;
 import org.apache.geronimo.tomcat.valve.DefaultSubjectValve;
-import org.apache.geronimo.tomcat.valve.InstanceContextValve;
-import org.apache.geronimo.tomcat.valve.PolicyContextValve;
-import org.apache.geronimo.tomcat.valve.TransactionContextValve;
+import org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve;
 import org.apache.geronimo.transaction.context.TransactionContextManager;
 import org.apache.geronimo.webservices.POJOWebServiceServlet;
 import org.apache.geronimo.webservices.WebServiceContainer;
@@ -72,7 +74,10 @@
     private Map webServiceMap = null;
 
     private boolean pipelineInitialized;
-
+    
+    private BeforeAfter beforeAfter = null;
+    private int contextCount = 0;
+    
     public void setContextProperties(TomcatContext ctx) throws DeploymentException {
         // Create ReadOnlyContext
         javax.naming.Context enc = null;
@@ -93,28 +98,25 @@
         } catch (NamingException ne) {
             log.error(ne);
         }
+        
+        int index = 0;
+        BeforeAfter interceptor = new InstanceContextBeforeAfter(null, index++, 
+                ctx.getUnshareableResources(), 
+                ctx.getApplicationManagedSecurityResources(), 
+                ctx.getTrackedConnectionAssociator());
 
-        //Set the InstanceContextValve
-        InstanceContextValve instanceContextValve =
-                new InstanceContextValve(ctx.getUnshareableResources(),
-                        ctx.getApplicationManagedSecurityResources(),
-                        ctx.getTrackedConnectionAssociator());
-        addValve(instanceContextValve);
-
-        // Set ComponentContext valve
+        // Set ComponentContext BeforeAfter
         if (enc != null) {
-            ComponentContextValve contextValve = new ComponentContextValve(enc);
-            addValve(contextValve);
+            interceptor = new ComponentContextBeforeAfter(interceptor, index++, enc);
         }
 
-        // Set TransactionContextValve
+        // Set TransactionContext BeforeAfter
         TransactionContextManager transactionContextManager = ctx.getTransactionContextManager();
         if (transactionContextManager != null) {
-            TransactionContextValve transactionValve = new TransactionContextValve(transactionContextManager);
-            addValve(transactionValve);
+            interceptor = new TransactionContextBeforeAfter(interceptor, index++, transactionContextManager);
         }
 
-        //Set a PolicyContext Valve
+        //Set a PolicyContext BeforeAfter
         SecurityHolder securityHolder = ctx.getSecurityHolder();
         if (securityHolder != null) {
             if (securityHolder.getPolicyContextID() != null) {
@@ -132,11 +134,16 @@
                     defaultSubject.getPrincipals().add(new IdentificationPrincipal(id));
                 }
 
-                PolicyContextValve policyValve = new PolicyContextValve(securityHolder.getPolicyContextID());
-                addValve(policyValve);
+                interceptor = new PolicyContextBeforeAfter(interceptor, index++, securityHolder.getPolicyContextID());
             }
         }
-
+        
+        //Set the BeforeAfters as a valve
+        GeronimoBeforeAfterValve geronimoBAValve = new GeronimoBeforeAfterValve(interceptor,
index);
+        addValve(geronimoBAValve);
+        beforeAfter = interceptor;
+        contextCount = index;
+        
         //Not clear if user defined valves should be involved in init processing.  Probably
not since
         //request and response are null.
 
@@ -176,6 +183,7 @@
                 valve.invoke(null, null);
                 //Install the DefaultSubjectValve after the authentication valve so the default
subject is supplied
                 //only if no real subject is authenticated.
+                
                 Valve defaultSubjectValve = new DefaultSubjectValve(defaultSubject);
                 addValve(defaultSubjectValve);
             } catch (IOException e) {
@@ -267,4 +275,14 @@
 
         }
     }
+
+
+    public BeforeAfter getBeforeAfter() {
+        return beforeAfter;
+    }
+
+    public int getContextCount() {
+        return contextCount;
+    }
+
 }

Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java?rev=374759&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
(added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
Fri Feb  3 14:06:34 2006
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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;
+
+public interface BeforeAfter {
+    
+    void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse);
+
+    void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse);
+
+}

Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java?rev=374759&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
(added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
Fri Feb  3 14:06:34 2006
@@ -0,0 +1,51 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.naming.Context;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.geronimo.naming.java.RootContext;
+
+public class ComponentContextBeforeAfter implements BeforeAfter{
+    private final BeforeAfter next;
+    private final int index;
+    private final Context componentContext;
+
+    public ComponentContextBeforeAfter(BeforeAfter next, int index, Context componentContext)
{
+        this.next = next;
+        this.index = index;
+        this.componentContext = componentContext;
+    }
+
+    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+        context[index] = RootContext.getComponentContext();
+        RootContext.setComponentContext(componentContext);
+        if (next != null) {
+            next.before(context, httpRequest, httpResponse);
+        }
+    }
+
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+        if (next != null) {
+            next.after(context, httpRequest, httpResponse);
+        }
+        RootContext.setComponentContext((Context) context[index]);
+    }
+
+}

Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java?rev=374759&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
(added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
Fri Feb  3 14:06:34 2006
@@ -0,0 +1,66 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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 java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.geronimo.transaction.DefaultInstanceContext;
+import org.apache.geronimo.transaction.InstanceContext;
+import org.apache.geronimo.transaction.TrackedConnectionAssociator;
+
+public class InstanceContextBeforeAfter implements BeforeAfter{
+    
+    private final BeforeAfter next;
+    private final int index;
+    private final Set unshareableResources;
+    private final Set applicationManagedSecurityResources;
+    private final TrackedConnectionAssociator trackedConnectionAssociator;
+
+    public InstanceContextBeforeAfter(BeforeAfter next, int index, Set unshareableResources,
Set applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator)
{
+        this.next = next;
+        this.index = index;
+        this.unshareableResources = unshareableResources;
+        this.applicationManagedSecurityResources = applicationManagedSecurityResources;
+        this.trackedConnectionAssociator = trackedConnectionAssociator;
+    }
+
+    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+        try {
+            context[index] = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources,
applicationManagedSecurityResources));
+        } catch (ResourceException e) {
+            throw new RuntimeException(e);
+        }
+        if (next != null) {
+            next.before(context, httpRequest, httpResponse);
+        }
+    }
+
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+        if (next != null) {
+            next.after(context, httpRequest, httpResponse);
+        }
+        try {
+            trackedConnectionAssociator.exit((InstanceContext) context[index]);
+        } catch (ResourceException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java?rev=374759&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
(added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
Fri Feb  3 14:06:34 2006
@@ -0,0 +1,85 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.security.auth.Subject;
+import javax.security.jacc.PolicyContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.catalina.connector.Request;
+
+public class PolicyContextBeforeAfter implements BeforeAfter{
+    
+    private final BeforeAfter next;
+    private final String policyContextID;
+    private final int policyContextIDIndex;
+
+    public PolicyContextBeforeAfter(BeforeAfter next, int policyContextIDIndex, String policyContextID)
{
+        this.next = next;
+        this.policyContextIDIndex = policyContextIDIndex;
+        this.policyContextID = policyContextID;
+    }
+
+    public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+        
+        //Save the old
+        PolicyObject policyObject = new PolicyObject();
+        policyObject.setContextId(PolicyContext.getContextID());
+        //policyObject.setRequest(TomcatGeronimoRealm.setRequest(httpRequest));
+        context[policyContextIDIndex] = policyObject;
+        
+        //Set the new
+        PolicyContext.setContextID(policyContextID);
+        PolicyContext.setHandlerData(httpRequest);
+        
+        if (next != null) {
+            next.before(context, httpRequest, httpResponse);
+        }
+    }
+
+    public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse)
{
+        if (next != null) {
+            next.after(context, httpRequest, httpResponse);
+        }
+        
+        //Replace the old
+        PolicyObject policyObject = (PolicyObject)context[policyContextIDIndex];
+        
+        PolicyContext.setContextID(policyObject.getContextId());
+        //TomcatGeronimoRealm.setRequest(policyObject.getRequest());
+    }
+    
+    class PolicyObject{
+        private String contextId = null;
+        private Request request = null;
+        
+        public String getContextId() {
+            return contextId;
+        }
+        public void setContextId(String contextId) {
+            this.contextId = contextId;
+        }
+        public Request getRequest() {
+            return request;
+        }
+        public void setRequest(Request request) {
+            this.request = request;
+        }
+    }
+
+}

Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java?rev=374759&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java
(added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java
Fri Feb  3 14:06:34 2006
@@ -0,0 +1,132 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import org.apache.geronimo.transaction.context.TransactionContext;
+import org.apache.geronimo.transaction.context.TransactionContextManager;
+
+public class TransactionContextBeforeAfter implements BeforeAfter {
+    private final BeforeAfter next;
+
+    private final int txIndex;
+
+    private final TransactionContextManager transactionContextManager;
+
+    public TransactionContextBeforeAfter(BeforeAfter next, int txIndex,
+            TransactionContextManager transactionContextManager) {
+        this.next = next;
+        this.txIndex = txIndex;
+        this.transactionContextManager = transactionContextManager;
+    }
+
+    public void before(Object[] context, ServletRequest httpRequest,
+            ServletResponse httpResponse) {
+        TransactionContextHolder tch = new TransactionContextHolder();
+        TransactionContext oldTransactionContext = transactionContextManager
+                .getContext();
+        TransactionContext newTransactionContext = null;
+        if (oldTransactionContext == null
+                || !oldTransactionContext.isInheritable()) {
+            newTransactionContext = transactionContextManager
+                    .newUnspecifiedTransactionContext();
+        }
+        
+        tch.setOldContext(oldTransactionContext);
+        tch.setNewContext(newTransactionContext);
+        context[txIndex] = tch;
+
+        if (next != null) {
+            next.before(context, httpRequest, httpResponse);
+        }
+    }
+
+    public void after(Object[] context, ServletRequest httpRequest,
+            ServletResponse httpResponse) {
+        try {
+            if (next != null) {
+                next.after(context, httpRequest, httpResponse);
+            }
+        } finally {
+            TransactionContextHolder tch = (TransactionContextHolder) context[txIndex];
+            TransactionContext oldTransactionContext = tch.getOldContext();
+            TransactionContext newTransactionContext = tch.getNewContext();
+            try {
+                if (newTransactionContext != null) {
+                    if (newTransactionContext != transactionContextManager
+                            .getContext()) {
+                        transactionContextManager.getContext().rollback();
+                        newTransactionContext.rollback();
+                        throw new RuntimeException(
+                                "WRONG EXCEPTION! returned from servlet call with wrong tx
context");
+                    }
+                    newTransactionContext.commit();
+
+                } else {
+                    if (oldTransactionContext != transactionContextManager
+                            .getContext()) {
+                        if (transactionContextManager.getContext() != null) {
+                            transactionContextManager.getContext().rollback();
+                        }
+                        throw new RuntimeException(
+                                "WRONG EXCEPTION! returned from servlet call with wrong tx
context");
+                    }
+                }
+            } catch (SystemException e) {
+                throw new RuntimeException("WRONG EXCEPTION!", e);
+            } catch (HeuristicMixedException e) {
+                throw new RuntimeException("WRONG EXCEPTION!", e);
+            } catch (HeuristicRollbackException e) {
+                throw new RuntimeException("WRONG EXCEPTION!", e);
+            } catch (RollbackException e) {
+                throw new RuntimeException("WRONG EXCEPTION!", e);
+            } finally {
+                // this is redundant when we enter with an inheritable context
+                // and nothing goes wrong.
+                transactionContextManager.setContext(oldTransactionContext);
+            }
+        }
+    }
+
+    class TransactionContextHolder {
+        private TransactionContext oldContext;
+
+        private TransactionContext newContext;
+
+        public TransactionContext getNewContext() {
+            return newContext;
+        }
+
+        public void setNewContext(TransactionContext newContext) {
+            this.newContext = newContext;
+        }
+
+        public TransactionContext getOldContext() {
+            return oldContext;
+        }
+
+        public void setOldContext(TransactionContext oldContext) {
+            this.oldContext = oldContext;
+        }
+    }
+}

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java?rev=374759&r1=374758&r2=374759&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
Fri Feb  3 14:06:34 2006
@@ -1,29 +1,80 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.listener;
 
+import java.util.Stack;
+
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
+import org.apache.catalina.Container;
 import org.apache.catalina.InstanceEvent;
 import org.apache.catalina.InstanceListener;
+import org.apache.geronimo.tomcat.GeronimoStandardContext;
+import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
+
+public class DispatchListener implements InstanceListener {
 
-public class DispatchListener implements InstanceListener{
+    //private static StackThreadLocal currentContext = new ThreadLocal();
+    private static ThreadLocal currentContext = new ThreadLocal() {
+        protected Object initialValue() {
+            return new Stack();
+        }
+    };
 
     public void instanceEvent(InstanceEvent event) {
-        
-        if (event.equals(event.BEFORE_DISPATCH_EVENT)){
-            beforeDispatch(event.getRequest(), event.getResponse());
+
+        if (event.getType().equals(InstanceEvent.BEFORE_DISPATCH_EVENT)) {
+
+            Container parent = event.getWrapper().getParent();
+            if (parent instanceof GeronimoStandardContext) {
+                beforeDispatch((GeronimoStandardContext) parent, event
+                        .getRequest(), event.getResponse());
+            }
         }
-        if (event.equals(event.AFTER_DISPATCH_EVENT)){
-            afterDispatch(event.getRequest(), event.getResponse());
+
+        if (event.getType().equals(InstanceEvent.AFTER_DISPATCH_EVENT)) {
+            Container parent = event.getWrapper().getParent();
+            if (parent instanceof GeronimoStandardContext) {
+                afterDispatch((GeronimoStandardContext) parent, event
+                        .getRequest(), event.getResponse());
+            }
         }
     }
-    
-    private void beforeDispatch(ServletRequest request, ServletResponse respons){
-        
+
+    private void beforeDispatch(GeronimoStandardContext webContext,
+            ServletRequest request, ServletResponse response) {
+        BeforeAfter beforeAfter = webContext.getBeforeAfter();
+        if (beforeAfter != null) {
+            Stack stack = (Stack) currentContext.get();
+            Object context[] = new Object[webContext.getContextCount()];
+            beforeAfter.before(context, request, response);
+            stack.push(context);
+        }
     }
-    
-    private void afterDispatch(ServletRequest request, ServletResponse respons){
-        
+
+    private void afterDispatch(GeronimoStandardContext webContext,
+            ServletRequest request, ServletResponse response) {
+        BeforeAfter beforeAfter = webContext.getBeforeAfter();
+        if (beforeAfter != null) {
+            Stack stack = (Stack) currentContext.get();
+            Object context[] = (Object[]) stack.pop();
+            beforeAfter.after(context, request, response);
+        }
     }
 
 }

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java?rev=374759&r1=374758&r2=374759&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
Fri Feb  3 14:06:34 2006
@@ -44,6 +44,8 @@
 import javax.security.jacc.WebResourcePermission;
 import javax.security.jacc.WebRoleRefPermission;
 import javax.security.jacc.WebUserDataPermission;
+import javax.servlet.ServletRequest;
+
 import java.io.IOException;
 import java.security.AccessControlContext;
 import java.security.AccessControlException;
@@ -71,11 +73,11 @@
 
      }
 
-    public static Request setRequest(Request request) {
-        Request old = (Request) currentRequest.get();
-        currentRequest.set(request);
-        return old;
-    }
+//    public static ServletRequest setRequest(Request request) {
+//        ServletRequest old = (ServletRequest) currentRequest.get();
+//        currentRequest.set(request);
+//        return old;
+//    }
 
     /**
      * Enforce any user data constraint required by the security constraint
@@ -178,6 +180,8 @@
                 return (true);
             }
         }
+        
+        currentRequest.set(request);
 
         // Which user principal have we already authenticated?
         Principal principal = request.getUserPrincipal();

Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java?rev=374759&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
(added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
Fri Feb  3 14:06:34 2006
@@ -0,0 +1,39 @@
+package org.apache.geronimo.tomcat.valve;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import org.apache.catalina.Valve;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.valves.ValveBase;
+import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
+
+public class GeronimoBeforeAfterValve extends ValveBase{
+    
+    private final BeforeAfter beforeAfter;
+    private final int contextIndexCount;
+
+    public GeronimoBeforeAfterValve(BeforeAfter beforeAfter, int contextIndexCount) {
+        this.beforeAfter = beforeAfter;
+        this.contextIndexCount = contextIndexCount;
+    }
+
+    public void invoke(Request request, Response response) throws IOException, ServletException
{
+        Object context[] = new Object[contextIndexCount];
+        
+        if (beforeAfter != null){
+            beforeAfter.before(context, request, response);
+        }
+        
+        // Pass this request on to the next valve in our pipeline
+        getNext().invoke(request, response);
+        
+        if (beforeAfter != null){
+            beforeAfter.after(context, request, response);
+        }
+        
+    }
+
+}



Mime
View raw message