org.glassfish.grizzly.http.server.util
Class Mapper

java.lang.Object
  extended by org.glassfish.grizzly.http.server.util.Mapper

public class Mapper
extends java.lang.Object

Mapper, which implements the servlet API mapping rules (which are derived from the HTTP rules).

Author:
Remy Maucherat

Nested Class Summary
protected static class Mapper.Context
           
protected static class Mapper.ContextList
           
protected static class Mapper.Host
           
protected static class Mapper.MapElement
           
protected static class Mapper.Wrapper
           
 
Field Summary
protected  Mapper.Context context
          Context associated with this wrapper, used for wrapper mapping.
protected  java.lang.String defaultHostName
          Default host name.
protected  Mapper.Host[] hosts
          Array containing the virtual hosts definitions.
 
Constructor Summary
Mapper()
           
 
Method Summary
 void addContext(java.lang.String hostName, java.lang.String path, java.lang.Object context, java.lang.String[] welcomeResources, javax.naming.Context resources)
          Add a new Context to an existing Host.
 void addContext(java.lang.String hostName, java.lang.String path, java.lang.Object context, java.lang.String[] welcomeResources, javax.naming.Context resources, java.util.List<AlternateDocBase> alternateDocBases)
          Add a new Context to an existing Host.
 void addHost(java.lang.String name, java.lang.String[] aliases, java.lang.Object host)
          Add a new host to the mapper.
protected  void addWrapper(Mapper.Context context, java.lang.String path, java.lang.Object wrapper)
           
protected  void addWrapper(Mapper.Context context, java.lang.String path, java.lang.Object wrapper, boolean jspWildCard, boolean isEmptyPathSpecial)
           
protected  void addWrapper(Mapper.Context context, java.lang.String path, java.lang.Object wrapper, boolean jspWildCard, java.lang.String servletName, boolean isEmptyPathSpecial)
          Adds a wrapper to the given context.
 void addWrapper(java.lang.String path, java.lang.Object wrapper)
          Add a wrapper to the context associated with this wrapper.
 void addWrapper(java.lang.String path, java.lang.Object wrapper, boolean jspWildCard, boolean isEmptyPathSpecial)
           
 void addWrapper(java.lang.String hostName, java.lang.String contextPath, java.lang.String path, java.lang.Object wrapper)
          Add a new Wrapper to an existing Context.
 void addWrapper(java.lang.String hostName, java.lang.String contextPath, java.lang.String path, java.lang.Object wrapper, boolean jspWildCard)
          Add a new Wrapper to an existing Context.
 void addWrapper(java.lang.String hostName, java.lang.String contextPath, java.lang.String path, java.lang.Object wrapper, boolean jspWildCard, java.lang.String servletName, boolean isEmptyPathSpecial)
          Add a new Wrapper to an existing Context.
static boolean allowReplacement()
          true if replacement of already added [@link Host}, Mapper.Context and Mapper.Wrapper when invoking addHost(java.lang.String, java.lang.String[], java.lang.Object), addContext(java.lang.String, java.lang.String, java.lang.Object, java.lang.String[], javax.naming.Context) etc.
 java.lang.String[] getContextNames()
          Return all contexts, in //HOST/PATH form
 java.lang.String getDefaultHostName()
           
 java.lang.String[] getHosts()
           
 int getPort()
           
 java.lang.String[] getWrapperNames(java.lang.String host, java.lang.String context)
           
 java.lang.String getWrappersString(java.lang.String host, java.lang.String context)
           
 void map(DataChunk host, DataChunk uri, MappingData mappingData)
          Map the specified host name and URI, mutating the given mapping data.
 void map(MessageBytes uri, MappingData mappingData)
          Map the specified URI relative to the context, mutating the given mapping data.
 void mapUriWithSemicolon(DataChunk serverName, DataChunk decodedURI, MappingData mappingData, int semicolonPos)
          Maps the decodedURI to the corresponding HttpHandler, considering that URI may have a semicolon with extra data followed, which shouldn't be a part of mapping process.
 void removeContext(java.lang.String hostName, java.lang.String path)
          Remove a context from an existing host.
 void removeHost(java.lang.String name)
          Remove a host from the mapper.
protected  void removeWrapper(Mapper.Context context, java.lang.String path)
           
 void removeWrapper(java.lang.String path)
          Remove a wrapper from the context associated with this wrapper.
 void removeWrapper(java.lang.String hostName, java.lang.String contextPath, java.lang.String path)
          Remove a wrapper from an existing context.
static void setAllowReplacement(boolean ar)
          Allow replacement of already added Mapper.Host, Mapper.Context and Mapper.Wrapper when invoking addHost(java.lang.String, java.lang.String[], java.lang.Object), addContext(java.lang.String, java.lang.String, java.lang.Object, java.lang.String[], javax.naming.Context) etc.
 void setContext(java.lang.String path, java.lang.String[] welcomeResources, javax.naming.Context resources)
          Set context, used for wrapper mapping (request dispatcher).
 void setDefaultContextPath(java.lang.String hostName, java.lang.String defaultContextPath)
          Configures the given virtual server with the given default context path.
 void setDefaultHostName(java.lang.String defaultHostName)
          Set default host.
 void setPort(int port)
          The Port this instance is used for mapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hosts

protected Mapper.Host[] hosts
Array containing the virtual hosts definitions.


defaultHostName

protected java.lang.String defaultHostName
Default host name.


context

protected Mapper.Context context
Context associated with this wrapper, used for wrapper mapping.

Constructor Detail

Mapper

public Mapper()
Method Detail

setAllowReplacement

public static void setAllowReplacement(boolean ar)
Allow replacement of already added Mapper.Host, Mapper.Context and Mapper.Wrapper when invoking addHost(java.lang.String, java.lang.String[], java.lang.Object), addContext(java.lang.String, java.lang.String, java.lang.Object, java.lang.String[], javax.naming.Context) etc. Default is false


allowReplacement

public static boolean allowReplacement()
true if replacement of already added [@link Host}, Mapper.Context and Mapper.Wrapper when invoking addHost(java.lang.String, java.lang.String[], java.lang.Object), addContext(java.lang.String, java.lang.String, java.lang.Object, java.lang.String[], javax.naming.Context) etc. Default is false


setPort

public void setPort(int port)
The Port this instance is used for mapping.


getPort

public int getPort()
Returns:
the port this instance is used for mapping.

getDefaultHostName

public java.lang.String getDefaultHostName()
Returns:
Default host name

setDefaultHostName

public void setDefaultHostName(java.lang.String defaultHostName)
Set default host.

Parameters:
defaultHostName - Default host name

addHost

public void addHost(java.lang.String name,
                    java.lang.String[] aliases,
                    java.lang.Object host)
Add a new host to the mapper.

Parameters:
name - Virtual host name
host - Host object

removeHost

public void removeHost(java.lang.String name)
Remove a host from the mapper.

Parameters:
name - Virtual host name

getHosts

public java.lang.String[] getHosts()

setContext

public void setContext(java.lang.String path,
                       java.lang.String[] welcomeResources,
                       javax.naming.Context resources)
Set context, used for wrapper mapping (request dispatcher).

Parameters:
welcomeResources - Welcome files defined for this context
resources - Static resources of the context

addContext

public void addContext(java.lang.String hostName,
                       java.lang.String path,
                       java.lang.Object context,
                       java.lang.String[] welcomeResources,
                       javax.naming.Context resources)
Add a new Context to an existing Host.

Parameters:
hostName - Virtual host name this context belongs to
path - Context path
context - Context object
welcomeResources - Welcome files defined for this context
resources - Static resources of the context

addContext

public void addContext(java.lang.String hostName,
                       java.lang.String path,
                       java.lang.Object context,
                       java.lang.String[] welcomeResources,
                       javax.naming.Context resources,
                       java.util.List<AlternateDocBase> alternateDocBases)
Add a new Context to an existing Host.

Parameters:
hostName - Virtual host name this context belongs to
path - Context path
context - Context object
welcomeResources - Welcome files defined for this context
resources - Static resources of the context
alternateDocBases - the alternate docbases of the context

removeContext

public void removeContext(java.lang.String hostName,
                          java.lang.String path)
Remove a context from an existing host.

Parameters:
hostName - Virtual host name this context belongs to
path - Context path

getContextNames

public java.lang.String[] getContextNames()
Return all contexts, in //HOST/PATH form

Returns:
The context names

addWrapper

public void addWrapper(java.lang.String hostName,
                       java.lang.String contextPath,
                       java.lang.String path,
                       java.lang.Object wrapper)
Add a new Wrapper to an existing Context.

Parameters:
hostName - Virtual host name this wrapper belongs to
contextPath - Context path this wrapper belongs to
path - Wrapper mapping
wrapper - Wrapper object

addWrapper

public void addWrapper(java.lang.String hostName,
                       java.lang.String contextPath,
                       java.lang.String path,
                       java.lang.Object wrapper,
                       boolean jspWildCard)
Add a new Wrapper to an existing Context.

Parameters:
hostName - Virtual host name this wrapper belongs to
contextPath - Context path this wrapper belongs to
path - Wrapper mapping
wrapper - Wrapper object
jspWildCard -

addWrapper

public void addWrapper(java.lang.String hostName,
                       java.lang.String contextPath,
                       java.lang.String path,
                       java.lang.Object wrapper,
                       boolean jspWildCard,
                       java.lang.String servletName,
                       boolean isEmptyPathSpecial)
Add a new Wrapper to an existing Context.

Parameters:
hostName - Virtual host name this wrapper belongs to
contextPath - Context path this wrapper belongs to
path - Wrapper mapping
wrapper - Wrapper object
jspWildCard -
servletName - servlet name or null if unknown

addWrapper

public void addWrapper(java.lang.String path,
                       java.lang.Object wrapper)
Add a wrapper to the context associated with this wrapper.

Parameters:
path - Wrapper mapping
wrapper - The Wrapper object

addWrapper

public void addWrapper(java.lang.String path,
                       java.lang.Object wrapper,
                       boolean jspWildCard,
                       boolean isEmptyPathSpecial)

addWrapper

protected void addWrapper(Mapper.Context context,
                          java.lang.String path,
                          java.lang.Object wrapper)

addWrapper

protected void addWrapper(Mapper.Context context,
                          java.lang.String path,
                          java.lang.Object wrapper,
                          boolean jspWildCard,
                          boolean isEmptyPathSpecial)

addWrapper

protected void addWrapper(Mapper.Context context,
                          java.lang.String path,
                          java.lang.Object wrapper,
                          boolean jspWildCard,
                          java.lang.String servletName,
                          boolean isEmptyPathSpecial)
Adds a wrapper to the given context.

Parameters:
context - The context to which to add the wrapper
path - Wrapper mapping
wrapper - The Wrapper object
jspWildCard - true if the wrapper corresponds to the JspServlet and the mapping path contains a wildcard; false otherwise
servletName - then name of servletName or null if unknown

removeWrapper

public void removeWrapper(java.lang.String path)
Remove a wrapper from the context associated with this wrapper.

Parameters:
path - Wrapper mapping

removeWrapper

public void removeWrapper(java.lang.String hostName,
                          java.lang.String contextPath,
                          java.lang.String path)
Remove a wrapper from an existing context.

Parameters:
hostName - Virtual host name this wrapper belongs to
contextPath - Context path this wrapper belongs to
path - Wrapper mapping

removeWrapper

protected void removeWrapper(Mapper.Context context,
                             java.lang.String path)

getWrappersString

public java.lang.String getWrappersString(java.lang.String host,
                                          java.lang.String context)

getWrapperNames

public java.lang.String[] getWrapperNames(java.lang.String host,
                                          java.lang.String context)

setDefaultContextPath

public void setDefaultContextPath(java.lang.String hostName,
                                  java.lang.String defaultContextPath)
                           throws java.lang.Exception
Configures the given virtual server with the given default context path. The given default path corresponds to the context path of one of the web contexts deployed on the virtual server that has been designated as the virtual server's new default-web-module.

Throws:
java.lang.Exception - if there is no web context deployed on the given virtual server that matches the given default context path

mapUriWithSemicolon

public void mapUriWithSemicolon(DataChunk serverName,
                                DataChunk decodedURI,
                                MappingData mappingData,
                                int semicolonPos)
                         throws java.lang.Exception
Maps the decodedURI to the corresponding HttpHandler, considering that URI may have a semicolon with extra data followed, which shouldn't be a part of mapping process.

Parameters:
serverName - the server name as described by the Host header.
decodedURI - decoded URI
mappingData - MappingData based on the URI.
semicolonPos - semicolon position. Might be 0 if position wasn't resolved yet (so it will be resolved in the method), or -1 if there is no semicolon in the URI.
Throws:
java.lang.Exception - if an error occurs mapping the request

map

public void map(DataChunk host,
                DataChunk uri,
                MappingData mappingData)
         throws java.lang.Exception
Map the specified host name and URI, mutating the given mapping data.

Parameters:
host - Virtual host name
uri - URI
mappingData - This structure will contain the result of the mapping operation
Throws:
java.lang.Exception

map

public void map(MessageBytes uri,
                MappingData mappingData)
         throws java.lang.Exception
Map the specified URI relative to the context, mutating the given mapping data.

Parameters:
uri - URI
mappingData - This structure will contain the result of the mapping operation
Throws:
java.lang.Exception


Copyright © 2012 Oracle Corporation. All Rights Reserved.