com.sun.grizzly.tcp.http11
Class GrizzlyAdapter

java.lang.Object
  extended by com.sun.grizzly.tcp.StaticResourcesAdapter
      extended by com.sun.grizzly.tcp.http11.GrizzlyAdapter
All Implemented Interfaces:
Adapter
Direct Known Subclasses:
CometdAdapter, GrizzlyAdapterChain, OSGiMainAdapter, OSGiResourceAdapter, ServletAdapter

public abstract class GrizzlyAdapter
extends StaticResourcesAdapter

Base class to use when GrizzlyRequest/Response/InputStream/OutputStream are needed to implement a customized HTTP container/extendion to the http module. The ServletAdapter demonstrate and easy and powerfull way of how to extend this class. The GrizzlyAdapter provides developpers with a simple and consistent mechanism for extending the functionality of the HTTP WebServer and for bridging existing http based technology like JRuby-on-Rail, Servlet, Bayeux Protocol or any http based protocol.

Author:
Jeanfrancois Arcand

Field Summary
protected static int ADAPTER_NOTES
           
protected static boolean ALLOW_BACKSLASH
           
protected  boolean chunkingDisabled
           
 
Fields inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
cache, commitErrorResponse, fileFolders, logger, resourcesContextPath
 
Constructor Summary
GrizzlyAdapter()
           
GrizzlyAdapter(String publicDirectory)
          Create a new instance which will look for static pages located under publicDirectory folder.
 
Method Summary
 void afterService(GrizzlyRequest request, GrizzlyResponse response)
          Once the service(com.sun.grizzly.tcp.Request, com.sun.grizzly.tcp.Response) method has been execyuted, the container will call this method to allow any extension to clean up there associated GrizzlyRequest and GrizzlyResponse.
 void afterService(Request req, Response res)
          Clean up the Request and Response object, and commit the response, and then invoke the afterService(com.sun.grizzly.tcp.http11.GrizzlyRequest, com.sun.grizzly.tcp.http11.GrizzlyResponse) method to allow extension of this class to clean their own objects.
 void destroy()
          Invoked when the GrizzlyWebServer or SelectorThread is stopped or removed.
 boolean isAllowEncodedSlash()
          Is http url request allowed to contains encoded slash.
 boolean isDecodeURL()
          Should this class decode the URL
 boolean isHandleStaticResources()
          Return true if this class should handle static resources.
abstract  void service(GrizzlyRequest request, GrizzlyResponse response)
          This method should contains the logic for any http extension to the Grizzly HTTP Webserver.
 void service(Request req, Response res)
          Wrap a Request and Response with associated high level classes like GrizzlyRequest and GrizzlyResponse.
 void setAllowEncodedSlash(boolean allowEncodedSlash)
          When true, url that contains encoded slash will be allowed.
protected  void setDecodeUrl(boolean decodeURL)
          Should this class decode the URL
 void setHandleStaticResources(boolean handleStaticResources)
          Enable static resource handling.
 void start()
          Called when the GrizzlyAdapter's container is started by invoking GrizzlyWebServer#start or when .
 
Methods inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
addRootFolder, customizedErrorPage, getDefaultContentType, getResourcesContextPath, getRootFolder, getRootFolders, initWebDir, isUseSendFile, service, setDefaultContentType, setLogger, setResourcesContextPath, setRootFolder, setUseSendFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADAPTER_NOTES

protected static final int ADAPTER_NOTES
See Also:
Constant Field Values

ALLOW_BACKSLASH

protected static final boolean ALLOW_BACKSLASH
See Also:
Constant Field Values

chunkingDisabled

protected boolean chunkingDisabled
Constructor Detail

GrizzlyAdapter

public GrizzlyAdapter()

GrizzlyAdapter

public GrizzlyAdapter(String publicDirectory)
Create a new instance which will look for static pages located under publicDirectory folder.

Parameters:
publicDirectory - the folder where the static resource are located.
Method Detail

service

public final void service(Request req,
                          Response res)
                   throws Exception
Wrap a Request and Response with associated high level classes like GrizzlyRequest and GrizzlyResponse. The later objects offer more high level API like GrizzlyInputStream, GrizzlyRead etc.

Specified by:
service in interface Adapter
Overrides:
service in class StaticResourcesAdapter
Parameters:
req - the Request
res - the Response
Throws:
Exception

service

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

Parameters:
request - The GrizzlyRequest
response - The GrizzlyResponse
Throws:
Exception

afterService

public void afterService(GrizzlyRequest request,
                         GrizzlyResponse response)
                  throws Exception
Once the service(com.sun.grizzly.tcp.Request, com.sun.grizzly.tcp.Response) method has been execyuted, the container will call this method to allow any extension to clean up there associated GrizzlyRequest and GrizzlyResponse.

Parameters:
request - The GrizzlyRequest
response - The GrizzlyResponse
Throws:
Exception

afterService

public final void afterService(Request req,
                               Response res)
                        throws Exception
Clean up the Request and Response object, and commit the response, and then invoke the afterService(com.sun.grizzly.tcp.http11.GrizzlyRequest, com.sun.grizzly.tcp.http11.GrizzlyResponse) method to allow extension of this class to clean their own objects.

Specified by:
afterService in interface Adapter
Overrides:
afterService in class StaticResourcesAdapter
Parameters:
req - the Request
res - the Response
Throws:
Exception

start

public void start()
Called when the GrizzlyAdapter's container is started by invoking GrizzlyWebServer#start or when . By default, it does nothing.


destroy

public void destroy()
Invoked when the GrizzlyWebServer or SelectorThread is stopped or removed. By default, this method does nothing. Just override the method if you need to clean some resource.


isHandleStaticResources

public boolean isHandleStaticResources()
Return true if this class should handle static resources.

Returns:
true if this class should handle static resources.

setHandleStaticResources

public void setHandleStaticResources(boolean handleStaticResources)
Enable static resource handling. Default is false.

Parameters:
handleStaticResources -

isAllowEncodedSlash

public boolean isAllowEncodedSlash()
Is http url request allowed to contains encoded slash.

Returns:
Is http url request allowed to contains encoded slash.

setAllowEncodedSlash

public void setAllowEncodedSlash(boolean allowEncodedSlash)
When true, url that contains encoded slash will be allowed. When false, the url will be rejected and considered ans an invalid one.

Parameters:
allowEncodedSlash - true

setDecodeUrl

protected void setDecodeUrl(boolean decodeURL)
Should this class decode the URL


isDecodeURL

public boolean isDecodeURL()
Should this class decode the URL



Copyright © 2012 Oracle Corporation. All Rights Reserved.