Package io.fusionauth.http.server
Class HTTPContext
java.lang.Object
io.fusionauth.http.server.HTTPContext
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute(String name) Retrieves a global attribute.Retrieves all the global attributes.getResource(String path) Attempts to retrieve a file or classpath resource at the given path.removeAttribute(String name) Removes a global attribute.Locates the path given the webapps baseDir (passed into the constructor.voidsetAttribute(String name, Object value) Sets a global attribute.
-
Field Details
-
attributes
-
baseDir
-
-
Constructor Details
-
HTTPContext
-
-
Method Details
-
getAttribute
Retrieves a global attribute.- Parameters:
name- The name of the attribute.- Returns:
- The attribute or null if it doesn't exist.
-
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
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
Removes a global attribute.- Parameters:
name- The name of the attribute.- Returns:
- The attribute if it exists.
-
resolve
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
Sets a global attribute.- Parameters:
name- The name to store the attribute under.value- The attribute value.
-