1 package com.atlassian.plugin.servlet;
2
3 import com.atlassian.plugin.util.ClassLoaderStack;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6
7 import javax.servlet.ServletContext;
8 import javax.servlet.http.HttpSession;
9 import java.util.Enumeration;
10
11
12
13
14
15
16
17
18 public class PluginHttpSessionWrapper implements HttpSession {
19 private HttpSession delegate;
20 private static final Logger log = LoggerFactory.getLogger(PluginHttpSessionWrapper.class);
21
22 public PluginHttpSessionWrapper(final HttpSession session) {
23 this.delegate = session;
24 }
25
26 public Object getAttribute(final String name) {
27
28
29 ClassLoader classLoader = ClassLoaderStack.pop();
30 try {
31 if (log.isDebugEnabled()) {
32 log.debug("getAttribute('{}') Popping ClassLoader: {}. New ContextClassLoader: {}",
33 name, classLoader, Thread.currentThread().getContextClassLoader());
34 }
35 return delegate.getAttribute(name);
36 } finally {
37
38 ClassLoaderStack.push(classLoader);
39 }
40 }
41
42 public void setAttribute(final String name, final Object value) {
43
44
45 ClassLoader classLoader = ClassLoaderStack.pop();
46 try {
47 delegate.setAttribute(name, value);
48 } finally {
49
50 ClassLoaderStack.push(classLoader);
51 }
52 }
53
54 public Object getValue(final String name) {
55
56
57 ClassLoader classLoader = ClassLoaderStack.pop();
58 try {
59
60 return delegate.getValue(name);
61 } finally {
62
63 ClassLoaderStack.push(classLoader);
64 }
65 }
66
67 public void putValue(final String name, final Object value) {
68
69
70 ClassLoader classLoader = ClassLoaderStack.pop();
71 try {
72
73 delegate.putValue(name, value);
74 } finally {
75
76 ClassLoaderStack.push(classLoader);
77 }
78 }
79
80 public long getCreationTime() {
81 return delegate.getCreationTime();
82 }
83
84 public String getId() {
85 return delegate.getId();
86 }
87
88 public long getLastAccessedTime() {
89 return delegate.getLastAccessedTime();
90 }
91
92 public ServletContext getServletContext() {
93 return delegate.getServletContext();
94 }
95
96 public void setMaxInactiveInterval(final int interval) {
97 delegate.setMaxInactiveInterval(interval);
98 }
99
100 public int getMaxInactiveInterval() {
101 return delegate.getMaxInactiveInterval();
102 }
103
104 @SuppressWarnings({"deprecation"})
105 public javax.servlet.http.HttpSessionContext getSessionContext() {
106 return delegate.getSessionContext();
107 }
108
109 public Enumeration<String> getAttributeNames() {
110 return delegate.getAttributeNames();
111 }
112
113 @SuppressWarnings({"deprecation"})
114 public String[] getValueNames() {
115 return delegate.getValueNames();
116 }
117
118 public void removeAttribute(final String name) {
119 delegate.removeAttribute(name);
120 }
121
122 @SuppressWarnings({"deprecation"})
123 public void removeValue(final String name) {
124 delegate.removeValue(name);
125 }
126
127 public void invalidate() {
128 delegate.invalidate();
129 }
130
131 public boolean isNew() {
132 return delegate.isNew();
133 }
134 }