1 17 18 19 package org.apache.geronimo.jetty6.handler; 20 21 import java.io.IOException ; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 import org.mortbay.jetty.handler.AbstractHandler; 28 29 32 public class ThreadClassloaderHandler extends AbstractImmutableHandler { 33 34 private final ClassLoader classLoader; 35 36 public ThreadClassloaderHandler(AbstractHandler next, ClassLoader classLoader) { 37 super(next); 38 this.classLoader = classLoader; 39 } 40 41 public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException , ServletException { 42 Thread thread = Thread.currentThread(); 43 ClassLoader oldClassLoader = thread.getContextClassLoader(); 44 thread.setContextClassLoader(classLoader); 45 try { 46 next.handle(target, request, response, dispatch); 47 } finally { 48 thread.setContextClassLoader(oldClassLoader); 49 } 50 } 51 52 public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception { 53 Thread thread = Thread.currentThread(); 54 ClassLoader oldClassLoader = thread.getContextClassLoader(); 55 thread.setContextClassLoader(classLoader); 56 try { 57 super.lifecycleCommand(lifecycleCommand); 58 } finally { 59 thread.setContextClassLoader(oldClassLoader); 60 } 61 } 62 } 63 | Popular Tags |