1 /** 2 * 3 * Copyright 2003-2004 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.geronimo.tomcat.interceptor; 18 19 import java.util.Set; 20 21 import javax.resource.ResourceException; 22 import javax.servlet.ServletRequest; 23 import javax.servlet.ServletResponse; 24 25 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContextImpl; 26 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext; 27 import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator; 28 29 public class InstanceContextBeforeAfter implements BeforeAfter{ 30 31 private final BeforeAfter next; 32 private final int index; 33 private final Set unshareableResources; 34 private final Set applicationManagedSecurityResources; 35 private final TrackedConnectionAssociator trackedConnectionAssociator; 36 37 public InstanceContextBeforeAfter(BeforeAfter next, int index, Set unshareableResources, Set applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator) { 38 this.next = next; 39 this.index = index; 40 this.unshareableResources = unshareableResources; 41 this.applicationManagedSecurityResources = applicationManagedSecurityResources; 42 this.trackedConnectionAssociator = trackedConnectionAssociator; 43 } 44 45 public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) { 46 try { 47 context[index] = trackedConnectionAssociator.enter(new ConnectorInstanceContextImpl(unshareableResources, applicationManagedSecurityResources)); 48 } catch (ResourceException e) { 49 throw new RuntimeException(e); 50 } 51 if (next != null) { 52 next.before(context, httpRequest, httpResponse); 53 } 54 } 55 56 public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) { 57 if (next != null) { 58 next.after(context, httpRequest, httpResponse); 59 } 60 try { 61 trackedConnectionAssociator.exit((ConnectorInstanceContext) context[index]); 62 } catch (ResourceException e) { 63 throw new RuntimeException(e); 64 } 65 } 66 }