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: */
17: package org.apache.jetspeed.container.invoker;
18:
19: import java.util.HashMap;
20: import java.util.Map;
21:
22: import javax.servlet.http.HttpServletRequest;
23: import javax.servlet.http.HttpServletRequestWrapper;
24:
25: /**
26: * Local servlet request wrapper. The purpose of this wrapper is to hold
27: * attribute information that is need for each request. In a threaded environment,
28: * each thread needs to have its own copy of this information so that there is
29: * not a timing issue with the original request object.
30: * Also, since the original request is no longer "holding" the attributes,
31: * there is no reason to remove them in the finally block.
32: * The LocalServletRequest object is automatically garbage collected at then
33: * end of this method.
34: *
35: * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
36: * @author <a href="">David Gurney</a>
37: * @version $Id: $
38: */
39: public class LocalServletRequest extends HttpServletRequestWrapper {
40: private Map attributeMap = new HashMap();
41:
42: private HttpServletRequest originalRequest = null;
43:
44: public LocalServletRequest(HttpServletRequest request) {
45: super (request);
46: originalRequest = request;
47: }
48:
49: public Object getAttribute(String p_sKey) {
50: Object a_oValue = attributeMap.get(p_sKey);
51: if (a_oValue == null) {
52: a_oValue = originalRequest.getAttribute(p_sKey);
53: }
54:
55: return a_oValue;
56: }
57:
58: public void removeAttribute(String key) {
59: Object value = attributeMap.remove(key);
60: if (value == null) {
61: originalRequest.removeAttribute(key);
62: }
63: }
64:
65: public void setAttribute(String key, Object value) {
66: attributeMap.put(key, value);
67: }
68:
69: }
|