1 17 18 19 package org.apache.geronimo.jetty6.handler; 20 21 import java.io.IOException ; 22 import java.util.Set ; 23 24 import javax.resource.ResourceException ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext; 30 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContextImpl; 31 import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext; 32 import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator; 33 import org.mortbay.jetty.Handler; 34 import org.mortbay.jetty.handler.AbstractHandler; 35 36 39 public class InstanceContextHandler extends AbstractImmutableHandler { 40 41 private final Set unshareableResources; 42 private final Set applicationManagedSecurityResources; 43 private final TrackedConnectionAssociator trackedConnectionAssociator; 44 45 public InstanceContextHandler(AbstractHandler next, Set unshareableResources, Set applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator) { 46 super(next); 47 this.unshareableResources = unshareableResources; 48 this.applicationManagedSecurityResources = applicationManagedSecurityResources; 49 this.trackedConnectionAssociator = trackedConnectionAssociator; 50 } 51 52 public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException , ServletException { 53 try { 54 if (dispatch == Handler.REQUEST) { 55 ConnectorInstanceContext oldContext = trackedConnectionAssociator.enter(new SharedConnectorInstanceContext(unshareableResources, applicationManagedSecurityResources, false)); 56 57 try { 58 next.handle(target, request, response, dispatch); 59 } finally { 60 trackedConnectionAssociator.exit(oldContext); 61 } 62 } else { 63 SharedConnectorInstanceContext context = new SharedConnectorInstanceContext(unshareableResources, applicationManagedSecurityResources, true); 64 SharedConnectorInstanceContext oldContext = (SharedConnectorInstanceContext) trackedConnectionAssociator.enter(context); 65 context.share(oldContext); 66 try { 67 next.handle(target, request, response, dispatch); 68 } finally { 69 context.hide(); 70 trackedConnectionAssociator.exit(oldContext); 71 } 72 } 73 } catch (ResourceException e) { 74 throw new ServletException (e); 75 } 76 } 77 78 public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception { 79 ConnectorInstanceContext oldContext = trackedConnectionAssociator.enter(new ConnectorInstanceContextImpl(unshareableResources, applicationManagedSecurityResources)); 80 try { 81 super.lifecycleCommand(lifecycleCommand); 82 } finally { 83 trackedConnectionAssociator.exit(oldContext); 84 } 85 } 86 } 87 | Popular Tags |