1 17 18 19 package org.apache.geronimo.jetty6; 20 21 import java.io.IOException ; 22 23 import javax.servlet.ServletRequest ; 24 import javax.servlet.ServletResponse ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.UnavailableException ; 27 import javax.security.auth.Subject ; 28 29 import org.mortbay.jetty.servlet.ServletHolder; 30 import org.apache.geronimo.jetty6.handler.AbstractImmutableHandler; 31 import org.apache.geronimo.jetty6.handler.LifecycleCommand; 32 import org.apache.geronimo.security.Callers; 33 import org.apache.geronimo.security.ContextManager; 34 35 38 public class InternalJettyServletHolder extends ServletHolder { 39 40 private static final ThreadLocal <String > currentServletName = new ThreadLocal <String >(); 41 42 private final AbstractImmutableHandler lifecycleChain; 43 private final Subject runAsSubject; 44 45 public InternalJettyServletHolder(AbstractImmutableHandler lifecycleChain, Subject runAsSubject) { 46 this.lifecycleChain = lifecycleChain; 47 this.runAsSubject = runAsSubject; 48 } 49 50 52 56 public void handle(ServletRequest request, ServletResponse response) 57 throws ServletException , UnavailableException , IOException { 58 String oldServletName = getCurrentServletName(); 59 setCurrentServletName(getName()); 60 try { 61 if (runAsSubject == null) { 62 super.handle(request, response); 63 } else { 64 Callers oldCallers = ContextManager.pushNextCaller(runAsSubject); 65 try { 66 super.handle(request, response); 67 } finally { 68 ContextManager.popCallers(oldCallers); 69 } 70 } 71 } finally { 72 setCurrentServletName(oldServletName); 73 } 74 } 75 76 82 static String getCurrentServletName() { 83 return currentServletName.get(); 84 } 85 86 static void setCurrentServletName(String servletName) { 87 currentServletName.set(servletName); 88 } 89 90 public void doStart() throws Exception { 91 LifecycleCommand lifecycleCommand = new StartCommand(); 92 lifecycleChain.lifecycleCommand(lifecycleCommand); 93 } 94 95 public void doStop() { 96 LifecycleCommand lifecycleCommand = new StopCommand(); 97 try { 98 lifecycleChain.lifecycleCommand(lifecycleCommand); 99 } catch (Exception e) { 100 } 102 } 103 104 private void internalDoStart() throws Exception { 105 super.doStart(); 106 } 107 108 private void internalDoStop() { 109 super.doStop(); 110 } 111 112 public class StartCommand implements LifecycleCommand { 113 114 public void lifecycleMethod() throws Exception { 115 internalDoStart(); 116 } 117 } 118 119 public class StopCommand implements LifecycleCommand { 120 121 public void lifecycleMethod() throws Exception { 122 internalDoStop(); 123 } 124 } 125 126 } 127 | Popular Tags |