Changeset 1078
- Timestamp:
- 06/07/08 21:16:14 (2 months ago)
- Files:
-
- trunk/mango/net/servlet/Servlet.d (modified) (3 diffs)
- trunk/mango/net/servlet/ServletProvider.d (modified) (8 diffs)
- trunk/mango/net/servlet/tools/AdminServlet.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/mango/net/servlet/Servlet.d
r1075 r1078 42 42 class Servlet 43 43 { 44 char[] name; 45 44 46 /********************************************************************** 45 47 … … 49 51 50 52 abstract void service (IServletRequest request, IServletResponse response); 53 54 /********************************************************************** 55 56 57 **********************************************************************/ 58 59 this (char[] name = null) 60 { 61 this.name = name; 62 } 63 64 /********************************************************************** 65 66 67 **********************************************************************/ 68 69 override char[] toString () 70 { 71 if (name.length) 72 return name; 73 return super.toString; 74 } 51 75 52 76 /********************************************************************** … … 110 134 **********************************************************************/ 111 135 112 this (char[] log= null)136 this (char[] name = null) 113 137 { 114 this.log = Log.lookup (log); 115 138 super (name); 139 140 log = Log.lookup (name); 116 141 metrics = new Metrics [7]; 117 142 } trunk/mango/net/servlet/ServletProvider.d
r1073 r1078 72 72 private Logger log; 73 73 private QueuedCache cache; 74 private HashMap proxies;75 74 private HashMap contexts; 76 75 private ServletMapping[] mappings; … … 86 85 this (Logger log, uint urls = 2048) 87 86 { 88 // small, low contention hashmap for proxies and contexts 89 proxies = new HashMap (128, 0.75, 1); 87 // small, low contention hashmap for contexts 90 88 contexts = new HashMap (128, 0.75, 1); 91 89 … … 178 176 contexts.put (context.getName, context); 179 177 return context; 180 }181 182 /**********************************************************************183 184 lookup and cast HashMap entry185 186 **********************************************************************/187 188 private final ServletProxy lookupProxy (char[] name)189 {190 return cast(ServletProxy) proxies.get (name);191 }192 193 /**********************************************************************194 195 Add a uri-mapping for the named servlet. The servlet should196 have been registered previously.197 198 **********************************************************************/199 200 void addMapping (char[] pattern, char[] servlet)201 in {202 assert (servlet.length);203 }204 body205 {206 ServletProxy proxy = lookupProxy (servlet);207 if (proxy)208 addMapping (pattern, proxy);209 else210 throw new ServletException ("Invalid servlet mapping argument");211 178 } 212 179 … … 261 228 /********************************************************************** 262 229 263 Return the servlet registered with the specified name, or264 null if there is no such servlet.265 266 **********************************************************************/267 268 IRegisteredServlet getServlet (char[] name)269 in {270 assert (name.length);271 }272 body273 {274 return lookupProxy (name);275 }276 277 /**********************************************************************278 279 230 Register a servlet with the specified name. The servlet 280 231 is associated with the default context. … … 282 233 **********************************************************************/ 283 234 284 IRegisteredServlet addServlet (Servlet servlet , char[] name)285 { 286 return addServlet (servlet, name, getDefaultContext());235 IRegisteredServlet addServlet (Servlet servlet) 236 { 237 return addServlet (servlet, getDefaultContext); 287 238 } 288 239 … … 293 244 **********************************************************************/ 294 245 295 IRegisteredServlet addServlet (Servlet servlet, char[] name, char[]context)246 IRegisteredServlet addServlet (Servlet servlet, ServletContext context) 296 247 in { 297 248 assert (context !is null); … … 299 250 body 300 251 { 301 // backward compatability for default context ... 302 if (context == "/") 303 context = ""; 304 305 return addServlet (servlet, name, getContext (context)); 306 } 307 308 /********************************************************************** 309 310 Register a servlet with the specified name and context 311 312 **********************************************************************/ 313 314 IRegisteredServlet addServlet (Servlet servlet, char[] name, ServletContext context) 252 return addServlet (servlet, new ServletConfig (context)); 253 } 254 255 /********************************************************************** 256 257 Register a servlet with the specified name and configuration 258 259 **********************************************************************/ 260 261 IRegisteredServlet addServlet (Servlet servlet, ServletConfig config) 315 262 in { 316 assert (context !is null);317 }318 body319 {320 return addServlet (servlet, name, new ServletConfig (context));321 }322 323 /**********************************************************************324 325 Register a servlet with the specified name and configuration326 327 **********************************************************************/328 329 IRegisteredServlet addServlet (Servlet servlet, char[] name, ServletConfig config)330 in {331 assert (name.length);332 263 assert (config !is null); 333 264 assert (servlet !is null); … … 336 267 body 337 268 { 338 ServletProxy proxy = new ServletProxy (servlet, name, config.getServletContext()); 339 proxies.put (name, proxy); 269 auto proxy = new ServletProxy (servlet, null, config.getServletContext); 340 270 341 271 // initialize this servlet trunk/mango/net/servlet/tools/AdminServlet.d
r1076 r1078 31 31 class AdminServlet : Servlet 32 32 { 33 version (WithOwnLogger)34 {35 // our logging instance36 private Logger log;37 38 /***********************************************************************39 40 Set up the logger for this servlet41 42 ***********************************************************************/43 44 this()45 {46 log = Log.lookup ("mango.admin.AdminServlet");47 log.level = log.Level.Error;48 }49 }50 51 33 /*********************************************************************** 52 34 … … 267 249 static void configure (ServletProvider sp, ServletContext context) 268 250 { 269 sp.addMapping ("/admin/logger", sp.addServlet (new AdminServlet, "admin",context));251 sp.addMapping ("/admin/logger", sp.addServlet (new AdminServlet, context)); 270 252 } 271 253 }
