org.glassfish.grizzly.http.server
Class HttpService

java.lang.Object
  extended by org.glassfish.grizzly.http.server.HttpService
Direct Known Subclasses:
HttpServiceChain

public abstract class HttpService
extends Object

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

Field Summary
protected  StaticResourcesHandler staticResourcesHandler
           
 
Constructor Summary
HttpService()
          Create HttpService, which, by default, won't handle requests to the static resources.
HttpService(String docRoot)
          Create a new instance which will look for static pages located under the docRoot.
 
Method Summary
protected  void customizedErrorPage(HttpServer server, 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 doService(Request request, Response response)
          Handles static resources if this service is configured to do so, otherwise invokes service(Request, Response).
 File getDocRoot()
          Return the directory from where files will be serviced, or null, if static resources won't be served by this HttpService.
 StaticResourcesHandler getStaticResourcesHandler()
          Get StaticResourcesHandler, which handles requests to a static resources.
 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 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 setDocRoot(File docRoot)
          Set the directory from where files will be serviced, if passed value is null - static resources won't be served by this HttpService.
 void setDocRoot(String docRoot)
          Set the directory from where files will be serviced, if passed value is null - static resources won't be served by this HttpService.
 void start()
          Called when the HttpService's container is started by invoking HttpServer.start().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

staticResourcesHandler

protected final StaticResourcesHandler staticResourcesHandler
Constructor Detail

HttpService

public HttpService()
Create HttpService, which, by default, won't handle requests to the static resources.


HttpService

public HttpService(String docRoot)
Create a new instance which will look for static pages located under the docRoot. If the docRoot is null - static pages won't be served by this HttpService

Parameters:
docRoot - the folder where the static resource are located. If the docRoot is null - static pages won't be served by this HttpService
Method Detail

doService

public final void doService(Request request,
                            Response response)
                     throws Exception
Handles static resources if this service is configured to do so, otherwise invokes service(Request, Response).

Parameters:
request - the Request
response - the Response
Throws:
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 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:
Exception

start

public void start()
Called when the HttpService'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.


getStaticResourcesHandler

public StaticResourcesHandler getStaticResourcesHandler()
Get StaticResourcesHandler, which handles requests to a static resources.

Returns:
StaticResourcesHandler, which handles requests to a static resources.

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

getDocRoot

public File getDocRoot()
Return the directory from where files will be serviced, or null, if static resources won't be served by this HttpService.

Returns:
the directory from where file will be serviced, or null, if static resources won't be served by this HttpService.

setDocRoot

public void setDocRoot(String docRoot)
Set the directory from where files will be serviced, if passed value is null - static resources won't be served by this HttpService.

Parameters:
docRoot - the directory from where files will be serviced, if passed value is null - static resources won't be served by this HttpService.

setDocRoot

public void setDocRoot(File docRoot)
Set the directory from where files will be serviced, if passed value is null - static resources won't be served by this HttpService.

Parameters:
docRoot - the directory from where files will be serviced, if passed value is null - static resources won't be served by this HttpService.

customizedErrorPage

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

Parameters:
server - the HttpServer associated with this service.
req - The Request object
res - The Response object
Throws:
Exception

sendAcknowledgment

protected boolean sendAcknowledgment(Request request,
                                     Response response)
                              throws 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 acknowledgement of the expectation, otherwise return false.
Throws:
IOException - if an error occurs sending the acknowledgement.

setDecodeUrl

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



Copyright © 2010 Oracle Corpration. All Rights Reserved.