public class ServletHandler extends Container implements HttpHandler
This handler does not implement the full J2EE features and is intended to be used when a full web application is not required. Specifically filters and request wrapping are not supported.
If a SessionManager is not added to the handler before it is initialized, then a HashSessionManager with a standard java.util.Random generator is created.
WebApplicationHandler
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
__DEFAULT_SERVLET |
static String |
__J_S_CONTEXT_TEMPDIR |
static String |
__J_S_ERROR_EXCEPTION |
static String |
__J_S_ERROR_EXCEPTION_TYPE |
static String |
__J_S_ERROR_MESSAGE |
static String |
__J_S_ERROR_REQUEST_URI |
static String |
__J_S_ERROR_SERVLET_NAME |
static String |
__J_S_ERROR_STATUS_CODE |
protected Map |
_attributes |
protected org.openqa.jetty.jetty.servlet.ServletHandler.Context |
_context |
protected org.apache.commons.logging.Log |
_contextLog |
protected String |
_formErrorPage |
protected String |
_formLoginPage |
protected HttpContext |
_httpContext |
protected ClassLoader |
_loader |
protected Map |
_nameMap |
protected PathMap |
_servletMap |
protected SessionManager |
_sessionManager |
Constructor and Description |
---|
ServletHandler()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
ServletHolder |
addServlet(String pathSpec,
String servletClass)
Add a servlet instance to this handler and map it to a pathspec.
|
ServletHolder |
addServlet(String name,
String pathSpec,
String servletClass)
Add a servlet.
|
ServletHolder |
addServlet(String name,
String pathSpec,
String servletClass,
String forcedPath)
Add a servlet.
|
void |
addServletHolder(ServletHolder holder)
Register an existing ServletHolder with this handler.
|
void |
destroy()
Destroy a stopped server.
|
protected void |
dispatch(String pathInContext,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
ServletHolder servletHolder,
int type)
Dispatch to a servletHolder.
|
protected void |
doStart()
Do start operations.
|
protected void |
doStop()
Do stop operations.
|
protected void |
finalize() |
void |
formAuthInit(String formLoginPage,
String formErrorPage) |
ClassLoader |
getClassLoader() |
protected Object |
getContextAttribute(String name)
Get context attribute.
|
protected Enumeration |
getContextAttributeNames()
Get context attribute names.
|
String |
getErrorPage(int status,
ServletHttpRequest request) |
Map.Entry |
getHolderEntry(String pathInContext)
ServletHolder matching path.
|
HttpContext |
getHttpContext() |
javax.servlet.http.HttpSession |
getHttpSession(String id) |
String |
getName()
Get the name of the handler.
|
javax.servlet.RequestDispatcher |
getNamedDispatcher(String name)
Get Named dispatcher.
|
String |
getRealPath(String path) |
javax.servlet.RequestDispatcher |
getRequestDispatcher(String uriInContext) |
URL |
getResource(String uriInContext)
Get a Resource.
|
InputStream |
getResourceAsStream(String uriInContext) |
Set |
getResourcePaths(String uriInContext) |
javax.servlet.ServletContext |
getServletContext() |
ServletHolder |
getServletHolder(String name) |
PathMap |
getServletMap() |
ServletHolder[] |
getServlets()
Get Servlets.
|
SessionManager |
getSessionManager() |
void |
handle(String pathInContext,
String pathParams,
HttpRequest httpRequest,
HttpResponse httpResponse)
Handle request.
|
protected void |
handleOptions(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
void |
handleTrace(HttpRequest request,
HttpResponse response) |
protected void |
handleTrace(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
void |
initialize(HttpContext context) |
void |
initializeServlets()
Initialize load-on-startup servlets.
|
boolean |
isAutoInitializeServlets() |
boolean |
isUsingCookies() |
ServletHolder |
mapPathToServlet(String pathSpec,
String servletName)
Map a servlet to a pathSpec
|
javax.servlet.http.HttpSession |
newHttpSession(javax.servlet.http.HttpServletRequest request) |
ServletHolder |
newServletHolder(String name,
String servletClass) |
ServletHolder |
newServletHolder(String name,
String servletClass,
String forcedPath) |
protected void |
notFound(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
removeContextAttribute(String name) |
void |
setAutoInitializeServlets(boolean b) |
protected void |
setContextAttribute(String name,
Object value) |
void |
setDynamicInitParams(Map initParams)
Deprecated.
Use org.openqa.jetty.jetty.servlet.Invoker
|
void |
setDynamicServletPathSpec(String dynamicServletPathSpec)
Deprecated.
Use org.openqa.jetty.jetty.servlet.Invoker
|
void |
setName(String name) |
void |
setServeDynamicSystemServlets(boolean b)
Deprecated.
Use org.openqa.jetty.jetty.servlet.Invoker
|
void |
setSessionInactiveInterval(int seconds)
Set the session timeout interval in seconds.
|
void |
setSessionManager(SessionManager sm) |
void |
setUsingCookies(boolean uc) |
addComponent, addEventListener, getComponents, isStarted, isStarting, isStopping, removeComponent, removeEventListener, start, stop
public static final String __DEFAULT_SERVLET
public static final String __J_S_CONTEXT_TEMPDIR
public static final String __J_S_ERROR_EXCEPTION
public static final String __J_S_ERROR_EXCEPTION_TYPE
public static final String __J_S_ERROR_MESSAGE
public static final String __J_S_ERROR_REQUEST_URI
public static final String __J_S_ERROR_SERVLET_NAME
public static final String __J_S_ERROR_STATUS_CODE
protected PathMap _servletMap
protected Map _nameMap
protected Map _attributes
protected String _formLoginPage
protected String _formErrorPage
protected SessionManager _sessionManager
protected transient org.openqa.jetty.jetty.servlet.ServletHandler.Context _context
protected transient ClassLoader _loader
protected transient org.apache.commons.logging.Log _contextLog
protected transient HttpContext _httpContext
public void setName(String name)
public String getName()
HttpHandler
getName
in interface HttpHandler
public HttpContext getHttpContext()
getHttpContext
in interface HttpHandler
public void initialize(HttpContext context)
initialize
in interface HttpHandler
public void setSessionManager(SessionManager sm)
public SessionManager getSessionManager()
public javax.servlet.ServletContext getServletContext()
public PathMap getServletMap()
public boolean isUsingCookies()
public void setDynamicServletPathSpec(String dynamicServletPathSpec)
public void setDynamicInitParams(Map initParams)
public void setServeDynamicSystemServlets(boolean b)
public ClassLoader getClassLoader()
public void setUsingCookies(boolean uc)
uc
- If true, cookies are used for sessionspublic ServletHolder newServletHolder(String name, String servletClass, String forcedPath)
public ServletHolder newServletHolder(String name, String servletClass)
public ServletHolder getServletHolder(String name)
public ServletHolder mapPathToServlet(String pathSpec, String servletName)
pathSpec
- The pathspec to mapservletName
- The name of the servlet, which must have already been added.public ServletHolder addServlet(String name, String pathSpec, String servletClass, String forcedPath)
name
- The servlet name.pathSpec
- A path specification to map this servlet to.servletClass
- The class name of the servlet.forcedPath
- If non null, the request attribute
javax.servlet.include.servlet_path will be set to this path before
service is called.public ServletHolder addServlet(String name, String pathSpec, String servletClass)
name
- The servlet name.pathSpec
- A path specification to map this servlet to.servletClass
- The class name of the servlet.public ServletHolder addServlet(String pathSpec, String servletClass)
pathSpec
- The pathmappingservletClass
- The class of the servletpublic void addServletHolder(ServletHolder holder)
holder
- the ServletHolder to register.public boolean isAutoInitializeServlets()
public void setAutoInitializeServlets(boolean b)
protected void doStart() throws Exception
Container
public ServletHolder[] getServlets()
public void initializeServlets() throws Exception
Exception
protected void doStop() throws Exception
Container
public javax.servlet.http.HttpSession getHttpSession(String id)
public javax.servlet.http.HttpSession newHttpSession(javax.servlet.http.HttpServletRequest request)
public void setSessionInactiveInterval(int seconds)
seconds
- the length of the session timeout interval in seconds.public void handle(String pathInContext, String pathParams, HttpRequest httpRequest, HttpResponse httpResponse) throws IOException
handle
in interface HttpHandler
pathInContext
- pathParams
- httpRequest
- httpResponse
- IOException
protected void dispatch(String pathInContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ServletHolder servletHolder, int type) throws javax.servlet.ServletException, javax.servlet.UnavailableException, IOException
pathInContext
- The path used to select the servlet holder.request
- response
- servletHolder
- type
- the type of dispatch as defined in the Dispatcher class.javax.servlet.ServletException
javax.servlet.UnavailableException
IOException
public Map.Entry getHolderEntry(String pathInContext)
pathInContext
- Path within context.public URL getResource(String uriInContext) throws MalformedURLException
uriInContext
- MalformedURLException
public InputStream getResourceAsStream(String uriInContext)
public javax.servlet.RequestDispatcher getRequestDispatcher(String uriInContext)
public javax.servlet.RequestDispatcher getNamedDispatcher(String name)
name
- The name of the servlet. If null or empty string, the
containers default servlet is returned.protected void notFound(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
IOException
protected void handleTrace(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
IOException
protected void handleOptions(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
IOException
public String getErrorPage(int status, ServletHttpRequest request)
protected Object getContextAttribute(String name)
name
- attribute name.protected Enumeration getContextAttributeNames()
protected void removeContextAttribute(String name)
public void handleTrace(HttpRequest request, HttpResponse response) throws IOException
IOException
public void destroy()
Container
Copyright © 2013. All Rights Reserved.