Class NoiseModellingServer

java.lang.Object
org.noise_planet.noisemodelling.webserver.NoiseModellingServer

public class NoiseModellingServer extends Object
NoiseModellingServer is the main class responsible for initializing and running the NoiseModelling web server. It leverages Javalin(psi_element://io.javalin.Javalin) to serve static content, manage OGC-compliant Web Processing Service (WPS) operations through OwsController(psi_element://org.noise_planet.noisemodelling.webserver.OwsController), and handle user authentication and management via UserController(psi_element://org.noise_planet.noisemodelling.webserver.secure.UserController).

The server provides functionalities such as:

  • Serving static web resources for the application interface.
  • Exposing OGC WPS endpoints for NoiseModelling computations.
  • User registration, login, and access control using JWT.
  • Job management, including logging and cancellation.
  • Dynamic script reloading by watching for changes in a specified script directory.
This class also handles server shutdown procedures and integrates with a database for persistent storage and user management.
  • Field Details

    • LOGGING_FILE_NAME

      public static final String LOGGING_FILE_NAME
      See Also:
    • logger

      protected final org.slf4j.Logger logger
    • app

      protected io.javalin.Javalin app
    • scriptWatch

      protected Future<?> scriptWatch
    • owsController

      protected final OwsController owsController
    • configuration

      protected final Configuration configuration
    • serverDataSource

      protected final DataSource serverDataSource
    • provider

      protected final JWTProvider<User> provider
    • userController

      protected final UserController userController
  • Constructor Details

  • Method Details

    • getConfiguration

      public Configuration getConfiguration()
    • getServerDataSource

      public DataSource getServerDataSource()
    • getUserDataSource

      public DataSource getUserDataSource(int userId) throws SQLException
      Retrieves a user-specific DataSource instance for database operations. The DataSource is maintained with a connection pool for reuse between transactions.
      Parameters:
      userId - the unique identifier of the user for whom the DataSource is being retrieved.
      Returns:
      the DataSource instance associated with the specified user.
      Throws:
      SQLException - if an SQL error occurs while retrieving or creating the DataSource.
    • main

      public static void main(String[] args)
      The entry point of the application. This method initializes and starts the server.
      Parameters:
      args - command-line arguments passed to the application. Not utilized currently.
    • getJavalinInstance

      public io.javalin.Javalin getJavalinInstance()
      Returns:
      Returns the Javalin application instance.
    • startServer

      public void startServer(boolean openBrowser) throws IOException
      Initializes and starts the NoiseModelling server with the specified configuration. The server serves static files, provides endpoints for OGC-compliant operations, and optionally opens a browser pointing to the server's base URL.
      Parameters:
      openBrowser - indicates whether the default web browser should be opened pointing to the server's base URL.
      Throws:
      IOException - if an I/O error occurs during server initialization or script directory resolution.
    • configureApp

      protected void configureApp(String rootPath)
      Configure Javalin routes
      Parameters:
      rootPath - Base url
    • getHelpDirectory

      public File getHelpDirectory()
      Determines the location of the "help" directory relative to the JAR file and returns it as a File object. "Working Directory" issue with macOS App Bundles. When you double-click a .app, the working directory is not the folder where the app is located; it's usually the system root (/).
      Returns:
      A File object representing the "help" directory if it exists, or null if it does not exist at the expected location.
    • handleBuilderIndex

      protected void handleBuilderIndex(io.javalin.http.Context ctx)
    • installWpsRoutes

      protected void installWpsRoutes()
      Web Processing Service (WPS) API
    • installExceptionHandlers

      protected void installExceptionHandlers()
    • installJobsRoutes

      protected void installJobsRoutes()
      Routes for job management and custom WPS Builder operations
    • installUserManagementRoutes

      protected void installUserManagementRoutes()
    • openBrowser

      public void openBrowser(String url)
      Opens the default web browser and navigates to the specified URL.
      Parameters:
      url - the URL to be opened in the default web browser. It must be a properly formatted URI.
    • startWatcher

      protected Future<Boolean> startWatcher(Path scriptsDir, OwsController owsController)
      Monitors a specified directory and its subdirectories for changes in files. Specifically watches for creation, deletion, and modification events of files with the `.groovy` extension and triggers a script reload using the provided OwsController.
      Parameters:
      scriptsDir - the root directory to monitor for changes. All subdirectories under this will also be monitored.
      owsController - the instance responsible for reloading scripts when a `.groovy` file is changed.
      Returns:
      a Future representing the asynchronous script reload operation.
    • manageLogsWebSocket

      protected void manageLogsWebSocket(io.javalin.websocket.WsConfig ws)
    • manageMemoryWebSocket

      protected void manageMemoryWebSocket(io.javalin.websocket.WsConfig ws)