Interface Context

All Superinterfaces:
Attributes, Decorator, Executor
All Known Implementing Classes:
ContextHandler.ScopedContext, ServletContextHandler.ServletScopedContext

public interface Context extends Attributes, Decorator, Executor

A context for handling an Request. Every request has a non-null context, which may initially be the server context, or a context provided by a ContextHandler. A Context:

See Also:
  • Method Details

    • getContextPath

      String getContextPath()
      Returns:
      the encoded context path of this Context or null
    • getClassLoader

      ClassLoader getClassLoader()
      Returns:
      the ClassLoader associated with this Context
    • getBaseResource

      Resource getBaseResource()
      Returns:
      the base resource used to lookup other resources specified by the request URI path
    • getErrorHandler

      Request.Handler getErrorHandler()
      Returns:
      the error Request.Handler associated with this Context
    • getVirtualHosts

      List<String> getVirtualHosts()
      Returns:
      a list of virtual host names associated with this Context
    • getMimeTypes

      MimeTypes getMimeTypes()
      Returns:
      the mime types associated with this Context
    • execute

      void execute(Runnable task)

      Executes the given task in a thread scoped to this Context.

      Specified by:
      execute in interface Executor
      Parameters:
      task - the task to run
      See Also:
    • run

      void run(Runnable task)

      Runs the given task in the current thread scoped to this Context.

      Parameters:
      task - the task to run
      See Also:
    • run

      void run(Runnable task, Request request)

      Runs the given task in the current thread scoped to this Context and the given Request.

      Parameters:
      task - the task to run
      request - the HTTP request to use in the scope
    • getPathInContext

      default String getPathInContext(String canonicallyEncodedPath)

      Returns the URI path scoped to this Context.

      Parameters:
      canonicallyEncodedPath - a full URI path that should be canonically encoded as per URIUtil.canonicalPath(String)
      Returns:
      the URI path scoped to this Context, or null if the full path does not match this Context. The empty string is returned if the full path is exactly the context path.
      See Also:
    • getTempDirectory

      File getTempDirectory()
      Returns:
      a non-null temporary directory, configured either for the context, the server or the JVM
    • isCrossContextDispatch

      default boolean isCrossContextDispatch(Request request)
      Check cross context dispatch status
      Parameters:
      request - The request to check
      Returns:
      True IFF this context supports cross context and the passed request is a cross context request.
    • getCrossContextDispatchType

      default String getCrossContextDispatchType(Request request)
      Get any cross context dispatch type
      Parameters:
      request - The request to get the type for
      Returns:
      A String representation of a dispatcher type iff this context supports cross context and the passed request is a cross context request, otherwise null.
    • getPathInContext

      static String getPathInContext(String encodedContextPath, String encodedPath)

      Returns the URI path scoped to the passed context path.

      For example, if the context path passed is /ctx then a path of /ctx/foo/bar will return /foo/bar.

      Parameters:
      encodedContextPath - The context path that should be canonically encoded as per URIUtil.canonicalPath(String).
      encodedPath - a full URI path that should be canonically encoded as per URIUtil.canonicalPath(String).
      Returns:
      the URI encodedPath scoped to the encodedContextPath, or null if the encodedPath does not match the context. The empty string is returned if the encodedPath is exactly the encodedContextPath.