Class HTTPContext

java.lang.Object
io.fusionauth.http.server.HTTPContext

public class HTTPContext extends Object
An object that is the context of the server. It can store global attributes and also a base directory from which files can be loaded.

This might be useful for MVCs and applications is they need a way to locate files based on a location such as an application directory.

Author:
Brian Pontarelli
  • Field Details

  • Constructor Details

    • HTTPContext

      public HTTPContext(Path baseDir)
  • Method Details

    • getAttribute

      public Object getAttribute(String name)
      Retrieves a global attribute.
      Parameters:
      name - The name of the attribute.
      Returns:
      The attribute or null if it doesn't exist.
    • getAttributes

      public Map<String,Object> getAttributes()
      Retrieves all the global attributes. This returns the direct Map so changes to the Map will affect all attributes.
      Returns:
      The attribute Map.
    • getResource

      public URL getResource(String path) throws IllegalStateException
      Attempts to retrieve a file or classpath resource at the given path. If the path is invalid, this will return null. If the classpath is borked or the path somehow cannot be converted to a URL, then this throws an exception.
      Parameters:
      path - The path.
      Returns:
      The URL to the resource or null.
      Throws:
      IllegalStateException - If the classpath is borked or the file system is jacked.
    • removeAttribute

      public Object removeAttribute(String name)
      Removes a global attribute.
      Parameters:
      name - The name of the attribute.
      Returns:
      The attribute if it exists.
    • resolve

      public Path resolve(String appPath)
      Locates the path given the webapps baseDir (passed into the constructor.
      Parameters:
      appPath - The app path to a resource (like an FTL file).
      Returns:
      The resolved path, which is almost always just the baseDir plus the appPath with a file separator in the middle.
    • setAttribute

      public void setAttribute(String name, Object value)
      Sets a global attribute.
      Parameters:
      name - The name to store the attribute under.
      value - The attribute value.