Class NoiseModellingServer
java.lang.Object
org.noise_planet.noisemodelling.webserver.NoiseModellingServer
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected io.javalin.Javalinprotected final Configurationprotected final org.slf4j.Loggerstatic final Stringprotected final OwsControllerprotected final JWTProvider<User> protected Future<?> protected final DataSourceprotected final UserController -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigureApp(String rootPath) Configure Javalin routesDetermines the location of the "help" directory relative to the JAR file and returns it as a File object.io.javalin.JavalingetUserDataSource(int userId) Retrieves a user-specificDataSourceinstance for database operations.protected voidhandleBuilderIndex(io.javalin.http.Context ctx) protected voidprotected voidRoutes for job management and custom WPS Builder operationsprotected voidprotected voidWeb Processing Service (WPS) APIstatic voidThe entry point of the application.protected voidmanageLogsWebSocket(io.javalin.websocket.WsConfig ws) protected voidmanageMemoryWebSocket(io.javalin.websocket.WsConfig ws) voidopenBrowser(String url) Opens the default web browser and navigates to the specified URL.voidstartServer(boolean openBrowser) Initializes and starts the NoiseModelling server with the specified configuration.startWatcher(Path scriptsDir, OwsController owsController) Monitors a specified directory and its subdirectories for changes in files.
-
Field Details
-
LOGGING_FILE_NAME
- See Also:
-
logger
protected final org.slf4j.Logger logger -
app
protected io.javalin.Javalin app -
scriptWatch
-
owsController
-
configuration
-
serverDataSource
-
provider
-
userController
-
-
Constructor Details
-
NoiseModellingServer
- Throws:
IOExceptionSQLException
-
-
Method Details
-
getConfiguration
-
getServerDataSource
-
getUserDataSource
Retrieves a user-specificDataSourceinstance for database operations. TheDataSourceis maintained with a connection pool for reuse between transactions.- Parameters:
userId- the unique identifier of the user for whom theDataSourceis being retrieved.- Returns:
- the
DataSourceinstance associated with the specified user. - Throws:
SQLException- if an SQL error occurs while retrieving or creating theDataSource.
-
main
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
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
Configure Javalin routes- Parameters:
rootPath- Base url
-
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
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
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)
-