Package nzilbb.labbcat.server.api
Interface APIRequestContext
-
public interface APIRequestContextAn object that can answer questions about the context of a request, for example the user, configuration parameters, etc.- Author:
- Robert Fromont robert@fromont.net.nz
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddResponseHeader(String name, String value)Add the given given header to the response.voidcacheNotification(String name)Generates an instance-wide notification that an underlying object has been updated, and cached versions of that object should be flushed.StringgetBaseUrl()Get the base URL for the server.nzilbb.sql.ConnectionFactorygetConnectionFactory()Accesses a database connection factory.StringgetInitParameter(String name)Access the value of an instance-wide named parameter.StringgetPathInfo()Returns the path portion of the request URL.StringgetRealPath(String path)Provides the local file corresponding to the given path within the servlet context.ObjectgetRequestAttribute(String name)Provides access to a given attribute of the request.StringgetRequestHeader(String name)Provides access to a given header of the request.ResourceBundlegetResourceBundle()Access the localization resources for the correct locale.ObjectgetServletContextAttribute(String name)Provides access to a given attribute of the serlvet context.StringgetServletPath()Get the base parth for the servlet.ObjectgetSessionAttribute(String name)Provides access to a given attribute of the user session.StringgetTitle()Access the title of the request endpoint.StringgetUser()The ID of the logged-in user.StringgetUserHost()The IP/host name of the user's connection.StringgetVersion()Determine the version of the server software.booleanisUserInRole(String role)Determines whether the logged-in user is in the given role.default booleanisUserInRole(String role, Connection db)Determines whether the logged-in user is in the given role.default voidresponseAttachmentName(String fileName)Sets the Content-Disposition header of the given Response correctly for saving a file to the given name.voidservletLog(String message)Log a message.default voidservletLog(Throwable exception)Log an exception.voidsetRequestAttribute(String name, Object value)Sets the value of a given attribute of the request.voidsetServletContextAttribute(String name, Object value)Sets the value of a given attribute of the serlvet context.voidsetSessionAttribute(String name, Object value)Sets the value of a given attribute of the user session.
-
-
-
Method Detail
-
getTitle
String getTitle()
Access the title of the request endpoint.- Returns:
- The title of the endpoint.
-
getVersion
String getVersion()
Determine the version of the server software.- Returns:
- The server version.
-
getBaseUrl
String getBaseUrl()
Get the base URL for the server.- Returns:
- The base URL for the server, or null if it can't be determined.
-
getServletPath
String getServletPath()
Get the base parth for the servlet.- Returns:
- Get the base parth for the servlet, or null if it can't be determined.
-
getUser
String getUser()
The ID of the logged-in user.- Returns:
- The ID of the logged-in user, on null if no user is logged in.
-
getUserHost
String getUserHost()
The IP/host name of the user's connection.- Returns:
- The IP/host name of the user's connection, or null if not available.
-
getPathInfo
String getPathInfo()
Returns the path portion of the request URL.- Returns:
- The path portion of the request URL.
-
getRequestHeader
String getRequestHeader(String name)
Provides access to a given header of the request.- Parameters:
name- The name of the header.- Returns:
- The request header.
-
addResponseHeader
void addResponseHeader(String name, String value)
Add the given given header to the response.- Parameters:
name- Header name.value- Header value.
-
getRequestAttribute
Object getRequestAttribute(String name)
Provides access to a given attribute of the request.- Parameters:
name- The name of the attribute.- Returns:
- The request attribute.
-
setRequestAttribute
void setRequestAttribute(String name, Object value)
Sets the value of a given attribute of the request.- Parameters:
name- The name of the attribute.value- The value for the attribute.
-
getSessionAttribute
Object getSessionAttribute(String name)
Provides access to a given attribute of the user session.- Parameters:
name- The name of the attribute.- Returns:
- The session attribute.
-
setSessionAttribute
void setSessionAttribute(String name, Object value)
Sets the value of a given attribute of the user session.- Parameters:
name- The name of the attribute.value- The value for the attribute.
-
getServletContextAttribute
Object getServletContextAttribute(String name)
Provides access to a given attribute of the serlvet context.- Parameters:
name- The name of the attribute.- Returns:
- The context attribute.
-
setServletContextAttribute
void setServletContextAttribute(String name, Object value)
Sets the value of a given attribute of the serlvet context.- Parameters:
name- The name of the attribute.value- The new value for the attribute.
-
getRealPath
String getRealPath(String path)
Provides the local file corresponding to the given path within the servlet context.- Parameters:
path- The path within the servlet context.- Returns:
- The local path corresponding to the given path.
-
isUserInRole
boolean isUserInRole(String role)
Determines whether the logged-in user is in the given role.- Parameters:
role- The desired role.- Returns:
- true if the user is in the given role, false otherwise.
-
getInitParameter
String getInitParameter(String name)
Access the value of an instance-wide named parameter.- Parameters:
name- The name of the parameter.- Returns:
- The value of the named parameter.
-
cacheNotification
void cacheNotification(String name)
Generates an instance-wide notification that an underlying object has been updated, and cached versions of that object should be flushed.- Parameters:
name- Name of the object that has been updated.
-
getResourceBundle
ResourceBundle getResourceBundle()
Access the localization resources for the correct locale.- Returns:
- The localization resources for the correct local.
-
getConnectionFactory
nzilbb.sql.ConnectionFactory getConnectionFactory()
Accesses a database connection factory.- Returns:
- An object that can provide database connections.
-
servletLog
void servletLog(String message)
Log a message.- Parameters:
message- The message to add to the log.
-
servletLog
default void servletLog(Throwable exception)
Log an exception.- Parameters:
exception- The exception to add a stack-trace of to the log.
-
isUserInRole
default boolean isUserInRole(String role, Connection db) throws SQLException
Determines whether the logged-in user is in the given role.Side effects:
- The session has a possibly new attribute called "security" which indicates what type of security is being used; one of "none", "JDBCRealm", "JNDIRealm"
- The session has a possibly new set of attributes called "group_role", one for each role the user has.
- The request may have a new attribute called "reset_password", if they are marked for resetting their password.
- Parameters:
role- The desired role.db- A connected database connection.- Returns:
- true if the user is in the given role, false otherwise.
- Throws:
SQLException
-
responseAttachmentName
default void responseAttachmentName(String fileName)
Sets the Content-Disposition header of the given Response correctly for saving a file to the given name.This should handle special characters/spaces in the file name correctly.
- Parameters:
fileName- The file name to save the response body as.
-
-