@ManagedObject(value="URI Context") public class ContextHandler extends ScopedHandler implements Attributes, 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)
This servers executore is made available via a context attributed "org.eclipse.jetty.server.Executor".
Modifier and Type | Class and Description |
---|---|
static interface |
ContextHandler.AliasCheck
Interface to check aliases
|
static class |
ContextHandler.ApproveAliases
Approve all aliases.
|
static class |
ContextHandler.ApproveNonExistentDirectoryAliases
Approve Aliases of a non existent directory.
|
static class |
ContextHandler.ApprovePathPrefixAliases
Deprecated.
|
static class |
ContextHandler.ApproveSameSuffixAliases
Deprecated.
|
static class |
ContextHandler.Availability |
class |
ContextHandler.Context
Context.
|
static class |
ContextHandler.NoContext |
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
protected ContextHandler.Context |
_scontext |
static int |
DEFAULT_LISTENER_TYPE_INDEX |
static int |
EXTENDED_LISTENER_TYPE_INDEX |
static String |
MANAGED_ATTRIBUTES
If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name.
|
static Class<?>[] |
SERVLET_LISTENER_TYPES |
static int |
SERVLET_MAJOR_VERSION |
static int |
SERVLET_MINOR_VERSION |
_nextScope, _outerScope
_handler
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) |
protected void |
addProgrammaticListener(EventListener listener)
Apply any necessary restrictions on a programmatic added listener.
|
void |
addVirtualHosts(String[] virtualHosts)
Either set virtual hosts or add to an existing set of virtual hosts.
|
protected void |
callContextDestroyed(ServletContextListener l,
ServletContextEvent e) |
protected void |
callContextInitialized(ServletContextListener l,
ServletContextEvent e) |
boolean |
checkAlias(String path,
Resource resource) |
boolean |
checkContext(String target,
Request baseRequest,
HttpServletResponse response) |
boolean |
checkContextPath(String uri) |
void |
checkManagedAttribute(String name,
Object value) |
boolean |
checkVirtualHost(Request baseRequest) |
void |
clearAttributes() |
void |
doHandle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) |
void |
doScope(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) |
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
void |
dump(Appendable out,
String indent) |
List<ContextHandler.AliasCheck> |
getAliasChecks() |
boolean |
getAllowNullPathInfo() |
Object |
getAttribute(String name) |
Enumeration<String> |
getAttributeNames() |
Attributes |
getAttributes() |
Resource |
getBaseResource() |
ClassLoader |
getClassLoader() |
String |
getClassPath()
Make best effort to extract a file classpath from the context classloader
|
static ContextHandler |
getContextHandler(ServletContext context) |
String |
getContextPath() |
static ContextHandler.Context |
getCurrentContext()
Get the current ServletContext implementation.
|
String |
getDisplayName() |
ErrorHandler |
getErrorHandler() |
EventListener[] |
getEventListeners() |
String |
getInitParameter(String name) |
Enumeration<String> |
getInitParameterNames() |
Map<String,String> |
getInitParams() |
String |
getLocaleEncoding(Locale locale)
Get the character encoding for a locale.
|
String |
getLocaleEncoding(String locale) |
Map<String,String> |
getLocaleEncodings()
Get all of the locale encodings
|
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 |
isAvailable() |
boolean |
isCompactPath() |
protected boolean |
isProgrammaticListener(EventListener listener) |
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(URI uri)
Convert URL to Resource wrapper for
Resource.newResource(URL) enables extensions to provide alternate resource implementations. |
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 |
removeEventListener(EventListener listener)
Remove a context event listeners.
|
void |
removeVirtualHosts(String[] virtualHosts)
Removes an array of virtual host entries, if this removes all entries the _vhosts will be set to null
|
void |
setAliasChecks(List<ContextHandler.AliasCheck> checks) |
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)
Set the base resource for this context.
|
void |
setClassLoader(ClassLoader classLoader) |
void |
setCompactPath(boolean compactPath) |
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)
Set the base resource for this context.
|
void |
setServer(Server server) |
void |
setVirtualHosts(String[] vhosts)
Set the virtual hosts for the context.
|
void |
setWelcomeFiles(String[] files) |
Future<Void> |
shutdown()
Set shutdown status.
|
protected void |
startContext()
Extensible startContext.
|
String |
toString() |
handle, never, nextHandle, nextScope
destroy, expandChildren, getHandler, getHandlers, setHandler
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
dumpThis, getServer
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, 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 int SERVLET_MAJOR_VERSION
public static final int SERVLET_MINOR_VERSION
public static final Class<?>[] SERVLET_LISTENER_TYPES
public static final int DEFAULT_LISTENER_TYPE_INDEX
public static final int EXTENDED_LISTENER_TYPE_INDEX
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 static ContextHandler getContextHandler(ServletContext context)
public void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
dump
in class ContainerLifeCycle
IOException
public ContextHandler.Context getServletContext()
@ManagedAttribute(value="Checks if the /context is not redirected to /context/") 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. Hosts may start with '@', in which case they
will match the Connector#getName()
for the request.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. Host names may start with '@', in which case they
will match the Connector#getName()
for the request.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.@ManagedAttribute(value="Virtual hosts accepted by the context", readonly=true) public String[] getVirtualHosts()
public Object getAttribute(String name)
getAttribute
in interface Attributes
public Enumeration<String> getAttributeNames()
getAttributeNames
in interface Attributes
public Attributes getAttributes()
public ClassLoader getClassLoader()
@ManagedAttribute(value="The file classpath") public String getClassPath()
@ManagedAttribute(value="True if URLs are compacted to replace the multiple \'/\'s with a single \'/\'") public String getContextPath()
public Enumeration<String> getInitParameterNames()
@ManagedAttribute(value="Initial Parameter map for the context") public Map<String,String> getInitParams()
@ManagedAttribute(value="Display name of the Context", readonly=true) public String getDisplayName()
public EventListener[] getEventListeners()
public void setEventListeners(EventListener[] eventListeners)
eventListeners
- the event listenersServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
public void addEventListener(EventListener listener)
public void removeEventListener(EventListener listener)
protected void addProgrammaticListener(EventListener listener)
listener
- protected boolean isProgrammaticListener(EventListener listener)
@ManagedAttribute(value="true for graceful shutdown, which allows existing requests to complete") public boolean isShutdown()
public Future<Void> shutdown()
public boolean isAvailable()
public void setAvailable(boolean available)
public Logger getLogger()
public void setLogger(Logger logger)
protected void doStart() throws Exception
ContainerLifeCycle
doStart
in class ScopedHandler
Exception
AbstractHandler.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
protected void callContextInitialized(ServletContextListener l, ServletContextEvent e)
protected void callContextDestroyed(ServletContextListener l, ServletContextEvent e)
protected void doStop() throws Exception
ContainerLifeCycle
doStop
in class AbstractHandler
Exception
public boolean checkVirtualHost(Request baseRequest)
public boolean checkContextPath(String uri)
public boolean checkContext(String target, Request baseRequest, HttpServletResponse response) throws IOException
IOException
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
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)
targets
- Array of URL prefix. Each prefix is in the form /path and will match
either /path exactly or /path/anythingpublic 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()
@ManagedAttribute(value="document root for context") public String getResourceBase()
public void setBaseResource(Resource base)
base
- The resource used as the base for all static content of this context.setResourceBase(String)
public void setResourceBase(String resourceBase)
resourceBase
- A string representing the base resource for the context. Any string accepted
by Resource.newResource(String)
may be passed and the call is equivalent to
setBaseResource(newResource(resourceBase));
public MimeTypes getMimeTypes()
public void setMimeTypes(MimeTypes mimeTypes)
mimeTypes
- The mimeTypes to set.public void setWelcomeFiles(String[] files)
@ManagedAttribute(value="Partial URIs of directory welcome files", readonly=true) public String[] getWelcomeFiles()
setWelcomeFiles(java.lang.String[])
@ManagedAttribute(value="The error handler to use for the context") public ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- The errorHandler to set.@ManagedAttribute(value="The maximum content size") 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 Map<String,String> getLocaleEncodings()
public Resource getResource(String path) throws MalformedURLException
MalformedURLException
public boolean checkAlias(String path, Resource resource)
path
- resource
- public Resource newResource(URL url) throws IOException
Resource.newResource(URL)
enables extensions to provide alternate resource implementations.IOException
public Resource newResource(URI uri) 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()
public void setAliasChecks(List<ContextHandler.AliasCheck> checks)
checks
- list of AliasCheck instancesCopyright © 1995-2015 Webtide. All Rights Reserved.