Class AppWebService

All Implemented Interfaces:
HttpUtil

public class AppWebService extends FileWebService
An app web service. This service extends the file web service with a RapidContext API and a default app launcher page. All provided APIs are available under the "rapidcontext/" sub-path.
Version:
1.0
  • Field Details

    • KEY_APP

      public static final String KEY_APP
      The dictionary key for the app identifier.
      See Also:
    • KEY_LOGIN

      public static final String KEY_LOGIN
      The dictionary key for the login app identifier.
      See Also:
    • KEY_TITLE

      public static final String KEY_TITLE
      The dictionary key for the page title.
      See Also:
    • KEY_LANG

      public static final String KEY_LANG
      The dictionary key for the page language meta-data.
      See Also:
    • KEY_VIEWPORT

      public static final String KEY_VIEWPORT
      The dictionary key for the page viewport meta-data.
      See Also:
    • KEY_HEADER

      public static final String KEY_HEADER
      The dictionary key for additional HTML headers.
      See Also:
    • logger

      protected LogWebService logger
      The log web service used for the "rapidcontext/log" URL.
    • statusService

      protected StatusWebService statusService
      The status web service used for the "rapidcontext/status" URL.
    • procedureService

      protected ProcedureWebService procedureService
      The procedure web service used for the "rapidcontext/procedure/" URLs.
    • storageService

      protected StorageWebService storageService
      The storage web service used for the "rapidcontext/storage/" URLs.
  • Constructor Details

    • AppWebService

      public AppWebService(String id, String type, Dict dict)
      Creates a new app web service from a serialized representation.
      Parameters:
      id - the object identifier
      type - the object type name
      dict - the serialized representation
  • Method Details

    • version

      protected static String version()
      Returns the platform version number.
      Returns:
      the platform version number
    • resources

      protected static String[] resources(String type, Path base)
      Finds binary files of a specified type from the storage. The file type is both used as a subdirectory (i.e. "files/css") and as a suffix (i.e. "*.css") when performing the search. The returned files will be prefixed with the proper path (e.g. "rapidcontext/files/") relative to the specified base path for the web service. The current platform version will be added as a parameter to the file URL:s.
      Parameters:
      type - the file type to find
      base - the web service root path
      Returns:
      a sorted list of all matching files found in storage
    • appId

      public String appId()
      Returns the app identifier for the default launcher.
      Returns:
      the app identifier for the default launcher, or null if the "index.html" file contains the app
    • loginId

      public String loginId()
      Returns the app identifier for non-authenticated users.
      Returns:
      the login app identifier, or "login" if not specified
    • title

      public String title()
      Returns the title for the HTML web page.
      Returns:
      the configured page title, or "RapidContext" if not defined
    • lang

      public String lang()
      Returns the page language ISO code.
      Returns:
      the page language ISO code, or "en" if not defined
    • viewport

      public String viewport()
      Returns the page viewport meta data.
      Returns:
      the page viewport meta data, or a full device width setting if not defined
    • headerLines

      public ArrayList<String> headerLines()
      Returns the list of optional HTML headers.
      Returns:
      the list of HTML headers, or an empty list if none defined
    • methodsImpl

      protected String[] methodsImpl(Request request)
      Returns the HTTP methods implemented for the specified request. The OPTIONS or HEAD methods doesn't have to be added to the result (added automatically later).
      Overrides:
      methodsImpl in class FileWebService
      Parameters:
      request - the request to check
      Returns:
      the array of HTTP method names supported
      See Also:
    • process

      public void process(Request request)
      Processes a request for this handler. This method assumes local request paths (removal of the mapped URL base).
      Overrides:
      process in class WebService
      Parameters:
      request - the request to process
      See Also:
    • doGet

      protected void doGet(Request request)
      Processes an HTTP GET request.
      Overrides:
      doGet in class FileWebService
      Parameters:
      request - the request to process
    • doPost

      protected void doPost(Request request)
      Processes an HTTP POST request.
      Overrides:
      doPost in class WebService
      Parameters:
      request - the request to process
    • processApp

      protected void processApp(Request request, String appId, String baseUrl)
      Processes an app launch request. This loads the app launcher template from storage and replaces all template variables with their corresponding search results and values.
      Parameters:
      request - the request to process
      appId - the app identifier to launch
      baseUrl - the base URL for requests
    • processAppTemplate

      protected String processAppTemplate(Binary template, String baseUrl, String appId) throws IOException
      Processes an HTML template file for a app and returns the text.
      Parameters:
      template - the template file to read
      baseUrl - the base URL for requests
      appId - the app identifier, or null for 'start'
      Returns:
      the processed contents of the HTML template file
      Throws:
      IOException - if the template file couldn't be read
    • processDownload

      protected void processDownload(Request request)
      Processes a file download request. This is used when file data is POST:ed to the special download URL, which makes the handler send the data back with the specified MIME type. Optionally, the "Content-Disposition" header is also set to force the browser "save as" dialog.
      Parameters:
      request - the request to process
    • processUpload

      protected void processUpload(Request request)
      Processes a file upload request. This is used when files are POST:ed to the special upload URL.
      Parameters:
      request - the request to process