Class HttpHandler
- java.lang.Object
-
- org.glassfish.grizzly.http.server.HttpHandler
-
- Direct Known Subclasses:
HttpHandlerChain,StaticHttpHandlerBase
public abstract class HttpHandler extends Object
Base class to use when Request/Response/InputStream/OutputStream are needed to implement a customized HTTP container/extension to the HTTP module. TheHttpHandlerprovides 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
Constructors Constructor Description HttpHandler()Create HttpHandler.HttpHandler(String name)Create HttpHandler with the specific name.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddestroy()Invoked when theHttpServerand may be overridden by custom implementations to perform implementation specific resource reclaimation tasks.protected ErrorPageGeneratorgetErrorPageGenerator(Request request)Returns theErrorPageGenerator, that might be used (if an error occurs) duringRequestprocessing.StringgetName()Get the HttpHandler name.RequestExecutorProvidergetRequestExecutorProvider()CharsetgetRequestURIEncoding()Get the request URI encoding used by this HttpHandler.protected StringgetSessionCookieName()protected SessionManagergetSessionManager(Request request)booleanisAllowCustomStatusMessage()Returnstrueif custom status messages (reason phrases) are allowed for this response, orfalse otherwise.booleanisAllowEncodedSlash()Is HTTP URL request allowed to contains encoded slash.protected booleansendAcknowledgment(Request request, Response response)The default implementation will acknowledge anExpect: 100-Continuewith a response line with the status 100 followed by the final response to this request.abstract voidservice(Request request, Response response)This method should contain the logic for any HTTP extension to the Grizzly HTTP web server.voidsetAllowCustomStatusMessage(boolean allowCustomStatusMessage)Sets if the custom status messages (reason phrases) are allowed for this response.voidsetAllowEncodedSlash(boolean allowEncodedSlash)When true, URL that contains encoded slash will be allowed.protected voidsetDecodeUrl(boolean decodeURL)Should this class decode the URLprotected voidsetDispatcherHelper(DispatcherHelper dispatcherHelper)voidsetRequestURIEncoding(String requestURIEncoding)Set the request URI encoding used by this HttpHandler.voidsetRequestURIEncoding(Charset requestURIEncoding)Set the request URI encoding used by this HttpHandler.voidstart()Called when theHttpHandler's container is started by invokingHttpServer.start().protected static voidupdatePaths(Request request, MappingData mappingData)Utility method to updateRequestpath values.
-
-
-
Constructor Detail
-
HttpHandler
public HttpHandler()
Create HttpHandler.
-
HttpHandler
public HttpHandler(String name)
Create HttpHandler with the specific name.- Parameters:
name-
-
-
Method Detail
-
getName
public String getName()
Get the HttpHandler name.- Returns:
- the HttpHandler name.
-
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.
-
start
public void start()
Called when theHttpHandler's container is started by invokingHttpServer.start(). By default, it does nothing.
-
destroy
public void destroy()
Invoked when theHttpServerand may be overridden by custom implementations to perform implementation specific resource reclaimation tasks. By default, this method does nothing.
-
isAllowCustomStatusMessage
public boolean isAllowCustomStatusMessage()
Returnstrueif custom status messages (reason phrases) are allowed for this response, orfalse otherwise.- Returns:
trueif custom status messages (reason phrases) are allowed for this response, orfalse otherwise.
-
setAllowCustomStatusMessage
public void setAllowCustomStatusMessage(boolean allowCustomStatusMessage)
Sets if the custom status messages (reason phrases) are allowed for this response.- Parameters:
allowCustomStatusMessage-trueif custom status messages (reason phrases) are allowed for this response, orfalse 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 Charset getRequestURIEncoding()
Get the request URI encoding used by this HttpHandler.- Returns:
- the request URI encoding used by this HttpHandler.
-
setRequestURIEncoding
public void setRequestURIEncoding(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(String requestURIEncoding)
Set the request URI encoding used by this HttpHandler.- Parameters:
requestURIEncoding- the request URI encoding used by this HttpHandler.
-
getRequestExecutorProvider
public RequestExecutorProvider getRequestExecutorProvider()
- Returns:
- the
RequestExecutorProviderresponsible for executing user's code inservice(org.glassfish.grizzly.http.server.Request, org.glassfish.grizzly.http.server.Response)and notifyingReadHandler,WriteHandlerregistered by the user.
-
getErrorPageGenerator
protected ErrorPageGenerator getErrorPageGenerator(Request request)
Returns theErrorPageGenerator, that might be used (if an error occurs) duringRequestprocessing.- Parameters:
request-Request- Returns:
- the
ErrorPageGenerator, that might be used (if an error occurs) duringRequestprocessing
-
getSessionCookieName
protected String getSessionCookieName()
- Returns:
- session cookie name, if not set default JSESSIONID name will be used
-
getSessionManager
protected SessionManager getSessionManager(Request request)
- Parameters:
request-Request- Returns:
- the
SessionManagerto be used. null value impliesDefaultSessionManager
-
sendAcknowledgment
protected boolean sendAcknowledgment(Request request, Response response) throws IOException
The default implementation will acknowledge anExpect: 100-Continuewith a response line with the status 100 followed by the final response to this request.- Parameters:
request- theRequest.response- theResponse.- Returns:
trueif request processing should continue after acknowledgment of the expectation, otherwise returnfalse.- Throws:
IOException- if an error occurs sending the acknowledgment.
-
setDecodeUrl
protected void setDecodeUrl(boolean decodeURL)
Should this class decode the URL
-
updatePaths
protected static void updatePaths(Request request, MappingData mappingData)
Utility method to updateRequestpath values.- Parameters:
request-mappingData-
-
setDispatcherHelper
protected void setDispatcherHelper(DispatcherHelper dispatcherHelper)
-
-