01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.jetty6.handler;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.ServletException;
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23:
24: import org.mortbay.jetty.Handler;
25:
26: /**
27: * @version $Rev: 601149 $ $Date: 2007-12-04 15:30:18 -0800 (Tue, 04 Dec 2007) $
28: */
29: public class ThreadClassloaderHandler extends AbstractImmutableHandler {
30:
31: private final ClassLoader classLoader;
32:
33: public ThreadClassloaderHandler(Handler next,
34: ClassLoader classLoader) {
35: super (next);
36: this .classLoader = classLoader;
37: }
38:
39: public void handle(String target, HttpServletRequest request,
40: HttpServletResponse response, int dispatch)
41: 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)
53: throws Exception {
54: Thread thread = Thread.currentThread();
55: ClassLoader oldClassLoader = thread.getContextClassLoader();
56: thread.setContextClassLoader(classLoader);
57: try {
58: super.lifecycleCommand(lifecycleCommand);
59: } finally {
60: thread.setContextClassLoader(oldClassLoader);
61: }
62: }
63: }
|