comparison src/org/eclipse/jetty/server/handler/ContextHandler.java @ 988:13beba0c127f

remove ContextHandler._attributes
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 17 Oct 2016 05:22:25 -0600
parents d35b0a3a7a4a
children 900e5b8ccd19
comparison
equal deleted inserted replaced
987:af8742d31bca 988:13beba0c127f
67 import org.eclipse.jetty.server.AbstractHttpConnection; 67 import org.eclipse.jetty.server.AbstractHttpConnection;
68 import org.eclipse.jetty.server.Handler; 68 import org.eclipse.jetty.server.Handler;
69 import org.eclipse.jetty.server.HandlerContainer; 69 import org.eclipse.jetty.server.HandlerContainer;
70 import org.eclipse.jetty.server.Request; 70 import org.eclipse.jetty.server.Request;
71 import org.eclipse.jetty.server.Server; 71 import org.eclipse.jetty.server.Server;
72 import org.eclipse.jetty.util.Attributes;
73 import org.eclipse.jetty.util.AttributesMap; 72 import org.eclipse.jetty.util.AttributesMap;
74 import org.eclipse.jetty.util.LazyList; 73 import org.eclipse.jetty.util.LazyList;
75 import org.eclipse.jetty.util.StringUtil; 74 import org.eclipse.jetty.util.StringUtil;
76 import org.eclipse.jetty.util.TypeUtil; 75 import org.eclipse.jetty.util.TypeUtil;
77 import org.eclipse.jetty.util.URIUtil; 76 import org.eclipse.jetty.util.URIUtil;
94 * The maximum size of a form that can be processed by this context is controlled by the system properties org.eclipse.jetty.server.Request.maxFormKeys 93 * The maximum size of a form that can be processed by this context is controlled by the system properties org.eclipse.jetty.server.Request.maxFormKeys
95 * and org.eclipse.jetty.server.Request.maxFormContentSize. These can also be configured with {@link #setMaxFormContentSize(int)} and {@link #setMaxFormKeys(int)} 94 * and org.eclipse.jetty.server.Request.maxFormContentSize. These can also be configured with {@link #setMaxFormContentSize(int)} and {@link #setMaxFormKeys(int)}
96 * 95 *
97 * @org.apache.xbean.XBean description="Creates a basic HTTP context" 96 * @org.apache.xbean.XBean description="Creates a basic HTTP context"
98 */ 97 */
99 public class ContextHandler extends ScopedHandler implements Attributes, Server.Graceful 98 public final class ContextHandler extends ScopedHandler implements Server.Graceful
100 { 99 {
101 private static final Logger LOG = LoggerFactory.getLogger(ContextHandler.class); 100 private static final Logger LOG = LoggerFactory.getLogger(ContextHandler.class);
102 101
103 private static final ThreadLocal<Context> __context = new ThreadLocal<Context>(); 102 private static final ThreadLocal<Context> __context = new ThreadLocal<Context>();
104 103
120 return __context.get(); 119 return __context.get();
121 } 120 }
122 121
123 protected Context _scontext; 122 protected Context _scontext;
124 123
125 private final AttributesMap _attributes;
126 private final AttributesMap _contextAttributes; 124 private final AttributesMap _contextAttributes;
127 private final Map<String, String> _initParams; 125 private final Map<String, String> _initParams;
128 private ClassLoader _classLoader; 126 private ClassLoader _classLoader;
129 private String _contextPath = "/"; 127 private String _contextPath = "/";
130 private String _displayName; 128 private String _displayName;
162 */ 160 */
163 public ContextHandler() 161 public ContextHandler()
164 { 162 {
165 super(); 163 super();
166 _scontext = new Context(); 164 _scontext = new Context();
167 _attributes = new AttributesMap();
168 _contextAttributes = new AttributesMap();
169 _initParams = new HashMap<String, String>();
170 addAliasCheck(new ApproveNonExistentDirectoryAliases());
171 }
172
173 /* ------------------------------------------------------------ */
174 /**
175 *
176 */
177 protected ContextHandler(Context context)
178 {
179 super();
180 _scontext = context;
181 _attributes = new AttributesMap();
182 _contextAttributes = new AttributesMap(); 165 _contextAttributes = new AttributesMap();
183 _initParams = new HashMap<String, String>(); 166 _initParams = new HashMap<String, String>();
184 addAliasCheck(new ApproveNonExistentDirectoryAliases()); 167 addAliasCheck(new ApproveNonExistentDirectoryAliases());
185 } 168 }
186 169
212 @Override 195 @Override
213 public void dump(Appendable out, String indent) throws IOException 196 public void dump(Appendable out, String indent) throws IOException
214 { 197 {
215 dumpThis(out); 198 dumpThis(out);
216 dump(out,indent,Collections.singletonList(new CLDump(getClassLoader())),TypeUtil.asList(getHandlers()),getBeans(),_initParams.entrySet(), 199 dump(out,indent,Collections.singletonList(new CLDump(getClassLoader())),TypeUtil.asList(getHandlers()),getBeans(),_initParams.entrySet(),
217 _attributes.getAttributeEntrySet(),_contextAttributes.getAttributeEntrySet()); 200 _contextAttributes.getAttributeEntrySet());
218 } 201 }
219 202
220 /* ------------------------------------------------------------ */ 203 /* ------------------------------------------------------------ */
221 public Context getServletContext() 204 public Context getServletContext()
222 { 205 {
355 * representation of IP addresses. Host names may start with '*.' to wildcard one level of names. 338 * representation of IP addresses. Host names may start with '*.' to wildcard one level of names.
356 */ 339 */
357 public String[] getVirtualHosts() 340 public String[] getVirtualHosts()
358 { 341 {
359 return _vhosts; 342 return _vhosts;
360 }
361
362 /* ------------------------------------------------------------ */
363 /*
364 * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
365 */
366 public Object getAttribute(String name)
367 {
368 return _attributes.getAttribute(name);
369 }
370
371 /* ------------------------------------------------------------ */
372 /*
373 * @see javax.servlet.ServletContext#getAttributeNames()
374 */
375 @SuppressWarnings("unchecked")
376 public Enumeration getAttributeNames()
377 {
378 return AttributesMap.getAttributeNamesCopy(_attributes);
379 }
380
381 /* ------------------------------------------------------------ */
382 /**
383 * @return Returns the attributes.
384 */
385 public Attributes getAttributes()
386 {
387 return _attributes;
388 } 343 }
389 344
390 /* ------------------------------------------------------------ */ 345 /* ------------------------------------------------------------ */
391 /** 346 /**
392 * @return Returns the classLoader. 347 * @return Returns the classLoader.
1128 String[] tmp = new String[_protectedTargets.length]; 1083 String[] tmp = new String[_protectedTargets.length];
1129 System.arraycopy(_protectedTargets, 0, tmp, 0, _protectedTargets.length); 1084 System.arraycopy(_protectedTargets, 0, tmp, 0, _protectedTargets.length);
1130 return tmp; 1085 return tmp;
1131 } 1086 }
1132 1087
1133
1134 /* ------------------------------------------------------------ */
1135 /*
1136 * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
1137 */
1138 public void removeAttribute(String name)
1139 {
1140 checkManagedAttribute(name,null);
1141 _attributes.removeAttribute(name);
1142 }
1143
1144 /* ------------------------------------------------------------ */
1145 /*
1146 * Set a context attribute. Attributes set via this API cannot be overriden by the ServletContext.setAttribute API. Their lifecycle spans the stop/start of
1147 * a context. No attribute listener events are triggered by this API.
1148 *
1149 * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)
1150 */
1151 public void setAttribute(String name, Object value)
1152 {
1153 checkManagedAttribute(name,value);
1154 _attributes.setAttribute(name,value);
1155 }
1156
1157 /* ------------------------------------------------------------ */
1158 /**
1159 * @param attributes
1160 * The attributes to set.
1161 */
1162 public void setAttributes(Attributes attributes)
1163 {
1164 _attributes.clearAttributes();
1165 _attributes.addAll(attributes);
1166 Enumeration e = _attributes.getAttributeNames();
1167 while (e.hasMoreElements())
1168 {
1169 String name = (String)e.nextElement();
1170 checkManagedAttribute(name,attributes.getAttribute(name));
1171 }
1172 }
1173
1174 /* ------------------------------------------------------------ */
1175 public void clearAttributes()
1176 {
1177 Enumeration e = _attributes.getAttributeNames();
1178 while (e.hasMoreElements())
1179 {
1180 String name = (String)e.nextElement();
1181 checkManagedAttribute(name,null);
1182 }
1183 _attributes.clearAttributes();
1184 }
1185 1088
1186 /* ------------------------------------------------------------ */ 1089 /* ------------------------------------------------------------ */
1187 public void checkManagedAttribute(String name, Object value) 1090 public void checkManagedAttribute(String name, Object value)
1188 { 1091 {
1189 if (_managedAttributes != null && _managedAttributes.containsKey(name)) 1092 if (_managedAttributes != null && _managedAttributes.containsKey(name))
1939 * @see javax.servlet.ServletContext#getAttribute(java.lang.String) 1842 * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
1940 */ 1843 */
1941 @Override 1844 @Override
1942 public synchronized Object getAttribute(String name) 1845 public synchronized Object getAttribute(String name)
1943 { 1846 {
1944 Object o = ContextHandler.this.getAttribute(name); 1847 if (_contextAttributes != null)
1945 if (o == null && _contextAttributes != null) 1848 return _contextAttributes.getAttribute(name);
1946 o = _contextAttributes.getAttribute(name); 1849 return null;
1947 return o;
1948 } 1850 }
1949 1851
1950 /* ------------------------------------------------------------ */ 1852 /* ------------------------------------------------------------ */
1951 /* 1853 /*
1952 * @see javax.servlet.ServletContext#getAttributeNames() 1854 * @see javax.servlet.ServletContext#getAttributeNames()
1960 { 1862 {
1961 Enumeration<String> e = _contextAttributes.getAttributeNames(); 1863 Enumeration<String> e = _contextAttributes.getAttributeNames();
1962 while (e.hasMoreElements()) 1864 while (e.hasMoreElements())
1963 set.add(e.nextElement()); 1865 set.add(e.nextElement());
1964 } 1866 }
1965 Enumeration<String> e = _attributes.getAttributeNames();
1966 while (e.hasMoreElements())
1967 set.add(e.nextElement());
1968 1867
1969 return Collections.enumeration(set); 1868 return Collections.enumeration(set);
1970 } 1869 }
1971 1870
1972 /* ------------------------------------------------------------ */ 1871 /* ------------------------------------------------------------ */
2012 checkManagedAttribute(name,null); 1911 checkManagedAttribute(name,null);
2013 1912
2014 if (_contextAttributes == null) 1913 if (_contextAttributes == null)
2015 { 1914 {
2016 // Set it on the handler 1915 // Set it on the handler
2017 _attributes.removeAttribute(name);
2018 return; 1916 return;
2019 } 1917 }
2020 1918
2021 Object old_value = _contextAttributes.getAttribute(name); 1919 Object old_value = _contextAttributes.getAttribute(name);
2022 _contextAttributes.removeAttribute(name); 1920 _contextAttributes.removeAttribute(name);