public class ContextHandler extends ScopedHandler implements Attributes, Server.Graceful
If the context init parameter "org.eclipse.jetty.server.context.ManagedAttributes" is set to a comma separated list of names, then they are treated as context attribute names, which if set as attributes are passed to the servers Container so that they may be managed with JMX.
The maximum size of a form that can be processed by this context is controlled by the system properties org.eclipse.jetty.server.Request.maxFormKeys
and org.eclipse.jetty.server.Request.maxFormContentSize. These can also be configured with setMaxFormContentSize(int)
and setMaxFormKeys(int)
Modifier and Type | Class and Description |
---|---|
static interface |
ContextHandler.AliasCheck
Interface to check aliases
|
static class |
ContextHandler.ApproveNonExistentDirectoryAliases
Approve Aliases of a non existent directory.
|
static class |
ContextHandler.ApprovePathPrefixAliases
Approve Aliases with a path prefix.
|
static class |
ContextHandler.ApproveSameSuffixAliases
Approve Aliases with same suffix.
|
class |
ContextHandler.Context
Context.
|
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Modifier and Type | Field and Description |
---|---|
protected ContextHandler.Context |
_scontext |
static String |
MANAGED_ATTRIBUTES
If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name.
|
_nextScope, _outerScope
_handler
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
Modifier | Constructor and Description |
---|---|
|
ContextHandler() |
protected |
ContextHandler(ContextHandler.Context context) |
|
ContextHandler(HandlerContainer parent,
String contextPath) |
|
ContextHandler(String contextPath) |
Modifier and Type | Method and Description |
---|---|
void |
addAliasCheck(ContextHandler.AliasCheck check)
Add an AliasCheck instance to possibly permit aliased resources
|
void |
addEventListener(EventListener listener)
Add a context event listeners.
|
void |
addLocaleEncoding(String locale,
String encoding) |
void |
addVirtualHosts(String[] virtualHosts)
Either set virtual hosts or add to an existing set of virtual hosts.
|
void |
callContextDestroyed(javax.servlet.ServletContextListener l,
javax.servlet.ServletContextEvent e) |
void |
callContextInitialized(javax.servlet.ServletContextListener l,
javax.servlet.ServletContextEvent e) |
boolean |
checkContext(String target,
Request baseRequest,
javax.servlet.http.HttpServletResponse response) |
void |
checkManagedAttribute(String name,
Object value) |
void |
clearAttributes() |
void |
doHandle(String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
void |
doScope(String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
doStart() |
protected void |
doStop() |
void |
dump(Appendable out,
String indent) |
List<ContextHandler.AliasCheck> |
getAliasChecks() |
boolean |
getAllowNullPathInfo() |
Object |
getAttribute(String name) |
Enumeration |
getAttributeNames() |
Attributes |
getAttributes() |
Resource |
getBaseResource() |
ClassLoader |
getClassLoader() |
String |
getClassPath()
Make best effort to extract a file classpath from the context classloader
|
String[] |
getConnectorNames() |
String |
getContextPath() |
static ContextHandler.Context |
getCurrentContext()
Get the current ServletContext implementation.
|
String |
getDisplayName() |
ErrorHandler |
getErrorHandler() |
EventListener[] |
getEventListeners() |
String |
getInitParameter(String name) |
Enumeration |
getInitParameterNames() |
Map<String,String> |
getInitParams() |
String |
getLocaleEncoding(Locale locale)
Get the character encoding for a locale.
|
String |
getLocaleEncoding(String locale) |
Logger |
getLogger() |
int |
getMaxFormContentSize() |
int |
getMaxFormKeys() |
MimeTypes |
getMimeTypes() |
String[] |
getProtectedTargets() |
Resource |
getResource(String path) |
String |
getResourceBase() |
Set<String> |
getResourcePaths(String path) |
ContextHandler.Context |
getServletContext() |
String[] |
getVirtualHosts()
Get the virtual hosts for the context.
|
String[] |
getWelcomeFiles() |
void |
handle(Runnable runnable) |
boolean |
isAliases() |
boolean |
isAvailable() |
boolean |
isCompactPath() |
boolean |
isProtectedTarget(String target)
Check the target.
|
boolean |
isShutdown() |
Class<?> |
loadClass(String className) |
Resource |
newResource(String urlOrPath)
Convert a URL or path to a Resource.
|
Resource |
newResource(URL url)
Convert URL to Resource wrapper for
Resource.newResource(URL) enables extensions to provide alternate resource implementations. |
void |
removeAttribute(String name) |
void |
removeVirtualHosts(String[] virtualHosts)
Removes an array of virtual host entries, if this removes all entries the _vhosts will be set to null
|
void |
restrictEventListener(EventListener listener)
Apply any necessary restrictions on a programmatically added
listener.
|
void |
setAliases(boolean aliases) |
void |
setAllowNullPathInfo(boolean allowNullPathInfo) |
void |
setAttribute(String name,
Object value) |
void |
setAttributes(Attributes attributes) |
void |
setAvailable(boolean available)
Set Available status.
|
void |
setBaseResource(Resource base) |
void |
setClassLoader(ClassLoader classLoader) |
void |
setCompactPath(boolean compactPath) |
void |
setConnectorNames(String[] connectors)
Set the names of accepted connectors.
|
void |
setContextPath(String contextPath) |
void |
setDisplayName(String servletContextName) |
void |
setErrorHandler(ErrorHandler errorHandler) |
void |
setEventListeners(EventListener[] eventListeners)
Set the context event listeners.
|
String |
setInitParameter(String name,
String value) |
void |
setLogger(Logger logger) |
void |
setManagedAttribute(String name,
Object value) |
void |
setMaxFormContentSize(int maxSize)
Set the maximum size of a form post, to protect against DOS attacks from large forms.
|
void |
setMaxFormKeys(int max)
Set the maximum number of form Keys to protect against DOS attack from crafted hash keys.
|
void |
setMimeTypes(MimeTypes mimeTypes) |
void |
setProtectedTargets(String[] targets) |
void |
setResourceBase(String resourceBase) |
void |
setServer(Server server) |
void |
setShutdown(boolean shutdown)
Set shutdown status.
|
void |
setVirtualHosts(String[] vhosts)
Set the virtual hosts for the context.
|
void |
setWelcomeFiles(String[] files) |
protected void |
startContext()
Extensible startContext.
|
String |
toString() |
handle, never, nextHandle, nextScope
destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
dumpThis, getServer
addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public static final String MANAGED_ATTRIBUTES
setManagedAttribute(String, Object)
, which typically initiates the creation of a JMX MBean
for the attribute value.protected ContextHandler.Context _scontext
public ContextHandler()
protected ContextHandler(ContextHandler.Context context)
public ContextHandler(String contextPath)
public ContextHandler(HandlerContainer parent, String contextPath)
public static ContextHandler.Context getCurrentContext()
public void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
dump
in class AbstractHandlerContainer
IOException
public ContextHandler.Context getServletContext()
public boolean getAllowNullPathInfo()
public void setAllowNullPathInfo(boolean allowNullPathInfo)
allowNullPathInfo
- true if /context is not redirected to /context/public void setServer(Server server)
setServer
in interface Handler
setServer
in class HandlerWrapper
public void setVirtualHosts(String[] vhosts)
vhosts
- Array of virtual hosts that this context responds to. A null host name or null/empty array means any hostname is acceptable. Host names may be
String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.public void addVirtualHosts(String[] virtualHosts)
virtualHosts
- Array of virtual hosts that this context responds to. A null host name or null/empty array means any hostname is acceptable. Host names may be
String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.public void removeVirtualHosts(String[] virtualHosts)
virtualHosts
- Array of virtual hosts that this context responds to. A null host name or null/empty array means any hostname is acceptable. Host names may be
String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.public String[] getVirtualHosts()
public String[] getConnectorNames()
public void setConnectorNames(String[] connectors)
connectors
- If non null, an array of connector names that this context will accept a request from.public Object getAttribute(String name)
getAttribute
in interface Attributes
public Enumeration getAttributeNames()
getAttributeNames
in interface Attributes
public Attributes getAttributes()
public ClassLoader getClassLoader()
public String getClassPath()
public String getContextPath()
public Enumeration getInitParameterNames()
public String getDisplayName()
public EventListener[] getEventListeners()
public void setEventListeners(EventListener[] eventListeners)
eventListeners
- the event listenersServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
public void addEventListener(EventListener listener)
ServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
public void restrictEventListener(EventListener listener)
listener
- public boolean isShutdown()
public void setShutdown(boolean shutdown)
setShutdown
in interface Server.Graceful
shutdown
- true if this context is (not?) accepting new requestspublic boolean isAvailable()
public void setAvailable(boolean available)
public Logger getLogger()
public void setLogger(Logger logger)
protected void doStart() throws Exception
doStart
in class ScopedHandler
Exception
HandlerWrapper.doStart()
protected void startContext() throws Exception
doStart()
instead of a call to super.doStart(). This allows derived classes to
insert additional handling (Eg configuration) before the call to super.doStart by this method will start contained handlers.Exception
ContextHandler.Context
public void callContextInitialized(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
public void callContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
protected void doStop() throws Exception
doStop
in class HandlerWrapper
Exception
public boolean checkContext(String target, Request baseRequest, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void doScope(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
doScope
in class ScopedHandler
IOException
javax.servlet.ServletException
ScopedHandler.doScope(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
public void doHandle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
doHandle
in class ScopedHandler
IOException
javax.servlet.ServletException
ScopedHandler.doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
public void handle(Runnable runnable)
public boolean isProtectedTarget(String target)
ScopedHandler.handle(String, Request, HttpServletRequest, HttpServletResponse)
when a target within a context is determined. If
the target is protected, 404 is returned.public void setProtectedTargets(String[] targets)
public String[] getProtectedTargets()
public void removeAttribute(String name)
removeAttribute
in interface Attributes
public void setAttribute(String name, Object value)
setAttribute
in interface Attributes
public void setAttributes(Attributes attributes)
attributes
- The attributes to set.public void clearAttributes()
clearAttributes
in interface Attributes
public void setClassLoader(ClassLoader classLoader)
classLoader
- The classLoader to set.public void setContextPath(String contextPath)
contextPath
- The _contextPath to set.public void setDisplayName(String servletContextName)
servletContextName
- The servletContextName to set.public Resource getBaseResource()
public String getResourceBase()
public void setBaseResource(Resource base)
base
- The resourceBase to set.public void setResourceBase(String resourceBase)
resourceBase
- The base resource as a string.public boolean isAliases()
public void setAliases(boolean aliases)
aliases
- aliases are allowedpublic MimeTypes getMimeTypes()
public void setMimeTypes(MimeTypes mimeTypes)
mimeTypes
- The mimeTypes to set.public void setWelcomeFiles(String[] files)
public String[] getWelcomeFiles()
setWelcomeFiles(java.lang.String[])
public ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- The errorHandler to set.public int getMaxFormContentSize()
public void setMaxFormContentSize(int maxSize)
maxSize
- public int getMaxFormKeys()
public void setMaxFormKeys(int max)
max
- public boolean isCompactPath()
public void setCompactPath(boolean compactPath)
compactPath
- True if URLs are compacted to replace multiple '/'s with a single '/'public Class<?> loadClass(String className) throws ClassNotFoundException
ClassNotFoundException
public String getLocaleEncoding(Locale locale)
locale
- a Locale
valueString
representing the character encoding for the locale or null if none found.public Resource getResource(String path) throws MalformedURLException
MalformedURLException
public Resource newResource(URL url) throws IOException
Resource.newResource(URL)
enables extensions to provide alternate resource implementations.IOException
public Resource newResource(String urlOrPath) throws IOException
Resource.newResource(String)
.urlOrPath
- The URL or path to convertIOException
- The Resource could not be created.public void addAliasCheck(ContextHandler.AliasCheck check)
check
- The alias checkerpublic List<ContextHandler.AliasCheck> getAliasChecks()
Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.