|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.glassfish.grizzly.http.server.HttpHandler
org.glassfish.grizzly.servlet.ServletHandler
public class ServletHandler
HttpHandler class that can initiate a FilterChain and execute its
Filter and its Servlet
Configuring a HttpServer to use this
HttpHandler implementation, adds the ability of servicing Servlet
as well as static resources.
This class can be used to programatically configure a Servlet, Filters, listeners,
init parameters, context-param, etc. a application usually defined using the web.xml.
See addInitParameter(String, String) addContextParameter(String, String)
setProperty(String, Object), addServletListener(String), etc.
As an example:
HttpServer hs = HttpServer.createSimpleServer("/var/www");
try {
ServletHandler sa = new ServletHandler();
sa.setServlet(new MyServlet());
// Set the display-name property
sa.setProperty("display-name", "myServlet");
// All Servlet listener types are added via the
// addServletListener() method regardless of their type...
sa.addServletListener(MyHttpSessionListener.class.getName());
sa.addServletListener(MyOtherHttpSessionListener.class.getName());
sa.addServletListener(FooServletContextListener.class.getName());
sa.assServletListener(BarServletCtxAttListener.class.getName());
// adding context initialization parameter...
sa.addContextParameter("databaseURI","jdbc://");
// adding servlet initialization parameter...
sa.addInitParameter("password","hello");
// adding servlet path information...
sa.setServletPath("/MyServletPath");
sa.setContextPath("/myApp");
// register the handler with the server...
hs.getServerConfiguration().addHttpHandler(sa, "/MyServletPath");
// start the server so the handler is able to serve requests...
hs.start();
} catch (IOException ex){
// Something when wrong.
}
| Field Summary | |
|---|---|
protected java.lang.ClassLoader |
classLoader
|
static int |
INCREMENT
|
protected boolean |
initialize
Initialize the ServletContext |
static java.lang.String |
LOAD_ON_STARTUP
|
protected java.util.Map<java.lang.String,java.lang.Object> |
properties
Holder for our configured properties. |
protected javax.servlet.Servlet |
servletInstance
|
| Constructor Summary | |
|---|---|
|
ServletHandler()
|
|
ServletHandler(javax.servlet.Servlet servlet)
Create a ServletAdapter which support the specific Servlet |
|
ServletHandler(javax.servlet.Servlet servlet,
ServletContextImpl servletContext)
|
|
ServletHandler(java.lang.String servletName)
|
protected |
ServletHandler(java.lang.String servletName,
ServletContextImpl servletCtx,
java.util.Map<java.lang.String,java.lang.String> contextParameters,
java.util.Map<java.lang.String,java.lang.String> servletInitParameters,
boolean initialize)
Convenience constructor. |
protected |
ServletHandler(java.lang.String servletName,
ServletContextImpl servletCtx,
java.util.Map<java.lang.String,java.lang.String> contextParameters,
java.util.Map<java.lang.String,java.lang.String> servletInitParameters,
java.util.List<java.lang.String> listeners)
Convenience constructor. |
protected |
ServletHandler(java.lang.String servletName,
ServletContextImpl servletCtx,
java.util.Map<java.lang.String,java.lang.String> contextParameters,
java.util.Map<java.lang.String,java.lang.String> servletInitParameters,
java.util.List<java.lang.String> listeners,
boolean initialize)
Convenience constructor. |
| Method Summary | |
|---|---|
void |
addContextParameter(java.lang.String name,
java.lang.String value)
Add a new servlet context parameter for this servlet. |
protected void |
addFilter(FilterConfigImpl filterConfig)
Add a filter to the set of filters that will be executed in this chain. |
void |
addFilter(javax.servlet.Filter filter,
java.lang.String filterName,
java.util.Map initParameters)
Add a Filter to the FilterChain. |
void |
addInitParameter(java.lang.String name,
java.lang.String value)
Add a new servlet initialization parameter for this servlet. |
void |
addServletListener(java.lang.String listenerName)
Add Servlet listeners that implement EventListener |
protected void |
configureClassLoader(java.lang.String applicationPath)
Create a URLClassLoader which has the capability of
loading classes jar under an exploded war application. |
protected void |
configureServletEnv()
Configure the ServletContextImpl
and ServletConfigImpl |
boolean |
containsInitParameter(java.lang.String name)
if the servlet initialization parameter in present for this servlet. |
void |
customizeErrorPage(Response response,
java.lang.String message,
int errorCode)
Customize the error page returned to the client. |
void |
destroy()
Destroy this Servlet and its associated ServletContextListener |
protected void |
doServletService(Request request,
Response response)
|
java.lang.ClassLoader |
getClassLoader()
|
protected java.util.Map<java.lang.String,java.lang.String> |
getContextParameters()
|
java.lang.String |
getContextPath()
Returns the portion of the request URI that indicates the context of the request. |
java.lang.String |
getInitParameter(java.lang.String name)
get a servlet initialization parameter for this servlet. |
protected java.util.List<java.lang.String> |
getListeners()
|
java.lang.String |
getName()
|
java.lang.Object |
getProperty(java.lang.String name)
Return a configured property. |
protected ServletContextImpl |
getServletCtx()
|
javax.servlet.Servlet |
getServletInstance()
Return the Servlet instance used by this ServletHandler |
java.lang.String |
getServletPath()
Returns the part of this request's URL that calls the servlet. |
boolean |
isLoadOnStartup()
|
protected void |
loadServlet()
Load a Servlet instance. |
ServletHandler |
newServletHandler(javax.servlet.Servlet servlet)
Create a new ServletHandler instance that will share the same
ServletContextImpl and Servlet's
listener but with an empty map of init-parameters. |
void |
removeInitParameter(java.lang.String name)
Remove a servlet initialization parameter for this servlet. |
void |
removeProperty(java.lang.String name)
Remove a configured property. |
boolean |
removeServletListener(java.lang.String listenerName)
Remove Servlet listeners that implement EventListener |
void |
service(Request request,
Response response)
|
void |
setClassLoader(java.lang.ClassLoader classLoader)
|
void |
setContextPath(java.lang.String contextPath)
Programmatically set the context path of the Servlet. |
protected void |
setDispatcherHelper(DispatcherHelper dispatcherHelper)
|
void |
setProperty(java.lang.String name,
java.lang.Object value)
Set a configured property. |
void |
setServletInstance(javax.servlet.Servlet servletInstance)
Set the Servlet instance used by this ServletHandler |
void |
setServletPath(java.lang.String servletPath)
Programmatically set the servlet path of the Servlet. |
void |
start()
|
| Methods inherited from class org.glassfish.grizzly.http.server.HttpHandler |
|---|
customizedErrorPage, doHandle, getRequestURIEncoding, isAllowCustomStatusMessage, isAllowEncodedSlash, sendAcknowledgment, setAllowCustomStatusMessage, setAllowEncodedSlash, setDecodeUrl, setRequestURIEncoding, setRequestURIEncoding, updateContextPath |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String LOAD_ON_STARTUP
protected volatile javax.servlet.Servlet servletInstance
protected final java.util.Map<java.lang.String,java.lang.Object> properties
protected boolean initialize
ServletContext
protected java.lang.ClassLoader classLoader
public static final int INCREMENT
| Constructor Detail |
|---|
public ServletHandler()
public ServletHandler(java.lang.String servletName)
public ServletHandler(javax.servlet.Servlet servlet)
servlet - Instance to be used by this adapter.
protected ServletHandler(java.lang.String servletName,
ServletContextImpl servletCtx,
java.util.Map<java.lang.String,java.lang.String> contextParameters,
java.util.Map<java.lang.String,java.lang.String> servletInitParameters,
java.util.List<java.lang.String> listeners)
servletCtx - ServletContextImpl to be used by new instance.contextParameters - Context parameters.servletInitParameters - servlet initialization parameters.listeners - Listeners.
protected ServletHandler(java.lang.String servletName,
ServletContextImpl servletCtx,
java.util.Map<java.lang.String,java.lang.String> contextParameters,
java.util.Map<java.lang.String,java.lang.String> servletInitParameters,
java.util.List<java.lang.String> listeners,
boolean initialize)
servletCtx - ServletContextImpl to be used by new instance.contextParameters - Context parameters.servletInitParameters - servlet initialization parameters.listeners - Listeners.initialize - false only when the newServletHandler(javax.servlet.Servlet) is invoked.
protected ServletHandler(java.lang.String servletName,
ServletContextImpl servletCtx,
java.util.Map<java.lang.String,java.lang.String> contextParameters,
java.util.Map<java.lang.String,java.lang.String> servletInitParameters,
boolean initialize)
servletCtx - ServletContextImpl to be used by new instance.contextParameters - Context parameters.servletInitParameters - servlet initialization parameters.initialize - false only when the newServletHandler(javax.servlet.Servlet) is invoked.
public ServletHandler(javax.servlet.Servlet servlet,
ServletContextImpl servletContext)
| Method Detail |
|---|
public void start()
start in class HttpHandler
protected void configureClassLoader(java.lang.String applicationPath)
throws java.io.IOException
URLClassLoader which has the capability of
loading classes jar under an exploded war application.
applicationPath - Application class path.
java.io.IOException - I/O error.
public void service(Request request,
Response response)
service in class HttpHandler
protected void doServletService(Request request,
Response response)
public void customizeErrorPage(Response response,
java.lang.String message,
int errorCode)
response - the Responsemessage - the HTTP error messageerrorCode - the error code.
protected void loadServlet()
throws javax.servlet.ServletException
Servlet instance.
javax.servlet.ServletException - If failed to
Servlet.init(javax.servlet.ServletConfig).
protected void configureServletEnv()
throws javax.servlet.ServletException
ServletContextImpl
and ServletConfigImpl
javax.servlet.ServletException - Error while configuring
Servlet.
public void addInitParameter(java.lang.String name,
java.lang.String value)
name - Name of this initialization parameter to addvalue - Value of this initialization parameter to addpublic void removeInitParameter(java.lang.String name)
name - Name of this initialization parameter to removepublic java.lang.String getInitParameter(java.lang.String name)
name - Name of this initialization parameter to retrievepublic boolean containsInitParameter(java.lang.String name)
name - Name of this initialization parameter
public void addContextParameter(java.lang.String name,
java.lang.String value)
name - Name of this initialization parameter to addvalue - Value of this initialization parameter to add
public void addFilter(javax.servlet.Filter filter,
java.lang.String filterName,
java.util.Map initParameters)
Filter to the FilterChain.
filter - an instance of FilterfilterName - the Filter's nameinitParameters - the Filter init parameters.public javax.servlet.Servlet getServletInstance()
Servlet instance used by this ServletHandler
Servlet instance.public void setServletInstance(javax.servlet.Servlet servletInstance)
Servlet instance used by this ServletHandler
servletInstance - an instance of Servlet.public java.lang.String getServletPath()
This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.
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.public void setServletPath(java.lang.String servletPath)
servletPath - Path of Servlet.public java.lang.String getContextPath()
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.
String specifying the
portion of the request URI that indicates the context
of the requestServletContext.getContextPath()public void setContextPath(java.lang.String contextPath)
contextPath - Context path.public void addServletListener(java.lang.String listenerName)
EventListener
listenerName - name of a Servlet listenerpublic boolean removeServletListener(java.lang.String listenerName)
EventListener
listenerName - name of a Servlet listener to removepublic java.lang.Object getProperty(java.lang.String name)
ServletContextImpl
and ServletConfigImpl
name - Name of property to get.
public void setProperty(java.lang.String name,
java.lang.Object value)
ServletContextImpl
and ServletConfigImpl.
Use this method to map what's you usually
have in a web.xml like display-name, context-param, etc.
name - Name of the property to setvalue - of the property.public void removeProperty(java.lang.String name)
ServletContextImpl
and ServletConfigImpl
name - Property name to remove.public boolean isLoadOnStartup()
public void destroy()
ServletContextListener
destroy in class HttpHandlerpublic ServletHandler newServletHandler(javax.servlet.Servlet servlet)
ServletHandler instance that will share the same
ServletContextImpl and Servlet's
listener but with an empty map of init-parameters.
servlet - - The Servlet associated with the ServletHandler
ServletHandlerprotected ServletContextImpl getServletCtx()
protected java.util.List<java.lang.String> getListeners()
protected java.util.Map<java.lang.String,java.lang.String> getContextParameters()
public java.lang.ClassLoader getClassLoader()
public void setClassLoader(java.lang.ClassLoader classLoader)
public java.lang.String getName()
getName in class HttpHandlerprotected void addFilter(FilterConfigImpl filterConfig)
filterConfig - The FilterConfig for the servlet to be executedprotected void setDispatcherHelper(DispatcherHelper dispatcherHelper)
setDispatcherHelper in class HttpHandler
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||