Interface APIRequestContext


  • public interface APIRequestContext
    An 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 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.