1 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.TrackedConnectionAssociator; 26 import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext; 27 28 public class InstanceContextBeforeAfter implements BeforeAfter{ 29 30 private final BeforeAfter next; 31 private final int oldIndex; 32 private final int newIndex; 33 private final Set unshareableResources; 34 private final Set applicationManagedSecurityResources; 35 private final TrackedConnectionAssociator trackedConnectionAssociator; 36 37 public InstanceContextBeforeAfter(BeforeAfter next, int oldIndex, int newIndex, Set unshareableResources, Set applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator) { 38 this.next = next; 39 this.oldIndex = oldIndex; 40 this.newIndex = newIndex; 41 this.unshareableResources = unshareableResources; 42 this.applicationManagedSecurityResources = applicationManagedSecurityResources; 43 this.trackedConnectionAssociator = trackedConnectionAssociator; 44 } 45 46 public void before(Object [] context, ServletRequest httpRequest, ServletResponse httpResponse) { 47 try { 48 SharedConnectorInstanceContext newConnectorInstanceContext = new SharedConnectorInstanceContext(unshareableResources, applicationManagedSecurityResources, false); 49 SharedConnectorInstanceContext oldContext = (SharedConnectorInstanceContext) trackedConnectionAssociator.enter(newConnectorInstanceContext); 50 if (oldContext != null) { 51 newConnectorInstanceContext.share(oldContext); 52 } 53 context[oldIndex] = oldContext; 54 context[newIndex] = newConnectorInstanceContext; 55 } catch (ResourceException e) { 56 throw new RuntimeException (e); 57 } 58 if (next != null) { 59 next.before(context, httpRequest, httpResponse); 60 } 61 } 62 63 public void after(Object [] context, ServletRequest httpRequest, ServletResponse httpResponse) { 64 if (next != null) { 65 next.after(context, httpRequest, httpResponse); 66 } 67 try { 68 SharedConnectorInstanceContext oldConnectorInstanceContext = (SharedConnectorInstanceContext) context[oldIndex]; 69 SharedConnectorInstanceContext newConnectorInstanceContext = (SharedConnectorInstanceContext) context[newIndex]; 70 if (oldConnectorInstanceContext != null) { 71 newConnectorInstanceContext.hide(); 72 } 73 trackedConnectionAssociator.exit(oldConnectorInstanceContext); 74 } catch (ResourceException e) { 75 throw new RuntimeException (e); 76 } 77 } 78 } 79 | Popular Tags |