electric.servlet
Class ServletMapper

java.lang.Object
  extended byelectric.servlet.ServletMapper

public class ServletMapper
extends java.lang.Object

ServletMapper maps a URI to a servlet according to the mapping algorithm defined in chapter SRV.11 of the servlet spec.

Author:
webMethods

Constructor Summary
ServletMapper()
           
 
Method Summary
 void addServletMapping(Config servletConfig, java.lang.String urlPattern)
          Add a new mapping between a servlet and a URL pattern.
 void clearCache()
          Clear the cache of url to servlet mappings.
protected  MappedServlet findDefault(java.lang.String path)
          4.
protected  MappedServlet findExactMatch(java.lang.String path)
          1.
protected  MappedServlet findPrefixMatch(java.lang.String path)
          2.
protected  MappedServlet findSuffixMatch(java.lang.String path)
          3.
 int getMaxCacheSize()
           
 Config getServletMapping(java.lang.String urlPattern)
           
 java.util.Hashtable getServletMappings()
          Return a hashtable containing a mapping from sevlet-pattern -> servletConfig.
 java.lang.String[] getServletMappings(Config servletConfig)
           
 MappedServlet mapPathToServlet(java.lang.String path)
          Map a path to a servlet and cache the results for quicker lookups later on.
 MappedServlet mapPathToServletNoCache(java.lang.String path)
          Return a servlet config whose uriPattern matches the given path.
 void removeAllMappings(Config servletConfig)
           
 void removeServletMapping(Config servletConfig, java.lang.String urlPattern)
           
 void setMaxCacheSize(int maxCacheSize)
          Set the maximum uri to servlet cache size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletMapper

public ServletMapper()
Method Detail

getServletMappings

public java.lang.String[] getServletMappings(Config servletConfig)
Parameters:
servletConfig -

addServletMapping

public void addServletMapping(Config servletConfig,
                              java.lang.String urlPattern)
Add a new mapping between a servlet and a URL pattern. A URL pattern can specify an exact match, a prefix mapping (ending with *) or an extension mapping (starting *.[extension]). An exact match for a lone slash "/" is a special case that sets the servlet as the "default servlet" for the context/webapp.

Parameters:
servletConfig -
urlPattern -

removeServletMapping

public void removeServletMapping(Config servletConfig,
                                 java.lang.String urlPattern)
Parameters:
servletConfig -
urlPattern -

removeAllMappings

public void removeAllMappings(Config servletConfig)
Parameters:
servletConfig -

getServletMappings

public java.util.Hashtable getServletMappings()
Return a hashtable containing a mapping from sevlet-pattern -> servletConfig.


getServletMapping

public Config getServletMapping(java.lang.String urlPattern)
Parameters:
urlPattern -

clearCache

public void clearCache()
Clear the cache of url to servlet mappings.


getMaxCacheSize

public int getMaxCacheSize()
Returns:
maximum cache size.

setMaxCacheSize

public void setMaxCacheSize(int maxCacheSize)
Set the maximum uri to servlet cache size. No limit is -1, 0 means don't cache at all, positive numbers mean limit the cache to that size. Limiting the size of the cache helps defend against denial-of-service attacks against "*" mappings that match an infinite number of possible URI's. todo: make this a param in config.xml

Parameters:
maxCacheSize -

mapPathToServlet

public MappedServlet mapPathToServlet(java.lang.String path)
Map a path to a servlet and cache the results for quicker lookups later on.

Parameters:
path - request path with context path stripped off.
Returns:
matching servlet config or null if no matches.

mapPathToServletNoCache

public MappedServlet mapPathToServletNoCache(java.lang.String path)
Return a servlet config whose uriPattern matches the given path. The path used for mapping to a servlet is the request URL from the request object minus the context path. The first successful match is used with no further matches attempted.

Parameters:
path - request path with context path stripped off.
Returns:
matching servlet config or null if no matches.

findExactMatch

protected MappedServlet findExactMatch(java.lang.String path)
1. Try to find an exact match of the path of the request to the path of the servlet.

Parameters:
path -
Returns:
matching servlet config or null if no matches.

findPrefixMatch

protected MappedServlet findPrefixMatch(java.lang.String path)
2. Try to match the longest path-prefix: Step down the path tree a directory at a time, using the / character as a path separator, the longest match determines the servlet selected.

Parameters:
path -
Returns:
matching servlet config or null if no matches.

findSuffixMatch

protected MappedServlet findSuffixMatch(java.lang.String path)
3. If the last segment in the URL path contains an extension (e.g. .jsp), try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last "." character.

Parameters:
path - request URI minus the context path.
Returns:
matching servlet config or null if no matches.

findDefault

protected MappedServlet findDefault(java.lang.String path)
4. If neither of the previous three rules result in a servlet match, attempt to serve content appropriate for the resource requested. If a "default" servlet is defined for the webapp/context, it will be used. If there is no default servlet, return null.

Parameters:
path -
Returns:
matching servlet config or null if no matches.


copyright© 2001-2004 by webMethods All Rights Reserved.