Class OwsController
java.lang.Object
org.noise_planet.noisemodelling.webserver.OwsController
The OwsController class handles requests for OGC Web Services (OWS), including
WPS (Web Processing Service), WFS (Web Feature Service), and WCS (Web Coverage Service).
It provides functionalities for GET and POST requests, depending on the OWS service and
operation type.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final longstatic final intstatic final intprotected final ScheduledExecutorService -
Constructor Summary
ConstructorsConstructorDescriptionOwsController(DataSource serverDataSource, JWTProvider<User> provider, Configuration configuration) Constructs an instance of the OwsController class. -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic ExecutionPlanextractExecuteQuery(net.opengis.wps10.ExecuteType execute, Map<String, ScriptMetadata> wpsScripts) Extracts input data from the providedExecuteTypeobject and returns the execution plan.fetchUserDataSource(int userId) The datasource instance contain the hikari connection pool so we must keep it between transactionsstatic ExecutionPlangenerateExecutionPlanFroExecuteType(net.opengis.wps10.ExecuteType execute, Map<String, ScriptMetadata> wpsScripts) static ExecutionPlangenerateExecutionPlanFromWPS(InputStream wpsXmlBody, Map<String, ScriptMetadata> wpsScripts) Parse the XML of the query to generate the execution planstatic StringgetUserDatabaseName(int userId) voidhandleDatabaseExport(io.javalin.http.Context ctx) Handles the export of the user's H2 database as a zip file.voidhandleDatabaseImport(io.javalin.http.Context ctx) Handles the import of an H2 database backup.voidhandleGet(io.javalin.http.Context ctx) Handles GET requests for the OWS (Web Services) endpoint.voidhandleJobExecuteStatus(io.javalin.http.Context ctx) OGC compliant WPS, Build a ExecuteResponse according to the state of a Jobprotected voidhandleWCSGet(io.javalin.http.Context ctx) Handles a Get request for the Web Coverage Service (WCS).protected voidhandleWFSGet(io.javalin.http.Context ctx) Handles WFS (Web Feature Service) GET requests for the OWS (Web Services) endpoint.protected voidhandleWPSGet(io.javalin.http.Context ctx) Handles HTTP GET requests for the WPS (Web Processing Service) by managing the "GetCapabilities" and "DescribeProcess" operations.voidhandleWPSPost(io.javalin.http.Context ctx) Handles an HTTP POST request for a Web Processing Service (WPS) operation.voidjobCancel(io.javalin.http.Context ctx) Cancels the job specified by the job ID in the request context.voidjobDelete(io.javalin.http.Context ctx) Deletes a job based on the job ID provided in the request context.voidjobDeleteAll(io.javalin.http.Context ctx) Deletes a job based on the job ID provided in the request context.voidjobList(io.javalin.http.Context ctx) Render job list HTML pagevoidjobLogs(io.javalin.http.Context ctx) Retrieves and displays the logs of a specific job based on the job ID.voidjobLogsStreamOnClose(io.javalin.websocket.WsCloseContext wsCloseContext) Handles the closure of a job log stream associated with a WebSocket context.voidjobLogsStreamOnConnect(io.javalin.websocket.WsConnectContext ctx) Establishes a WebSocket stream to send logs associated with a specific job to the client upon connection.static net.opengis.wps10.ExecuteTypeparseExecuteRequest(InputStream inputStream) Parses an InputStream to extract and return an ExecuteType object.static net.opengis.wps10.ExecuteResponseTypeparseExecuteResponse(InputStream inputStream) Parses the given input stream to extract an ExecuteResponseType object.static voidprocessResult(io.javalin.http.Context context, Object result) Format the WPS output for the rendering of the WPS Builder websitevoidReloads the WPS (Web Processing Service) scripts by reloading them from the file system and rebuilding the corresponding script wrappers.voidreturnExceptionDocument(io.javalin.http.Context ctx, Exception ex) voidshutdown()Shuts down the server by stopping the job executor service.
-
Field Details
-
CORE_POOL_SIZE
public static final int CORE_POOL_SIZE- See Also:
-
MAXIMUM_POOL_SIZE
public static final int MAXIMUM_POOL_SIZE- See Also:
-
KEEP_ALIVE_TIME
public static final long KEEP_ALIVE_TIME- See Also:
-
MAXIMUM_LINES_TO_FETCH
public static final int MAXIMUM_LINES_TO_FETCH- See Also:
-
scheduledExecutorService
-
-
Constructor Details
-
OwsController
public OwsController(DataSource serverDataSource, JWTProvider<User> provider, Configuration configuration) throws IOException Constructs an instance of the OwsController class. This constructor initializes the WPS scripts by loading and grouping them using the WpsScriptWrapper utility. The scripts are classified based on their directory structure and wrapped into appropriate script wrappers for further processing.- Throws:
IOException- if an error occurs while loading or processing the script files.
-
-
Method Details
-
reloadScripts
Reloads the WPS (Web Processing Service) scripts by reloading them from the file system and rebuilding the corresponding script wrappers.- Throws:
IOException- if an error occurs while loading or rebuilding the scripts.
-
handleGet
public void handleGet(io.javalin.http.Context ctx) Handles GET requests for the OWS (Web Services) endpoint. Based on the "service" query parameter, it routes the request to the appropriate WPS, WFS, or WCS service handler. If the service type is unknown, responds with HTTP 400 (Bad Request). Handles exceptions and responds with HTTP 500 (Internal Server Error) in case of server-side errors.- Parameters:
ctx- the context of the current HTTP request, providing access to request parameters, response handling, and the ability to set content type and status codes
-
returnExceptionDocument
- Throws:
IOException
-
handleWPSGet
Handles HTTP GET requests for the WPS (Web Processing Service) by managing the "GetCapabilities" and "DescribeProcess" operations. Based on the "request" query parameter, this method retrieves WPS capabilities or details of a specific process. Responds with appropriate XML content or error messages in case of invalid requests or missing parameters.- Parameters:
ctx- the context of the current HTTP request, providing access to query parameters, response handling, and the ability to set content type and status codes- Throws:
IOException
-
handleWFSGet
Handles WFS (Web Feature Service) GET requests for the OWS (Web Services) endpoint. Depending on the value of the "request" query parameter, this method determines the desired operation. If the request is "GetCapabilities", the corresponding XML file is read and returned in the response. For unknown or unsupported requests, it returns an HTTP 400 (Bad Request) status.- Parameters:
ctx- the context of the current HTTP request, providing access to query parameters, request and response handling, and allowing for status and body configuration- Throws:
Exception- if an error occurs while reading or responding with the requested resource
-
handleWCSGet
Handles a Get request for the Web Coverage Service (WCS). The method processes the incoming HTTP request by examining the "request" query parameter. If the query parameter is "GetCapabilities", it responds with the contents of a WCS capabilities XML file. If the request is not recognized, it responds with a 400 HTTP status and an error message.- Parameters:
ctx- the context of the HTTP request, providing access to query parameters, response handling, status codes, and other request-related information- Throws:
Exception- if an I/O error occurs while attempting to read the WCS capabilities XML file or while processing the request
-
handleJobExecuteStatus
public void handleJobExecuteStatus(io.javalin.http.Context ctx) OGC compliant WPS, Build a ExecuteResponse according to the state of a Job- Parameters:
ctx- the context of the current HTTP request, providing access to query parameters, request and response handling, and allowing for status and body configuration
-
jobList
public void jobList(io.javalin.http.Context ctx) Render job list HTML page- Parameters:
ctx- web context
-
parseExecuteRequest
public static net.opengis.wps10.ExecuteType parseExecuteRequest(InputStream inputStream) throws IOException, ParserConfigurationException, SAXException Parses an InputStream to extract and return an ExecuteType object.- Parameters:
inputStream- the input stream containing the request to be parsed- Returns:
- an ExecuteType object if parsing is successful and the input corresponds to ExecuteType; otherwise, returns null
- Throws:
IOException- if an I/O error occurs during parsingParserConfigurationException- if a configuration error occurs while setting up the parserSAXException- if an error occurs during XML parsing
-
parseExecuteResponse
public static net.opengis.wps10.ExecuteResponseType parseExecuteResponse(InputStream inputStream) throws IOException, ParserConfigurationException, SAXException Parses the given input stream to extract an ExecuteResponseType object.- Parameters:
inputStream- the input stream containing the data to be parsed- Returns:
- an ExecuteResponseType instance if parsing is successful and the parsed object is of the expected type, otherwise returns null
- Throws:
IOException- if an I/O error occurs while reading the input streamParserConfigurationException- if a parser configuration error occursSAXException- if an XML parsing error occurs
-
generateExecutionPlanFromWPS
public static ExecutionPlan generateExecutionPlanFromWPS(InputStream wpsXmlBody, Map<String, ScriptMetadata> wpsScripts) throws IOException, ParserConfigurationException, SAXExceptionParse the XML of the query to generate the execution plan- Parameters:
wpsXmlBody- XML of the query- Returns:
- Execution plan
- Throws:
IOException- if an I/O error occurs while reading the XMLParserConfigurationException- if a configuration error occurs while parsing the XMLSAXException- if a SAX error occurs while parsing the XML
-
generateExecutionPlanFroExecuteType
public static ExecutionPlan generateExecutionPlanFroExecuteType(net.opengis.wps10.ExecuteType execute, Map<String, ScriptMetadata> wpsScripts) throws IOException, ParserConfigurationException, SAXException -
extractExecuteQuery
public static ExecutionPlan extractExecuteQuery(net.opengis.wps10.ExecuteType execute, Map<String, ScriptMetadata> wpsScripts) throws IOExceptionExtracts input data from the providedExecuteTypeobject and returns the execution plan. It processes the data inputs defined in theExecuteTypeobject to construct this mapping.- Parameters:
execute- theExecuteTypeobject that contains the data inputs to extract.wpsScripts- the map of WPS scripts to their metadata.- Returns:
- The execution plan requested by the query
- Throws:
IOException
-
handleWPSPost
public void handleWPSPost(io.javalin.http.Context ctx) Handles an HTTP POST request for a Web Processing Service (WPS) operation. This method parses the request body, validates the WPS Execute Request, identifies the target script to execute based on its process identifier, and executes the script. The result of the script execution is returned as a JSON response. Responds with appropriate HTTP status codes for invalid requests, missing scripts, and internal server errors.- Parameters:
ctx- the context of the HTTP request, providing access to the request body, response handling, and the ability to set status codes and send JSON responses
-
processResult
Format the WPS output for the rendering of the WPS Builder website- Parameters:
context-result-
-
fetchUserDataSource
The datasource instance contain the hikari connection pool so we must keep it between transactions- Parameters:
userId- User identifier- Returns:
- Throws:
SQLException
-
getUserDatabaseName
-
jobLogs
public void jobLogs(@NotNull io.javalin.http.Context ctx) Retrieves and displays the logs of a specific job based on the job ID. This method retrieves the job data from the database, checks access permissions, and fetches the corresponding log entries, rendering them in the response context.- Parameters:
ctx- the context of the current request, containing job-related parameters, request attributes, and response handling methods.
-
jobDelete
public void jobDelete(@NotNull io.javalin.http.Context ctx) Deletes a job based on the job ID provided in the request context. Ensures user authorization before deleting the job and updates the job list upon successful deletion. Handles errors for invalid job IDs and database issues.- Parameters:
ctx- The context of the request containing user information and job ID path parameter.
-
jobDeleteAll
public void jobDeleteAll(@NotNull io.javalin.http.Context ctx) Deletes a job based on the job ID provided in the request context. Ensures user authorization before deleting the job and updates the job list upon successful deletion. Handles errors for invalid job IDs and database issues.- Parameters:
ctx- The context of the request containing user information and job ID path parameter.
-
jobCancel
public void jobCancel(@NotNull io.javalin.http.Context ctx) Cancels the job specified by the job ID in the request context. The method validates user access to the job, retrieves the job data, and triggers the cancellation of the job with a default delay.- Parameters:
ctx- the context of the HTTP request, containing information such as path parameters, user attributes, and other relevant data required for the operation
-
jobLogsStreamOnConnect
public void jobLogsStreamOnConnect(io.javalin.websocket.WsConnectContext ctx) Establishes a WebSocket stream to send logs associated with a specific job to the client upon connection. The method retrieves job details, validates user access, and creates a custom log appender that captures logs for the specified job thread. Logs are filtered and streamed through the WebSocket connection.- Parameters:
ctx- the WebSocket connection context that contains the connection details and user session data.
-
jobLogsStreamOnClose
public void jobLogsStreamOnClose(io.javalin.websocket.WsCloseContext wsCloseContext) Handles the closure of a job log stream associated with a WebSocket context. This method removes the corresponding appender from the logger and cleans up the association within the internal tracking map.- Parameters:
wsCloseContext- the WebSocket close context representing the closed connection
-
closeDataBaseDataSources
public void closeDataBaseDataSources() -
handleDatabaseExport
public void handleDatabaseExport(io.javalin.http.Context ctx) Handles the export of the user's H2 database as a zip file. Uses H2's BACKUP TO command to create a safe binary backup. The backup is streamed to the client as application/octet-stream.- Parameters:
ctx- the Javalin HTTP context
-
handleDatabaseImport
public void handleDatabaseImport(io.javalin.http.Context ctx) Handles the import of an H2 database backup. Closes the existing user connection pool, replaces the database file with the uploaded backup, and lets the pool reconnect on next access. No SQL is executed from the uploaded file — only file replacement.- Parameters:
ctx- the Javalin HTTP context
-
shutdown
public void shutdown()Shuts down the server by stopping the job executor service.
-