Class ContextHandler
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.handler.AbstractHandler
-
- org.eclipse.jetty.server.handler.AbstractHandlerContainer
-
- org.eclipse.jetty.server.handler.HandlerWrapper
-
- org.eclipse.jetty.server.handler.ScopedHandler
-
- org.eclipse.jetty.server.handler.ContextHandler
-
- All Implemented Interfaces:
Handler
,HandlerContainer
,org.eclipse.jetty.util.Attributes
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.Graceful
,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
MovedContextHandler
@ManagedObject("URI Context") public class ContextHandler extends ScopedHandler implements org.eclipse.jetty.util.Attributes, org.eclipse.jetty.util.component.Graceful
ContextHandler. 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)
andsetMaxFormKeys(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) andContextHandler.ApproveNonExistentDirectoryAliases
. If these alias checkers are not required, thenclearAliasChecks()
orsetAliasChecks(List)
should be called.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ContextHandler.AliasCheck
Interface to check aliasesstatic 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 callbacksstatic class
ContextHandler.StaticContext
-
Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.AbstractHandler
AbstractHandler.ErrorDispatchHandler
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
-
Field Summary
Fields 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
-
Fields inherited from class org.eclipse.jetty.server.handler.ScopedHandler
_nextScope, _outerScope
-
Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
_handler
-
-
Constructor Summary
Constructors Modifier Constructor Description ContextHandler()
ContextHandler(java.lang.String contextPath)
protected
ContextHandler(ContextHandler.Context context)
ContextHandler(HandlerContainer parent, java.lang.String contextPath)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAliasCheck(ContextHandler.AliasCheck check)
Add an AliasCheck instance to possibly permit aliased resourcesvoid
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(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
protected void
callContextInitialized(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
boolean
checkAlias(java.lang.String path, org.eclipse.jetty.util.resource.Resource resource)
boolean
checkContext(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletResponse response)
boolean
checkContextPath(java.lang.String uri)
boolean
checkVirtualHost(Request baseRequest)
void
clearAliasChecks()
clear the list of AliasChecksvoid
clearAttributes()
void
doHandle(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Do the handler work within the scope.void
doScope(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Scope the handlerprotected 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 classloaderstatic ContextHandler
getContextHandler(javax.servlet.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 encodingsorg.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 requestboolean
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 forResource.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 forResource.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 nullprotected void
requestDestroyed(Request baseRequest, javax.servlet.http.HttpServletRequest request)
protected void
requestInitialized(Request baseRequest, javax.servlet.http.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)
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(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()
-
Methods inherited from class org.eclipse.jetty.server.handler.ScopedHandler
handle, nextHandle, nextScope
-
Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
-
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer
doShutdown, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
-
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler
doError, getServer
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Field Detail
-
SERVLET_MAJOR_VERSION
public static final int SERVLET_MAJOR_VERSION
- See Also:
- Constant Field Values
-
SERVLET_MINOR_VERSION
public static final int SERVLET_MINOR_VERSION
- See Also:
- Constant Field Values
-
SERVLET_LISTENER_TYPES
public static final java.lang.Class<?>[] SERVLET_LISTENER_TYPES
-
DEFAULT_LISTENER_TYPE_INDEX
public static final int DEFAULT_LISTENER_TYPE_INDEX
- See Also:
- Constant Field Values
-
EXTENDED_LISTENER_TYPE_INDEX
public static final int EXTENDED_LISTENER_TYPE_INDEX
- See Also:
- Constant Field Values
-
MANAGED_ATTRIBUTES
public static final 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. Any other context attributes that are set with a name from this list will result in a call tosetManagedAttribute(String, Object)
, which typically initiates the creation of a JMX MBean for the attribute value.- See Also:
- Constant Field Values
-
_scontext
protected ContextHandler.Context _scontext
-
-
Constructor Detail
-
ContextHandler
public ContextHandler()
-
ContextHandler
protected ContextHandler(ContextHandler.Context context)
-
ContextHandler
public ContextHandler(java.lang.String contextPath)
-
ContextHandler
public ContextHandler(HandlerContainer parent, java.lang.String contextPath)
-
-
Method Detail
-
getCurrentContext
public static ContextHandler.Context getCurrentContext()
Get the current ServletContext implementation.- Returns:
- ServletContext implementation
-
getContextHandler
public static ContextHandler getContextHandler(javax.servlet.ServletContext context)
-
getServerInfo
public static java.lang.String getServerInfo()
-
setServerInfo
public static void setServerInfo(java.lang.String serverInfo)
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Overrides:
dump
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.io.IOException
-
getServletContext
public ContextHandler.Context getServletContext()
-
getAllowNullPathInfo
@ManagedAttribute("Checks if the /context is not redirected to /context/") public boolean getAllowNullPathInfo()
- Returns:
- the allowNullPathInfo true if /context is not redirected to /context/
-
setAllowNullPathInfo
public void setAllowNullPathInfo(boolean allowNullPathInfo)
- Parameters:
allowNullPathInfo
- true if /context is not redirected to /context/
-
setServer
public void setServer(Server server)
- Specified by:
setServer
in interfaceHandler
- Overrides:
setServer
in classAbstractHandlerContainer
-
isUsingSecurityManager
public boolean isUsingSecurityManager()
-
setUsingSecurityManager
public void setUsingSecurityManager(boolean usingSecurityManager)
-
setVirtualHosts
public void setVirtualHosts(java.lang.String[] vhosts)
Set the virtual hosts for the context. Only requests that have a matching host header or fully qualified URL will be passed to that context with a virtual host name. A context with no virtual host names or a null virtual host name is available to all requests that are not served by a context with a matching virtual host name.- Parameters:
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 theConnector.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.
-
addVirtualHosts
public void addVirtualHosts(java.lang.String[] virtualHosts)
Either set virtual hosts or add to an existing set of virtual hosts.- Parameters:
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 theConnector.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.
-
removeVirtualHosts
public 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- Parameters:
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 theConnector.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.
-
getVirtualHosts
@ManagedAttribute(value="Virtual hosts accepted by the context", readonly=true) public java.lang.String[] getVirtualHosts()
Get the virtual hosts for the context. Only requests that have a matching host header or fully qualified URL will be passed to that context with a virtual host name. A context with no virtual host names or a null virtual host name is available to all requests that are not served by a context with a matching virtual host name.- Returns:
- 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.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
- Specified by:
getAttribute
in interfaceorg.eclipse.jetty.util.Attributes
-
getAttributeNames
public java.util.Enumeration<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNames
in interfaceorg.eclipse.jetty.util.Attributes
-
getAttributes
public org.eclipse.jetty.util.Attributes getAttributes()
- Returns:
- Returns the attributes.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
- Returns:
- Returns the classLoader.
-
getClassPath
@ManagedAttribute("The file classpath") public java.lang.String getClassPath()
Make best effort to extract a file classpath from the context classloader- Returns:
- Returns the classLoader.
-
getContextPath
@ManagedAttribute("True if URLs are compacted to replace the multiple \'/\'s with a single \'/\'") public java.lang.String getContextPath()
- Returns:
- Returns the contextPath.
-
getContextPathEncoded
public java.lang.String getContextPathEncoded()
- Returns:
- Returns the encoded contextPath.
-
getInitParameter
public java.lang.String getInitParameter(java.lang.String name)
-
setInitParameter
public java.lang.String setInitParameter(java.lang.String name, java.lang.String value)
-
getInitParameterNames
public java.util.Enumeration<java.lang.String> getInitParameterNames()
-
getInitParams
@ManagedAttribute("Initial Parameter map for the context") public java.util.Map<java.lang.String,java.lang.String> getInitParams()
- Returns:
- Returns the initParams.
-
getDisplayName
@ManagedAttribute(value="Display name of the Context", readonly=true) public java.lang.String getDisplayName()
-
getEventListeners
public java.util.EventListener[] getEventListeners()
-
setEventListeners
public void setEventListeners(java.util.EventListener[] eventListeners)
Set the context event listeners.- Parameters:
eventListeners
- the event listeners- See Also:
ServletContextListener
,ServletContextAttributeListener
,ServletRequestListener
,ServletRequestAttributeListener
-
addEventListener
public void addEventListener(java.util.EventListener listener)
Add a context event listeners.- Parameters:
listener
- the event listener to add- See Also:
ServletContextListener
,ServletContextAttributeListener
,ServletRequestListener
,ServletRequestAttributeListener
-
removeEventListener
public void removeEventListener(java.util.EventListener listener)
Remove a context event listeners.- Parameters:
listener
- the event listener to remove- See Also:
ServletContextListener
,ServletContextAttributeListener
,ServletRequestListener
,ServletRequestAttributeListener
-
addProgrammaticListener
protected void addProgrammaticListener(java.util.EventListener listener)
Apply any necessary restrictions on a programmatic added listener.- Parameters:
listener
- the programmatic listener to add
-
isProgrammaticListener
protected boolean isProgrammaticListener(java.util.EventListener listener)
-
isShutdown
@ManagedAttribute("true for graceful shutdown, which allows existing requests to complete") public boolean isShutdown()
- Specified by:
isShutdown
in interfaceorg.eclipse.jetty.util.component.Graceful
- Returns:
- true if this context is shutting down
-
shutdown
public java.util.concurrent.Future<java.lang.Void> shutdown()
Set shutdown status. This field allows for graceful shutdown of a context. A started context may be put into non accepting state so that existing requests can complete, but no new requests are accepted.- Specified by:
shutdown
in interfaceorg.eclipse.jetty.util.component.Graceful
-
isAvailable
public boolean isAvailable()
- Returns:
- false if this context is unavailable (sends 503)
-
setAvailable
public void setAvailable(boolean available)
Set Available status.- Parameters:
available
- true to set as enabled
-
getLogger
public org.eclipse.jetty.util.log.Logger getLogger()
-
setLogger
public void setLogger(org.eclipse.jetty.util.log.Logger logger)
-
doStart
protected void doStart() throws java.lang.Exception
- Overrides:
doStart
in classScopedHandler
- Throws:
java.lang.Exception
- See Also:
AbstractHandler.doStart()
-
startContext
protected void startContext() throws java.lang.Exception
Extensible startContext. this method is called fromdoStart()
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.- Throws:
java.lang.Exception
- if unable to start the context- See Also:
ContextHandler.Context
-
stopContext
protected void stopContext() throws java.lang.Exception
- Throws:
java.lang.Exception
-
callContextInitialized
protected void callContextInitialized(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
-
callContextDestroyed
protected void callContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
-
doStop
protected void doStop() throws java.lang.Exception
- Overrides:
doStop
in classAbstractHandler
- Throws:
java.lang.Exception
-
checkVirtualHost
public boolean checkVirtualHost(Request baseRequest)
-
checkContextPath
public boolean checkContextPath(java.lang.String uri)
-
checkContext
public boolean checkContext(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
- Throws:
java.io.IOException
-
doScope
public void doScope(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
Description copied from class:ScopedHandler
Scope the handlerDerived implementations should call
ScopedHandler.nextScope(String, Request, HttpServletRequest, HttpServletResponse)
- Overrides:
doScope
in classScopedHandler
- Parameters:
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as theRequest
object or a wrapper of that request. The
method can be used access the Request object if required.HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
response
- The response as theResponse
object or a wrapper of that request. The
method can be used access the Response object if required.HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
- Throws:
java.io.IOException
- if unable to handle the request or response processingjavax.servlet.ServletException
- if unable to handle the request or response due to underlying servlet issue- See Also:
ScopedHandler.doScope(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
-
requestInitialized
protected void requestInitialized(Request baseRequest, javax.servlet.http.HttpServletRequest request)
-
requestDestroyed
protected void requestDestroyed(Request baseRequest, javax.servlet.http.HttpServletRequest request)
-
doHandle
public void doHandle(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
Description copied from class:ScopedHandler
Do the handler work within the scope.Derived implementations should call
ScopedHandler.nextHandle(String, Request, HttpServletRequest, HttpServletResponse)
- Specified by:
doHandle
in classScopedHandler
- Parameters:
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as theRequest
object or a wrapper of that request. The
method can be used access the Request object if required.HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
response
- The response as theResponse
object or a wrapper of that request. The
method can be used access the Response object if required.HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
- Throws:
java.io.IOException
- if unable to handle the request or response processingjavax.servlet.ServletException
- if unable to handle the request or response due to underlying servlet issue- See Also:
ScopedHandler.doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
-
enterScope
protected void enterScope(Request request, java.lang.Object reason)
- Parameters:
request
- A request that is applicable to the scope, or nullreason
- An object that indicates the reason the scope is being entered.
-
exitScope
protected void exitScope(Request request)
- Parameters:
request
- A request that is applicable to the scope, or null
-
handle
public void handle(Request request, java.lang.Runnable runnable)
Handle a runnable in the scope of this context and a particular request- Parameters:
request
- The request to scope the thread to (may be null if no particular request is in scope)runnable
- The runnable to run.
-
handle
public void handle(java.lang.Runnable runnable)
-
isProtectedTarget
public boolean isProtectedTarget(java.lang.String target)
Check the target. Called byScopedHandler.handle(String, Request, HttpServletRequest, HttpServletResponse)
when a target within a context is determined. If the target is protected, 404 is returned.- Parameters:
target
- the target to test- Returns:
- true if target is a protected target
-
setProtectedTargets
public void setProtectedTargets(java.lang.String[] targets)
- Parameters:
targets
- Array of URL prefix. Each prefix is in the form /path and will match either /path exactly or /path/anything
-
getProtectedTargets
public java.lang.String[] getProtectedTargets()
-
removeAttribute
public void removeAttribute(java.lang.String name)
- Specified by:
removeAttribute
in interfaceorg.eclipse.jetty.util.Attributes
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
- Specified by:
setAttribute
in interfaceorg.eclipse.jetty.util.Attributes
-
setAttributes
public void setAttributes(org.eclipse.jetty.util.Attributes attributes)
- Parameters:
attributes
- The attributes to set.
-
clearAttributes
public void clearAttributes()
- Specified by:
clearAttributes
in interfaceorg.eclipse.jetty.util.Attributes
-
setManagedAttribute
@Deprecated public void setManagedAttribute(java.lang.String name, java.lang.Object value)
Deprecated.
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
- Parameters:
classLoader
- The classLoader to set.
-
setContextPath
public void setContextPath(java.lang.String contextPath)
- Parameters:
contextPath
- The _contextPath to set.
-
setDisplayName
public void setDisplayName(java.lang.String servletContextName)
- Parameters:
servletContextName
- The servletContextName to set.
-
getBaseResource
public org.eclipse.jetty.util.resource.Resource getBaseResource()
- Returns:
- Returns the resourceBase.
-
getResourceBase
@ManagedAttribute("document root for context") public java.lang.String getResourceBase()
- Returns:
- Returns the base resource as a string.
-
setBaseResource
public void setBaseResource(org.eclipse.jetty.util.resource.Resource base)
Set the base resource for this context.- Parameters:
base
- The resource used as the base for all static content of this context.- See Also:
setResourceBase(String)
-
setResourceBase
public void setResourceBase(java.lang.String resourceBase)
Set the base resource for this context.- Parameters:
resourceBase
- A string representing the base resource for the context. Any string accepted byResource.newResource(String)
may be passed and the call is equivalent tosetBaseResource(newResource(resourceBase));
-
getMimeTypes
public org.eclipse.jetty.http.MimeTypes getMimeTypes()
- Returns:
- Returns the mimeTypes.
-
setMimeTypes
public void setMimeTypes(org.eclipse.jetty.http.MimeTypes mimeTypes)
- Parameters:
mimeTypes
- The mimeTypes to set.
-
setWelcomeFiles
public void setWelcomeFiles(java.lang.String[] files)
-
getWelcomeFiles
@ManagedAttribute(value="Partial URIs of directory welcome files", readonly=true) public java.lang.String[] getWelcomeFiles()
- Returns:
- The names of the files which the server should consider to be welcome files in this context.
- See Also:
- The Servlet Specification,
setWelcomeFiles(java.lang.String[])
-
getErrorHandler
@ManagedAttribute("The error handler to use for the context") public ErrorHandler getErrorHandler()
- Returns:
- Returns the errorHandler.
-
setErrorHandler
public void setErrorHandler(ErrorHandler errorHandler)
- Parameters:
errorHandler
- The errorHandler to set.
-
getMaxFormContentSize
@ManagedAttribute("The maximum content size") public int getMaxFormContentSize()
-
setMaxFormContentSize
public void setMaxFormContentSize(int maxSize)
Set the maximum size of a form post, to protect against DOS attacks from large forms.- Parameters:
maxSize
- the maximum size of the form content (in bytes)
-
getMaxFormKeys
public int getMaxFormKeys()
-
setMaxFormKeys
public void setMaxFormKeys(int max)
Set the maximum number of form Keys to protect against DOS attack from crafted hash keys.- Parameters:
max
- the maximum number of form keys
-
isCompactPath
public boolean isCompactPath()
- Returns:
- True if URLs are compacted to replace multiple '/'s with a single '/'
-
setCompactPath
public void setCompactPath(boolean compactPath)
- Parameters:
compactPath
- True if URLs are compacted to replace multiple '/'s with a single '/'
-
toString
public java.lang.String toString()
- Overrides:
toString
in classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
loadClass
public java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
addLocaleEncoding
public void addLocaleEncoding(java.lang.String locale, java.lang.String encoding)
-
getLocaleEncoding
public java.lang.String getLocaleEncoding(java.lang.String locale)
-
getLocaleEncoding
public java.lang.String getLocaleEncoding(java.util.Locale locale)
Get the character encoding for a locale. The full locale name is first looked up in the map of encodings. If no encoding is found, then the locale language is looked up.- Parameters:
locale
- aLocale
value- Returns:
- a
String
representing the character encoding for the locale or null if none found.
-
getLocaleEncodings
public java.util.Map<java.lang.String,java.lang.String> getLocaleEncodings()
Get all of the locale encodings- Returns:
- a map of all the locale encodings: key is name of the locale and value is the char encoding
-
getResource
public org.eclipse.jetty.util.resource.Resource getResource(java.lang.String path) throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
checkAlias
public boolean checkAlias(java.lang.String path, org.eclipse.jetty.util.resource.Resource resource)
- Parameters:
path
- the path to check the alias forresource
- the resource- Returns:
- True if the alias is OK
-
newResource
public org.eclipse.jetty.util.resource.Resource newResource(java.net.URL url) throws java.io.IOException
Convert URL to Resource wrapper forResource.newResource(URL)
enables extensions to provide alternate resource implementations.- Parameters:
url
- the url to convert to a Resource- Returns:
- the Resource for that url
- Throws:
java.io.IOException
- if unable to create a Resource from the URL
-
newResource
public org.eclipse.jetty.util.resource.Resource newResource(java.net.URI uri) throws java.io.IOException
Convert URL to Resource wrapper forResource.newResource(URL)
enables extensions to provide alternate resource implementations.- Parameters:
uri
- the URI to convert to a Resource- Returns:
- the Resource for that URI
- Throws:
java.io.IOException
- if unable to create a Resource from the URL
-
newResource
public org.eclipse.jetty.util.resource.Resource newResource(java.lang.String urlOrPath) throws java.io.IOException
Convert a URL or path to a Resource. The default implementation is a wrapper forResource.newResource(String)
.- Parameters:
urlOrPath
- The URL or path to convert- Returns:
- The Resource for the URL/path
- Throws:
java.io.IOException
- The Resource could not be created.
-
getResourcePaths
public java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
-
addAliasCheck
public void addAliasCheck(ContextHandler.AliasCheck check)
Add an AliasCheck instance to possibly permit aliased resources- Parameters:
check
- The alias checker
-
getAliasChecks
public java.util.List<ContextHandler.AliasCheck> getAliasChecks()
- Returns:
- Mutable list of Alias checks
-
setAliasChecks
public void setAliasChecks(java.util.List<ContextHandler.AliasCheck> checks)
- Parameters:
checks
- list of AliasCheck instances
-
clearAliasChecks
public void clearAliasChecks()
clear the list of AliasChecks
-
-