Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server.handler

public Class ContextHandler

extends Wrapper
implements Attributes, AliasCheck
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.server.AliasCheck, org.eclipse.jetty.util.Attributes
Known Direct Subclasses
org.eclipse.jetty.server.handler.MovedContextHandler, org.eclipse.jetty.server.handler.ResourceHandler.ResourceContext
Annotations
@ManagedObject
Imports
java.io.File, .IOException, java.net.URI, .URLClassLoader, java.nio.file.Path, java.util.ArrayList, .Arrays, .Collections, .EventListener, .List, .Objects, .Set, java.util.concurrent.CopyOnWriteArrayList, java.util.concurrent.atomic.AtomicReference, java.util.function.Consumer, .Predicate, java.util.stream.Collectors, org.eclipse.jetty.http.HttpField, .HttpHeader, .HttpStatus, .MimeTypes, org.eclipse.jetty.server.AliasCheck, .Connector, .Context, .Handler, .Request, .Response, .Server, .SymlinkAllowedResourceAliasChecker, org.eclipse.jetty.util.Attributes, .Callback, .DecoratedObjectFactory, .IO, .Index, .StringUtil, .TypeUtil, .URIUtil, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.ClassLoaderDump, .DumpableAttributes, .LifeCycle, org.eclipse.jetty.util.resource.Resource, .ResourceFactory, .Resources, org.eclipse.jetty.util.thread.Invocable, org.slf4j.Logger, .LoggerFactory

A Handler that scopes a request to a specific Context.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
public static interface
ContextHandler.ContextScopeListener

Listener for all threads entering context scope, including async IO callbacks

private static enum
ContextHandler.ProtectedTargetType

The type of protected target match

public class
private static class

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<Context>
private final List<AliasCheck>
private boolean
private final AtomicReference<ContextHandler.Availability>
private Resource
private ClassLoader
private final ContextHandler.ScopedContext
private final List<ContextHandler.ContextScopeListener>
private String
private String
private Request.Handler
private final MimeTypes.Wrapper
private final Attributes
private Index<ContextHandler.ProtectedTargetType>
private boolean
private File
private boolean
private boolean
private final List<ContextHandler.VHost>
private static final Logger
public static final String

Constructor Summary

AccessConstructor and Description
public
public
public
ContextHandler(String contextPath)

public
ContextHandler(Handler handler, String contextPath)

Method Summary

Modifier and TypeMethod and Description
public void
addAliasCheck(AliasCheck
The alias checker
check
)

Add an AliasCheck instance to possibly permit aliased resources

public boolean
public void
addVirtualHosts(String...
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 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 none 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.
virtualHosts
)

Either set virtual hosts or add to an existing set of virtual hosts.

public boolean
checkAlias(String
The path the aliased resource was created for.
pathInContext
,
Resource
The aliased resourced.
resource
)

Implements org.eclipse.jetty.server.AliasCheck.checkAlias.

Check if an alias is allowed to be served.
public boolean
public void
clearAliasChecks()

clear the list of AliasChecks

public void
clearAttributes()

Overrides default org.eclipse.jetty.util.Attributes.clearAttributes.

Clear all attribute names
protected void
createTempDirectory()

Create the temporary directory.

public void
destroy()

Overrides org.eclipse.jetty.server.Handler.Abstract.destroy.

Implements org.eclipse.jetty.util.component.Destroyable.destroy.

Destroys the managed Destroyable beans in the reverse order they were added.
protected void
doStart()

Overrides org.eclipse.jetty.server.Handler.Abstract.doStart.

Starts the managed lifecycle beans in the order they were added.
protected void
doStop()

Overrides org.eclipse.jetty.server.Handler.Abstract.doStop.

Stops the managed lifecycle beans in the reverse order they were added.
public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.
protected ClassLoader
enterScope(Request contextRequest)

protected void
exitScope(Request request, Context lastContext, ClassLoader lastLoader)

public List<AliasCheck>

Returns:

Immutable list of Alias checks
getAliasChecks
()

public boolean

Returns:

the allowNullPathInfo true if /context is not redirected to /context/
getAllowNullPathInContext
()

public Object
getAttribute(String
the attribute to get
name
)

Implements org.eclipse.jetty.util.Attributes.getAttribute.

Get an attribute
public Set<String>
getAttributeNameSet()

Implements org.eclipse.jetty.util.Attributes.getAttributeNameSet.

Get the immutable set of attribute names.
public Resource

Returns:

Returns the base resource as a string.
getBaseResource
()

public ClassLoader
public String

Returns:

Returns the classLoader.
getClassPath
()

Make best effort to extract a file classpath from the context classloader

public ContextHandler.ScopedContext
public static ContextHandler
public String

Returns:

Returns the contextPath.
getContextPath
()

public static Context

Returns:

The Context from a ContextHandler; or null if the current Thread is not scoped to a ContextHandler.
getCurrentContext
()

Get the current Context if any.

public static Context

Returns:

The Context from a ContextHandler; or Server#getContext() if the current Thread is not scoped to a ContextHandler.
getCurrentContext
(Server
The server.
server
)

Get the current Context if any, or else server context if any.

public static ContextHandler
public String
public Request.Handler

Returns:

Returns the errorHandler.
getErrorHandler
()

public MimeTypes.Mutable

Returns:

A mutable MimeTypes that wraps the Server#getMimeTypes() once ContextHandler#setServer(Server) has been called.
getMimeTypes
()

public String[]
public File

Returns:

The temporary directory configured for the context, or null if none configured.
getTempDirectory
()

public List<String>

Returns:

list 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 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 none 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
()

Get the virtual hosts for the context.

public boolean
handle(Request
the HTTP request to handle
request
,
Response
the HTTP response to handle
response
,
Callback
the callback to complete when the handling is complete
callback
)

Overrides org.eclipse.jetty.server.Handler.Wrapper.handle.

Implements org.eclipse.jetty.server.Request.Handler.handle.

Invoked to handle the passed HTTP request and response.

protected boolean
handleByContextHandler(String pathInContext, ContextRequest request, Response response, Callback callback)

protected void
handleMovedPermanently(Request request, Response response, Callback callback)

protected void
handleUnavailable(Request request, Response response, Callback callback)

public boolean

Returns:

false if this context is unavailable (sends 503)
isAvailable
()

public boolean

Returns:

true if target is a protected target
isProtectedTarget
(String
the target to test
target
)

Check the target when a target within a context is determined.

public boolean

Returns:

true if tmp directory will persist between startups of the context
isTempDirectoryPersistent
()

protected ContextHandler.ScopedContext
private static String
protected void
notifyEnterScope(Request
A request that is applicable to the scope, or null
request
)

protected void
notifyExitScope(Request
A request that is applicable to the scope, or null
request
)

public Object
removeAttribute(String
the attribute to remove
name
)

Implements org.eclipse.jetty.util.Attributes.removeAttribute.

Remove an attribute
public boolean
public void
removeVirtualHosts(String...
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 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 none 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.
virtualHosts
)

Removes an array of virtual host entries, if this removes all entries the _vhosts will be set to null

public void
setAliasChecks(List<AliasCheck>
list of AliasCheck instances
checks
)

Set list of AliasCheck instances.

public void
setAllowNullPathInContext(boolean
true if /context is not redirected to /context/
allowNullPathInContext
)

Set true if /context is not redirected to /context/.

public Object
setAttribute(String
the attribute to set
name
,
Object
the value to set. A null value is equivalent to removing the attribute.
attribute
)

Implements org.eclipse.jetty.util.Attributes.setAttribute.

Set an attribute
public void
setAvailable(boolean
true to set as enabled
available
)

Set Available status.

public void
setBaseResource(Resource
The base resource for the context.
resourceBase
)

Set the base resource to serve content from for this context, which must exist and be readable when the context is started.

public void
setBaseResourceAsPath(Path
The path to create a base resource from.
path
)

Set the base resource to serve content from.

public void
setBaseResourceAsString(String
The path to create a base resource from.
base
)

Set the base resource to serve content from.

public void
setClassLoader(ClassLoader contextLoader)

public void
setContextPath(String
The _contextPath to set.
contextPath
)

public void
setDisplayName(String
The servletContextName to set.
servletContextName
)

public void
setErrorHandler(Request.Handler
The error handler to set.
errorHandler
)

public void
setProtectedTargets(String[]
Array of URL prefix. Each prefix is in the form /path and will match either /path exactly or /path/anything
targets
)

public void
setServer(Server
the Server to associate to this Handler
server
)

Overrides org.eclipse.jetty.server.Handler.AbstractContainer.setServer.

Implements org.eclipse.jetty.server.Handler.setServer.

Set the Server to associate to this Handler.
public void
setTempDirectory(File
A directory. If it does not exist, it must be able to be created during start.
tempDirectory
)

Set the temporary directory returned by ScopedContext#getTempDirectory().

public void
setTempDirectoryPersistent(boolean
true to persist the temp directory on shutdown / exit of the context
persist
)

Set if the temp directory for this context will be kept over a stop and start cycle.

public void
setVirtualHosts(List<String>
List of virtual hosts that this context responds to. A null/empty list 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" (eg: "*.example.org@connectorname"), in which case they will match only if the Connector#getName() for the request also matches. If an entry is just "@connectorname" it will match any host if that connector was used.
vhosts
)

Set the virtual hosts for the context.

public String
toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Returns a string representation of the object.
protected ContextRequest
wrapRequest(Request request, Response response)

protected ContextResponse
Inherited from org.eclipse.jetty.server.Handler.Wrapper:
getHandlergetInvocationTypesetHandler