org.glassfish.grizzly.http.server
Class HttpHandler

java.lang.Object
  extended by org.glassfish.grizzly.http.server.HttpHandler
Direct Known Subclasses:
HttpHandlerChain, StaticHttpHandler

public abstract class HttpHandler
extends java.lang.Object

Base class to use when Request/Response/InputStream/OutputStream are needed to implement a customized HTTP container/extension to the HTTP module. The HttpHandler provides developers 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

Constructor Summary
HttpHandler()
          Create HttpHandler.
HttpHandler(java.lang.String name)
          Create HttpHandler with the specific name.
 
Method Summary
protected  void customizedErrorPage(Request req, Response res)
          Customize the error page.
 void destroy()
          Invoked when the HttpServer and may be overridden by custom implementations to perform implementation specific resource reclaimation tasks.
 void doHandle(Request request, Response response)
          Pre-processes HttpHandler Request and Response, checks the HTTP acknowledgment and decodes URL if required.
 java.lang.String getName()
          Get the HttpHandler name.
 java.nio.charset.Charset getRequestURIEncoding()
          Get the request URI encoding used by this HttpHandler.
 boolean isAllowCustomStatusMessage()
          Returns true if custom status messages (reason phrases) are allowed for this response, or false otherwise.
 boolean isAllowEncodedSlash()
          Is HTTP URL request allowed to contains encoded slash.
protected  boolean sendAcknowledgment(Request request, Response response)
          The default implementation will acknowledge an Expect: 100-Continue with a response line with the status 100 followed by the final response to this request.
abstract  void service(Request request, Response response)
          This method should contain the logic for any HTTP extension to the Grizzly HTTP web server.
 void setAllowCustomStatusMessage(boolean allowCustomStatusMessage)
          Sets if the custom status messages (reason phrases) are allowed for this response.
 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
protected  void setDispatcherHelper(DispatcherHelper dispatcherHelper)
           
 void setRequestURIEncoding(java.nio.charset.Charset requestURIEncoding)
          Set the request URI encoding used by this HttpHandler.
 void setRequestURIEncoding(java.lang.String requestURIEncoding)
          Set the request URI encoding used by this HttpHandler.
 void start()
          Called when the HttpHandler's container is started by invoking HttpServer.start().
protected static void updateContextPath(Request request, java.lang.String contextPath)
          Utility method to update Request context-path value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpHandler

public HttpHandler()
Create HttpHandler.


HttpHandler

public HttpHandler(java.lang.String name)
Create HttpHandler with the specific name.

Method Detail

getName

public java.lang.String getName()
Get the HttpHandler name.

Returns:
the HttpHandler name.

doHandle

public final void doHandle(Request request,
                           Response response)
                    throws java.lang.Exception
Pre-processes HttpHandler Request and Response, checks the HTTP acknowledgment and decodes URL if required. Then passes control to service(Request, Response).

Parameters:
request - the Request
response - the Response
Throws:
java.lang.Exception - if an error occurs serving a static resource or from the invocation of service(Request, Response)

service

public abstract void service(Request request,
                             Response response)
                      throws java.lang.Exception
This method should contain the logic for any HTTP extension to the Grizzly HTTP web server.

Parameters:
request - The Request
response - The Response
Throws:
java.lang.Exception

start

public void start()
Called when the HttpHandler's container is started by invoking HttpServer.start(). By default, it does nothing.


destroy

public void destroy()
Invoked when the HttpServer and may be overridden by custom implementations to perform implementation specific resource reclaimation tasks. By default, this method does nothing.


isAllowCustomStatusMessage

public boolean isAllowCustomStatusMessage()
Returns true if custom status messages (reason phrases) are allowed for this response, or false otherwise.

Returns:
true if custom status messages (reason phrases) are allowed for this response, or false otherwise.

setAllowCustomStatusMessage

public void setAllowCustomStatusMessage(boolean allowCustomStatusMessage)
Sets if the custom status messages (reason phrases) are allowed for this response.

Parameters:
allowCustomStatusMessage - true if custom status messages (reason phrases) are allowed for this response, or false otherwise.

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 as an invalid one.

Parameters:
allowEncodedSlash - true

getRequestURIEncoding

public java.nio.charset.Charset getRequestURIEncoding()
Get the request URI encoding used by this HttpHandler.

Returns:
the request URI encoding used by this HttpHandler.

setRequestURIEncoding

public void setRequestURIEncoding(java.nio.charset.Charset requestURIEncoding)
Set the request URI encoding used by this HttpHandler.

Parameters:
requestURIEncoding - the request URI encoding used by this HttpHandler.

setRequestURIEncoding

public void setRequestURIEncoding(java.lang.String requestURIEncoding)
Set the request URI encoding used by this HttpHandler.

Parameters:
requestURIEncoding - the request URI encoding used by this HttpHandler.

customizedErrorPage

protected void customizedErrorPage(Request req,
                                   Response res)
                            throws java.lang.Exception
Customize the error page.

Parameters:
req - The Request object
res - The Response object
Throws:
java.lang.Exception

sendAcknowledgment

protected boolean sendAcknowledgment(Request request,
                                     Response response)
                              throws java.io.IOException
The default implementation will acknowledge an Expect: 100-Continue with a response line with the status 100 followed by the final response to this request.

Parameters:
request - the Request.
response - the Response.
Returns:
true if request processing should continue after acknowledgment of the expectation, otherwise return false.
Throws:
java.io.IOException - if an error occurs sending the acknowledgment.

setDecodeUrl

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


updateContextPath

protected static void updateContextPath(Request request,
                                        java.lang.String contextPath)
Utility method to update Request context-path value.

Parameters:
request -
contextPath -

setDispatcherHelper

protected void setDispatcherHelper(DispatcherHelper dispatcherHelper)


Copyright © 2012 Oracle Corporation. All Rights Reserved.