Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

ServletProvider Class Reference

Inheritance diagram for ServletProvider:

IProvider List of all members.

Public Member Functions

 this (uint urls=2048)
HttpRequest createRequest (IProviderBridge bridge)
HttpResponse createResponse (IProviderBridge bridge)
char[] toString ()
ServletContext getDefaultContext ()
ServletContext getContext (char[] name)
ServletContext addContext (ServletContext context)
void addMapping (char[] pattern, char[] servlet)
void addMapping (char[] pattern, IRegisteredServlet servlet)
IRegisteredServlet getServlet (char[] name)
IRegisteredServlet addServlet (Servlet servlet, char[] name)
IRegisteredServlet addServlet (Servlet servlet, char[] name, char[] context)
IRegisteredServlet addServlet (Servlet servlet, char[] name, ServletContext context)
IRegisteredServlet addServlet (Servlet servlet, char[] name, ServletConfig config)
void service (HttpRequest req, HttpResponse res)

Private Member Functions

final ServletProxy lookupProxy (char[] name)
PathMapping constructPathMapping (char[] path)
void error (ServletResponse response, Object x)

Private Attributes

QueuedCache cache
HashMap proxies
HashMap contexts
ServletMapping[] mappings

Detailed Description

ServletProvider is a servlet-host implementation; you bind one of these to an HttpServer instance and you're up and running. This particular implementation has a few quirks worth noting:

Overall this should be pretty fast, since it doesn't cause any memory allocation whatsoever (once operationally primed).

Definition at line 94 of file ServletProvider.d.


Member Function Documentation

this uint  urls = 2048  )  [inline]
 

Construct a ServletProvider with a default path-mapping cache of 2048 entries. We also create the default context here.

Definition at line 109 of file ServletProvider.d.

References addContext(), contexts, HashMap, proxies, and QueuedCache.

HttpRequest createRequest IProviderBridge  bridge  )  [inline]
 

IProvider interface method

Reimplemented from IProvider.

Definition at line 130 of file ServletProvider.d.

References ServletRequest.

HttpResponse createResponse IProviderBridge  bridge  )  [inline]
 

IProvider interface method

Reimplemented from IProvider.

Definition at line 141 of file ServletProvider.d.

References ServletResponse.

char [] toString  )  [inline]
 

Return the name of this provider

Reimplemented from IProvider.

Definition at line 152 of file ServletProvider.d.

ServletContext getDefaultContext  )  [inline]
 

Return the default context. This is used for those servlets which don't have a context of their own, and is effectively a backwards-compatability hack.

Definition at line 165 of file ServletProvider.d.

References getContext().

Referenced by addServlet().

ServletContext getContext char[]  name  )  [inline]
 

Return the named context, or null if the name is unregistered

Definition at line 176 of file ServletProvider.d.

Referenced by getDefaultContext().

ServletContext addContext ServletContext  context  )  [inline]
 

Register a servlet context. The name is provided by the context itself.

Definition at line 190 of file ServletProvider.d.

Referenced by TaskServer::this(), and this().

final ServletProxy lookupProxy char[]  name  )  [inline, private]
 

lookup and cast HashMap entry

Definition at line 204 of file ServletProvider.d.

References HashMap::get(), and proxies.

void addMapping char[]  pattern,
char[]  servlet
[inline]
 

Add a uri-mapping for the named servlet. The servlet should have been registered previously.

Definition at line 216 of file ServletProvider.d.

Referenced by testServletEngine().

void addMapping char[]  pattern,
IRegisteredServlet  servlet
[inline]
 

Add a uri-mapping for the specified servlet. We follow the Java spec in terms of pattern support, but the namespace is not seperated for the four different pattern types. That is, all the mappings are placed into a single namespace.

Definition at line 236 of file ServletProvider.d.

IRegisteredServlet getServlet char[]  name  )  [inline]
 

Return the servlet registered with the specified name, or null if there is no such servlet.

Definition at line 280 of file ServletProvider.d.

IRegisteredServlet addServlet Servlet  servlet,
char[]  name
[inline]
 

Register a servlet with the specified name. The servlet is associated with the default context.

Definition at line 294 of file ServletProvider.d.

Referenced by addServlet(), and testServletEngine().

IRegisteredServlet addServlet Servlet  servlet,
char[]  name,
char[]  context
[inline]
 

Register a servlet with the specified name and context

Definition at line 305 of file ServletProvider.d.

References addServlet(), and getDefaultContext().

IRegisteredServlet addServlet Servlet  servlet,
char[]  name,
ServletContext  context
[inline]
 

Register a servlet with the specified name and context

Definition at line 322 of file ServletProvider.d.

IRegisteredServlet addServlet Servlet  servlet,
char[]  name,
ServletConfig  config
[inline]
 

Register a servlet with the specified name and configuration

Definition at line 335 of file ServletProvider.d.

PathMapping constructPathMapping char[]  path  )  [inline, private]
 

Scan the servlet mappings, looking for one that matches the specified path. The first match found is returned.

Definition at line 355 of file ServletProvider.d.

Referenced by service().

void service HttpRequest  req,
HttpResponse  res
[inline]
 

IProvider interface method. This is where the real work is done, and where optimization efforts should be focused. The process itself is straightforward:

  • we lookup the mapping cache to see if we've processed the request before. If not, we create a new mapping
  • we then setup the input parameters to the servlet, and invoke the latter.
  • lastly, we flush the response
All exceptions are caught and logged.

Reimplemented from IProvider.

Definition at line 381 of file ServletProvider.d.

References constructPathMapping(), HttpResponse::flush(), QueuedCache::get(), IRegisteredServlet::getContext(), IRegisteredServlet::getName(), Uri::getPath(), IRegisteredServlet::getServlet(), ServletRequest::getUri(), ServletResponse::getWriter(), PathMapping::mapping, ServletMapping::proxy, ServletResponse::sendError(), Servlet::service(), and ServletRequest::set().

void error ServletResponse  response,
Object  x
[inline, private]
 

handle internal errors

Definition at line 445 of file ServletProvider.d.

References HttpResponseCode.


Member Data Documentation

QueuedCache cache [private]
 

Definition at line 96 of file ServletProvider.d.

HashMap proxies [private]
 

Definition at line 97 of file ServletProvider.d.

Referenced by lookupProxy(), and this().

HashMap contexts [private]
 

Definition at line 98 of file ServletProvider.d.

Referenced by this().

ServletMapping [] mappings [private]
 

Definition at line 99 of file ServletProvider.d.


The documentation for this class was generated from the following file:
Generated on Sun Nov 7 19:07:10 2004 for Mango by doxygen 1.3.6