com.sun.grizzly.http.servlet
Class ServletAdapter

java.lang.Object
  extended by com.sun.grizzly.tcp.StaticResourcesAdapter
      extended by com.sun.grizzly.tcp.http11.GrizzlyAdapter
          extended by com.sun.grizzly.http.servlet.ServletAdapter
All Implemented Interfaces:
Adapter

public class ServletAdapter
extends GrizzlyAdapter

Adapter class that can initiate a FilterChain and execute its Filter and its Servlet

Author:
Jeanfrancois Arcand

Field Summary
protected  HashMap<String,Object> properties
          Holder for our configured properties.
static int REQUEST_RESPONSE_NOTES
           
static int SERVLETCONFIG_NOTES
           
 
Fields inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter
ADAPTER_NOTES, ALLOW_BACKSLASH
 
Fields inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
commitErrorResponse, logger
 
Fields inherited from interface com.sun.grizzly.tcp.Adapter
CONNECTION_PROCESSING_COMPLETED, CONNECTION_PROCESSING_STARTED, REQUEST_PROCESSING_COMPLETED, REQUEST_PROCESSING_STARTED
 
Constructor Summary
ServletAdapter()
           
ServletAdapter(String publicDirectory)
           
 
Method Summary
 void addFilter(Filter filter, String filterName, Map initParameters)
          Add a Filter to the FilterChain
 void addInitParameter(String name, String value)
          Add a new servlet initialization parameter for this servlet.
 void afterService(GrizzlyRequest request, GrizzlyResponse response)
          This method should contains the logic for any http extension to the Grizzly HTTP Webserver.
protected  String getBasePath()
          Return the current based path.
 String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 Object getProperty(String name)
          Return a configured property.
 Servlet getServletInstance()
          Return the Servlet instance used by this Adapter
 String getServletPath()
          Returns the part of this request's URL that calls the servlet.
 void removeProperty(String name)
          remove a configured property.
 void service(GrizzlyRequest request, GrizzlyResponse response)
          This method should contains the logic for any http extension to the Grizzly HTTP Webserver.
protected  void setBasePath(String basePath)
          Set the basePath used by the ServletContext#getRealPath.
 void setContextPath(String contextPath)
          Programmatically set the context path of the Servlet.
 void setProperty(String name, Object value)
          Set a configured property.
 void setServletInstance(Servlet servletInstance)
          Set the Servlet instance used by this Adapter
 void setServletPath(String servletPath)
          Programmatically set the servlet path of the Servlet.
 
Methods inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter
afterService, convertMB, convertURI, copyBytes, isHandleStaticResources, log, log, normalize, service, setHandleStaticResources
 
Methods inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
customizedErrorPage, fireAdapterEvent, getLogger, getRootFolder, service, setLogger, setRootFolder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUEST_RESPONSE_NOTES

public static final int REQUEST_RESPONSE_NOTES
See Also:
Constant Field Values

SERVLETCONFIG_NOTES

public static final int SERVLETCONFIG_NOTES
See Also:
Constant Field Values

properties

protected HashMap<String,Object> properties
Holder for our configured properties.

Constructor Detail

ServletAdapter

public ServletAdapter()

ServletAdapter

public ServletAdapter(String publicDirectory)
Method Detail

service

public void service(GrizzlyRequest request,
                    GrizzlyResponse response)
This method should contains the logic for any http extension to the Grizzly HTTP Webserver.

Specified by:
service in class GrizzlyAdapter

afterService

public void afterService(GrizzlyRequest request,
                         GrizzlyResponse response)
                  throws Exception
This method should contains the logic for any http extension to the Grizzly HTTP Webserver.

Specified by:
afterService in class GrizzlyAdapter
Throws:
Exception

addInitParameter

public void addInitParameter(String name,
                             String value)
Add a new servlet initialization parameter for this servlet.

Parameters:
name - Name of this initialization parameter to add
value - Value of this initialization parameter to add

addFilter

public void addFilter(Filter filter,
                      String filterName,
                      Map initParameters)
Add a Filter to the FilterChain

Parameters:
filter - an instance of Filter
filterName - the Filter's name
initParameters - the Filter init parameters.

getServletInstance

public Servlet getServletInstance()
Return the Servlet instance used by this Adapter

Returns:

setServletInstance

public void setServletInstance(Servlet servletInstance)
Set the Servlet instance used by this Adapter

Parameters:
servletInstance - an instance of Servlet.

getServletPath

public String getServletPath()
Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME.

This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.

Returns:
a String containing the name or path of the servlet being called, as specified in the request URL, decoded, or an empty string if the servlet used to process the request is matched using the "/*" pattern.

setServletPath

public void setServletPath(String servletPath)
Programmatically set the servlet path of the Servlet.

Parameters:
servletPath -

getContextPath

public String getContextPath()
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.

It is possible that a servlet container may match a context by more than one context path. In such cases this method will return the actual context path used by the request and it may differ from the path returned by the ServletContext.getContextPath() method. The context path returned by ServletContext.getContextPath() should be considered as the prime or preferred context path of the application.

Returns:
a String specifying the portion of the request URI that indicates the context of the request
See Also:
ServletContext.getContextPath()

setContextPath

public void setContextPath(String contextPath)
Programmatically set the context path of the Servlet.

Parameters:
contextPath -

getBasePath

protected String getBasePath()
Return the current based path.

Returns:
basePath

setBasePath

protected void setBasePath(String basePath)
Set the basePath used by the ServletContext#getRealPath.

Parameters:
basePath -

getProperty

public Object getProperty(String name)
Return a configured property.


setProperty

public void setProperty(String name,
                        Object value)
Set a configured property.


removeProperty

public void removeProperty(String name)
remove a configured property.



Copyright © 2009 SUN Microsystems. All Rights Reserved.