Handler
, HandlerContainer
, org.eclipse.jetty.util.Attributes
, org.eclipse.jetty.util.component.Destroyable
, org.eclipse.jetty.util.component.Graceful
, org.eclipse.jetty.util.component.LifeCycle
MovedContextHandler
@ManagedObject("URI Context") public class ContextHandler extends ScopedHandler implements org.eclipse.jetty.util.Attributes, org.eclipse.jetty.util.component.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 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 | 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.StaticContext |
AbstractHandler.ErrorDispatchHandler
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
Modifier and Type | Field | Description |
---|---|---|
protected ContextHandler.Context |
_scontext |
|
static int |
DEFAULT_LISTENER_TYPE_INDEX |
|
static int |
EXTENDED_LISTENER_TYPE_INDEX |
|
static java.lang.String |
MANAGED_ATTRIBUTES |
If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name.
|
static java.lang.Class<?>[] |
SERVLET_LISTENER_TYPES |
|
static int |
SERVLET_MAJOR_VERSION |
|
static int |
SERVLET_MINOR_VERSION |
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
_handler
_nextScope, _outerScope
Modifier | Constructor | Description |
---|---|---|
|
ContextHandler() |
|
|
ContextHandler(java.lang.String contextPath) |
|
protected |
ContextHandler(ContextHandler.Context context) |
|
|
ContextHandler(HandlerContainer parent,
java.lang.String contextPath) |
Modifier and Type | Method | Description |
---|---|---|
void |
addAliasCheck(ContextHandler.AliasCheck check) |
Add an AliasCheck instance to possibly permit aliased resources
|
void |
addEventListener(java.util.EventListener listener) |
Add a context event listeners.
|
void |
addLocaleEncoding(java.lang.String locale,
java.lang.String encoding) |
|
protected void |
addProgrammaticListener(java.util.EventListener listener) |
Apply any necessary restrictions on a programmatic added listener.
|
void |
addVirtualHosts(java.lang.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(java.lang.String path,
org.eclipse.jetty.util.resource.Resource resource) |
|
boolean |
checkContext(java.lang.String target,
Request baseRequest,
HttpServletResponse response) |
|
boolean |
checkContextPath(java.lang.String uri) |
|
boolean |
checkVirtualHost(Request baseRequest) |
|
void |
clearAliasChecks() |
clear the list of AliasChecks
|
void |
clearAttributes() |
|
void |
doHandle(java.lang.String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) |
Do the handler work within the scope.
|
void |
doScope(java.lang.String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) |
Scope the handler
|
protected void |
doStart() |
|
protected void |
doStop() |
|
void |
dump(java.lang.Appendable out,
java.lang.String indent) |
|
protected void |
enterScope(Request request,
java.lang.Object reason) |
|
protected void |
exitScope(Request request) |
|
java.util.List<ContextHandler.AliasCheck> |
getAliasChecks() |
|
boolean |
getAllowNullPathInfo() |
|
java.lang.Object |
getAttribute(java.lang.String name) |
|
java.util.Enumeration<java.lang.String> |
getAttributeNames() |
|
org.eclipse.jetty.util.Attributes |
getAttributes() |
|
org.eclipse.jetty.util.resource.Resource |
getBaseResource() |
|
java.lang.ClassLoader |
getClassLoader() |
|
java.lang.String |
getClassPath() |
Make best effort to extract a file classpath from the context classloader
|
static ContextHandler |
getContextHandler(ServletContext context) |
|
java.lang.String |
getContextPath() |
|
java.lang.String |
getContextPathEncoded() |
|
static ContextHandler.Context |
getCurrentContext() |
Get the current ServletContext implementation.
|
java.lang.String |
getDisplayName() |
|
ErrorHandler |
getErrorHandler() |
|
java.util.EventListener[] |
getEventListeners() |
|
java.lang.String |
getInitParameter(java.lang.String name) |
|
java.util.Enumeration<java.lang.String> |
getInitParameterNames() |
|
java.util.Map<java.lang.String,java.lang.String> |
getInitParams() |
|
java.lang.String |
getLocaleEncoding(java.lang.String locale) |
|
java.lang.String |
getLocaleEncoding(java.util.Locale locale) |
Get the character encoding for a locale.
|
java.util.Map<java.lang.String,java.lang.String> |
getLocaleEncodings() |
Get all of the locale encodings
|
org.eclipse.jetty.util.log.Logger |
getLogger() |
|
int |
getMaxFormContentSize() |
|
int |
getMaxFormKeys() |
|
org.eclipse.jetty.http.MimeTypes |
getMimeTypes() |
|
java.lang.String[] |
getProtectedTargets() |
|
org.eclipse.jetty.util.resource.Resource |
getResource(java.lang.String path) |
|
java.lang.String |
getResourceBase() |
|
java.util.Set<java.lang.String> |
getResourcePaths(java.lang.String path) |
|
static java.lang.String |
getServerInfo() |
|
ContextHandler.Context |
getServletContext() |
|
java.lang.String[] |
getVirtualHosts() |
Get the virtual hosts for the context.
|
java.lang.String[] |
getWelcomeFiles() |
|
void |
handle(java.lang.Runnable runnable) |
|
void |
handle(Request request,
java.lang.Runnable runnable) |
Handle a runnable in the scope of this context and a particular request
|
boolean |
isAvailable() |
|
boolean |
isCompactPath() |
|
protected boolean |
isProgrammaticListener(java.util.EventListener listener) |
|
boolean |
isProtectedTarget(java.lang.String target) |
Check the target.
|
boolean |
isShutdown() |
|
boolean |
isUsingSecurityManager() |
|
java.lang.Class<?> |
loadClass(java.lang.String className) |
|
org.eclipse.jetty.util.resource.Resource |
newResource(java.lang.String urlOrPath) |
Convert a URL or path to a Resource.
|
org.eclipse.jetty.util.resource.Resource |
newResource(java.net.URI uri) |
Convert URL to Resource wrapper for
Resource.newResource(URL) enables extensions to provide alternate resource implementations. |
org.eclipse.jetty.util.resource.Resource |
newResource(java.net.URL url) |
Convert URL to Resource wrapper for
Resource.newResource(URL) enables extensions to provide alternate resource implementations. |
void |
removeAttribute(java.lang.String name) |
|
void |
removeEventListener(java.util.EventListener listener) |
Remove a context event listeners.
|
void |
removeVirtualHosts(java.lang.String[] virtualHosts) |
Removes an array of virtual host entries, if this removes all entries the _vhosts will be set to null
|
protected void |
requestDestroyed(Request baseRequest,
HttpServletRequest request) |
|
protected void |
requestInitialized(Request baseRequest,
HttpServletRequest request) |
|
void |
setAliasChecks(java.util.List<ContextHandler.AliasCheck> checks) |
|
void |
setAllowNullPathInfo(boolean allowNullPathInfo) |
|
void |
setAttribute(java.lang.String name,
java.lang.Object value) |
|
void |
setAttributes(org.eclipse.jetty.util.Attributes attributes) |
|
void |
setAvailable(boolean available) |
Set Available status.
|
void |
setBaseResource(org.eclipse.jetty.util.resource.Resource base) |
Set the base resource for this context.
|
void |
setClassLoader(java.lang.ClassLoader classLoader) |
|
void |
setCompactPath(boolean compactPath) |
|
void |
setContextPath(java.lang.String contextPath) |
|
void |
setDisplayName(java.lang.String servletContextName) |
|
void |
setErrorHandler(ErrorHandler errorHandler) |
|
void |
setEventListeners(java.util.EventListener[] eventListeners) |
Set the context event listeners.
|
java.lang.String |
setInitParameter(java.lang.String name,
java.lang.String value) |
|
void |
setLogger(org.eclipse.jetty.util.log.Logger logger) |
|
void |
setManagedAttribute(java.lang.String name,
java.lang.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(org.eclipse.jetty.http.MimeTypes mimeTypes) |
|
void |
setProtectedTargets(java.lang.String[] targets) |
|
void |
setResourceBase(java.lang.String resourceBase) |
Set the base resource for this context.
|
void |
setServer(Server server) |
|
static void |
setServerInfo(java.lang.String serverInfo) |
|
void |
setUsingSecurityManager(boolean usingSecurityManager) |
|
void |
setVirtualHosts(java.lang.String[] vhosts) |
Set the virtual hosts for the context.
|
void |
setWelcomeFiles(java.lang.String[] files) |
|
java.util.concurrent.Future<java.lang.Void> |
shutdown() |
Set shutdown status.
|
protected void |
startContext() |
Extensible startContext.
|
protected void |
stopContext() |
|
java.lang.String |
toString() |
doError, dumpThis, getServer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
handle, nextHandle, nextScope
public static final int SERVLET_MAJOR_VERSION
public static final int SERVLET_MINOR_VERSION
public static final java.lang.Class<?>[] SERVLET_LISTENER_TYPES
public static final int DEFAULT_LISTENER_TYPE_INDEX
public static final int EXTENDED_LISTENER_TYPE_INDEX
public static final java.lang.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(java.lang.String contextPath)
public ContextHandler(HandlerContainer parent, java.lang.String contextPath)
public static ContextHandler.Context getCurrentContext()
public static ContextHandler getContextHandler(ServletContext context)
public static java.lang.String getServerInfo()
public static void setServerInfo(java.lang.String serverInfo)
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
dump
in class org.eclipse.jetty.util.component.ContainerLifeCycle
java.io.IOException
public ContextHandler.Context getServletContext()
@ManagedAttribute("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(java.lang.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(java.lang.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(java.lang.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 java.lang.String[] getVirtualHosts()
public java.lang.Object getAttribute(java.lang.String name)
getAttribute
in interface org.eclipse.jetty.util.Attributes
public java.util.Enumeration<java.lang.String> getAttributeNames()
getAttributeNames
in interface org.eclipse.jetty.util.Attributes
public org.eclipse.jetty.util.Attributes getAttributes()
public java.lang.ClassLoader getClassLoader()
@ManagedAttribute("The file classpath") public java.lang.String getClassPath()
@ManagedAttribute("True if URLs are compacted to replace the multiple \'/\'s with a single \'/\'") public java.lang.String getContextPath()
public java.lang.String getContextPathEncoded()
public java.lang.String getInitParameter(java.lang.String name)
public java.lang.String setInitParameter(java.lang.String name, java.lang.String value)
public java.util.Enumeration<java.lang.String> getInitParameterNames()
@ManagedAttribute("Initial Parameter map for the context") public java.util.Map<java.lang.String,java.lang.String> getInitParams()
@ManagedAttribute(value="Display name of the Context", readonly=true) public java.lang.String getDisplayName()
public java.util.EventListener[] getEventListeners()
public void setEventListeners(java.util.EventListener[] eventListeners)
eventListeners
- the event listenersServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
public void addEventListener(java.util.EventListener listener)
listener
- the event listener to addServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
public void removeEventListener(java.util.EventListener listener)
listener
- the event listener to removeServletContextListener
,
ServletContextAttributeListener
,
ServletRequestListener
,
ServletRequestAttributeListener
protected void addProgrammaticListener(java.util.EventListener listener)
listener
- the programmatic listener to addprotected boolean isProgrammaticListener(java.util.EventListener listener)
@ManagedAttribute("true for graceful shutdown, which allows existing requests to complete") public boolean isShutdown()
public java.util.concurrent.Future<java.lang.Void> shutdown()
shutdown
in interface org.eclipse.jetty.util.component.Graceful
public boolean isAvailable()
public void setAvailable(boolean available)
available
- true to set as enabledpublic org.eclipse.jetty.util.log.Logger getLogger()
public void setLogger(org.eclipse.jetty.util.log.Logger logger)
protected void doStart() throws java.lang.Exception
doStart
in class ScopedHandler
java.lang.Exception
AbstractHandler.doStart()
protected void startContext() throws java.lang.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.java.lang.Exception
- if unable to start the contextContextHandler.Context
protected void stopContext() throws java.lang.Exception
java.lang.Exception
protected void callContextInitialized(ServletContextListener l, ServletContextEvent e)
protected void callContextDestroyed(ServletContextListener l, ServletContextEvent e)
protected void doStop() throws java.lang.Exception
doStop
in class AbstractHandler
java.lang.Exception
public boolean checkVirtualHost(Request baseRequest)
public boolean checkContextPath(java.lang.String uri)
public boolean checkContext(java.lang.String target, Request baseRequest, HttpServletResponse response) throws java.io.IOException
java.io.IOException
public void doScope(java.lang.String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException
ScopedHandler
Derived implementations should call ScopedHandler.nextScope(String, Request, HttpServletRequest, HttpServletResponse)
doScope
in class ScopedHandler
java.io.IOException
ServletException
ScopedHandler.doScope(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
protected void requestInitialized(Request baseRequest, HttpServletRequest request)
protected void requestDestroyed(Request baseRequest, HttpServletRequest request)
public void doHandle(java.lang.String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException
ScopedHandler
Derived implementations should call ScopedHandler.nextHandle(String, Request, HttpServletRequest, HttpServletResponse)
doHandle
in class ScopedHandler
java.io.IOException
ServletException
ScopedHandler.doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
protected void enterScope(Request request, java.lang.Object reason)
request
- A request that is applicable to the scope, or nullreason
- An object that indicates the reason the scope is being entered.protected void exitScope(Request request)
request
- A request that is applicable to the scope, or nullpublic void handle(Request request, java.lang.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(java.lang.Runnable runnable)
public boolean isProtectedTarget(java.lang.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(java.lang.String[] targets)
targets
- Array of URL prefix. Each prefix is in the form /path and will match
either /path exactly or /path/anythingpublic java.lang.String[] getProtectedTargets()
public void removeAttribute(java.lang.String name)
removeAttribute
in interface org.eclipse.jetty.util.Attributes
public void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface org.eclipse.jetty.util.Attributes
public void setAttributes(org.eclipse.jetty.util.Attributes attributes)
attributes
- The attributes to set.public void clearAttributes()
clearAttributes
in interface org.eclipse.jetty.util.Attributes
public void setManagedAttribute(java.lang.String name, java.lang.Object value)
public void setClassLoader(java.lang.ClassLoader classLoader)
classLoader
- The classLoader to set.public void setContextPath(java.lang.String contextPath)
contextPath
- The _contextPath to set.public void setDisplayName(java.lang.String servletContextName)
servletContextName
- The servletContextName to set.public org.eclipse.jetty.util.resource.Resource getBaseResource()
@ManagedAttribute("document root for context") public java.lang.String getResourceBase()
public void setBaseResource(org.eclipse.jetty.util.resource.Resource base)
base
- The resource used as the base for all static content of this context.setResourceBase(String)
public void setResourceBase(java.lang.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 org.eclipse.jetty.http.MimeTypes getMimeTypes()
public void setMimeTypes(org.eclipse.jetty.http.MimeTypes mimeTypes)
mimeTypes
- The mimeTypes to set.public void setWelcomeFiles(java.lang.String[] files)
@ManagedAttribute(value="Partial URIs of directory welcome files", readonly=true) public java.lang.String[] getWelcomeFiles()
setWelcomeFiles(java.lang.String[])
@ManagedAttribute("The error handler to use for the context") public ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- The errorHandler to set.@ManagedAttribute("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 java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public void addLocaleEncoding(java.lang.String locale, java.lang.String encoding)
public java.lang.String getLocaleEncoding(java.lang.String locale)
public java.lang.String getLocaleEncoding(java.util.Locale locale)
locale
- a Locale
valueString
representing the character encoding for the locale or null if none found.public java.util.Map<java.lang.String,java.lang.String> getLocaleEncodings()
public org.eclipse.jetty.util.resource.Resource getResource(java.lang.String path) throws java.net.MalformedURLException
java.net.MalformedURLException
public boolean checkAlias(java.lang.String path, org.eclipse.jetty.util.resource.Resource resource)
path
- the path to check the alias forresource
- the resourcepublic org.eclipse.jetty.util.resource.Resource newResource(java.net.URL url) throws java.io.IOException
Resource.newResource(URL)
enables extensions to provide alternate resource implementations.url
- the url to convert to a Resourcejava.io.IOException
- if unable to create a Resource from the URLpublic org.eclipse.jetty.util.resource.Resource newResource(java.net.URI uri) throws java.io.IOException
Resource.newResource(URL)
enables extensions to provide alternate resource implementations.uri
- the URI to convert to a Resourcejava.io.IOException
- if unable to create a Resource from the URLpublic org.eclipse.jetty.util.resource.Resource newResource(java.lang.String urlOrPath) throws java.io.IOException
Resource.newResource(String)
.urlOrPath
- The URL or path to convertjava.io.IOException
- The Resource could not be created.public java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
public void addAliasCheck(ContextHandler.AliasCheck check)
check
- The alias checkerpublic java.util.List<ContextHandler.AliasCheck> getAliasChecks()
public void setAliasChecks(java.util.List<ContextHandler.AliasCheck> checks)
checks
- list of AliasCheck instancespublic void clearAliasChecks()
Copyright © 1995–2018 Webtide. All rights reserved.