@ManagedObject(value="URI Context") public class ContextHandler extends ScopedHandler implements Attributes, Graceful
This handler wraps a call to handle by setting the context and servlet path, plus setting the context classloader.
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)
The executor is made available via a context attributed org.eclipse.jetty.server.Executor
.
By default, the context is created with alias checkers for AllowSymLinkAliasChecker
(unix only) and ContextHandler.ApproveNonExistentDirectoryAliases
. If
these alias checkers are not required, then clearAliasChecks()
or setAliasChecks(List)
should be called.
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.Availability |
class |
ContextHandler.Context
Context.
|
static interface |
ContextHandler.ContextScopeListener
Listener for all threads entering context scope, including async IO callbacks
|
static class |
ContextHandler.ContextStatus |
static class |
ContextHandler.StaticContext
A simple implementation of ServletContext that is used when there is no
ContextHandler.
|
AbstractHandler.ErrorDispatchHandler
AbstractLifeCycle.AbstractLifeCycleListener
Attributes.Wrapper
Graceful.Shutdown
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_LISTENER_TYPE_INDEX |
static int |
DEFAULT_MAX_FORM_CONTENT_SIZE |
static int |
DEFAULT_MAX_FORM_KEYS |
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 String |
MAX_FORM_CONTENT_SIZE_KEY |
static String |
MAX_FORM_KEYS_KEY |
static Class<?>[] |
SERVLET_LISTENER_TYPES |
static int |
SERVLET_MAJOR_VERSION |
static int |
SERVLET_MINOR_VERSION |
Constructor and Description |
---|
ContextHandler() |
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.
|
boolean |
checkAlias(String path,
Resource resource) |
boolean |
checkContext(String target,
Request baseRequest,
HttpServletResponse response) |
boolean |
checkContextPath(String uri) |
boolean |
checkVirtualHost(Request baseRequest) |
void |
clearAliasChecks()
clear the list of AliasChecks
|
void |
clearAttributes() |
void |
contextDestroyed()
Call the ServletContextListeners with contextDestroyed.
|
void |
contextInitialized()
Call the ServletContextListeners contextInitialized methods.
|
void |
doHandle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
Do the handler work within the scope.
|
void |
doScope(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
Scope the handler
|
void |
dump(Appendable out,
String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
List<ContextHandler.AliasCheck> |
getAliasChecks() |
boolean |
getAllowNullPathInfo() |
Object |
getAttribute(String name) |
Enumeration<String> |
getAttributeNames() |
Set<String> |
getAttributeNameSet() |
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() |
String |
getContextPathEncoded() |
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) |
static String |
getServerInfo() |
ContextHandler.Context |
getServletContext() |
String[] |
getVirtualHosts()
Get the virtual hosts for the context.
|
String[] |
getWelcomeFiles() |
void |
handle(Request request,
Runnable runnable)
Handle a runnable in the scope of this context and a particular request
|
void |
handle(Runnable runnable) |
boolean |
isAvailable() |
boolean |
isCompactPath() |
boolean |
isDurableListener(EventListener listener) |
boolean |
isProgrammaticListener(EventListener listener) |
boolean |
isProtectedTarget(String target)
Check the target.
|
boolean |
isShutdown() |
boolean |
isUsingSecurityManager() |
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)
Deprecated.
|
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) |
static void |
setServerInfo(String serverInfo) |
void |
setUsingSecurityManager(boolean usingSecurityManager) |
void |
setVirtualHosts(String[] vhosts)
Set the virtual hosts for the context.
|
void |
setWelcomeFiles(String[] files) |
Future<Void> |
shutdown()
Set shutdown status.
|
String |
toString() |
handle, nextHandle, nextScope
destroy, getHandler, getHandlers, insertHandler, setHandler
findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
getServer
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
unwrap
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stop
dumpContainer, dumpIterable, dumpMapEntries, dumpObjects, dumpSelf, named
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.public static final String MAX_FORM_KEYS_KEY
public static final String MAX_FORM_CONTENT_SIZE_KEY
public static final int DEFAULT_MAX_FORM_KEYS
public static final int DEFAULT_MAX_FORM_CONTENT_SIZE
public ContextHandler()
public ContextHandler(String contextPath)
public ContextHandler(HandlerContainer parent, String contextPath)
public static ContextHandler.Context getCurrentContext()
public static ContextHandler getContextHandler(ServletContext context)
public static String getServerInfo()
public static void setServerInfo(String serverInfo)
public void dump(Appendable out, String indent) throws IOException
Dumpable
dump
in interface Dumpable
dump
in class ContainerLifeCycle
out
- The appendable to dump toindent
- The indent to apply after any new lines.IOException
- if unable to write to Appendablepublic 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 AbstractHandlerContainer
public boolean isUsingSecurityManager()
public void setUsingSecurityManager(boolean usingSecurityManager)
public void setVirtualHosts(String[] vhosts)
vhosts
- Array of virtual hosts that this context responds to. A 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 and wildcard hosts may be followed with
'@connectorname', in which case they will match only if the the Connector.getName()
for the request also matches. If an entry is just
'@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed
and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only
entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning
can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.public void addVirtualHosts(String[] virtualHosts)
virtualHosts
- Array of virtual hosts that this context responds to. A 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 and wildcard hosts may be followed with
'@connectorname', in which case they will match only if the the Connector.getName()
for the request also matches. If an entry is just
'@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed
and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only
entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning
can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.public void removeVirtualHosts(String[] virtualHosts)
virtualHosts
- Array of virtual hosts that this context responds to. A 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 and wildcard hosts may be followed with
'@connectorname', in which case they will match only if the the Connector.getName()
for the request also matches. If an entry is just
'@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed
and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only
entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning
can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.@ManagedAttribute(value="Virtual hosts accepted by the context", readonly=true) public String[] getVirtualHosts()
Connector.getName()
for the request also matches. If an entry is just
'@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed
and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only
entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning
can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.public Object getAttribute(String name)
getAttribute
in interface Attributes
public Enumeration<String> getAttributeNames()
getAttributeNames
in interface Attributes
public Set<String> getAttributeNameSet()
getAttributeNameSet
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 String getContextPathEncoded()
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)
listener
- the event listener to addServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
public void removeEventListener(EventListener listener)
listener
- the event listener to removeServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
public boolean isProgrammaticListener(EventListener listener)
public boolean isDurableListener(EventListener listener)
@ManagedAttribute(value="true for graceful shutdown, which allows existing requests to complete") public boolean isShutdown()
isShutdown
in interface Graceful
public Future<Void> shutdown()
public boolean isAvailable()
public void setAvailable(boolean available)
available
- true to set as enabledpublic Logger getLogger()
public void setLogger(Logger logger)
public void contextInitialized() throws Exception
Exception
public void contextDestroyed() throws Exception
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
ScopedHandler
Derived implementations should call ScopedHandler.nextScope(String, Request, HttpServletRequest, HttpServletResponse)
doScope
in class ScopedHandler
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as the Request
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.IOException
- if unable to handle the request or response processingServletException
- if unable to handle the request or response due to underlying servlet issueScopedHandler.doScope(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
ScopedHandler
Derived implementations should call ScopedHandler.nextHandle(String, Request, HttpServletRequest, HttpServletResponse)
doHandle
in class ScopedHandler
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as the Request
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.IOException
- if unable to handle the request or response processingServletException
- if unable to handle the request or response due to underlying servlet issueScopedHandler.doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
public void handle(Request request, Runnable runnable)
request
- The request to scope the thread to (may be null if no particular request is in scope)runnable
- The runnable to run.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.target
- the target to testpublic 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
@Deprecated public void setManagedAttribute(String name, Object value)
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
- the maximum size of the form content (in bytes)public int getMaxFormKeys()
public void setMaxFormKeys(int max)
max
- the maximum number of form keyspublic boolean isCompactPath()
public void setCompactPath(boolean compactPath)
compactPath
- True if URLs are compacted to replace multiple '/'s with a single '/'public String toString()
toString
in class AbstractLifeCycle
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
- the path to check the alias forresource
- the resourcepublic Resource newResource(URL url) throws IOException
Resource.newResource(URL)
enables extensions to provide alternate resource implementations.url
- the url to convert to a ResourceIOException
- if unable to create a Resource from the URLpublic Resource newResource(URI uri) throws IOException
Resource.newResource(URL)
enables extensions to provide alternate resource implementations.uri
- the URI to convert to a ResourceIOException
- if unable to create a Resource from the URLpublic 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 instancespublic void clearAliasChecks()
Copyright © 2010 - 2020 Adobe. All Rights Reserved