From 8f5a43a8a8f246095eb73ddb011cab910cd643cc Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Wed, 2 Jul 2025 13:32:54 +0200
Subject: [PATCH] Add try-with-resources to model run client

---
 .../controller/session/ForecastBean.java      | 27 ++++++++++---------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java b/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java
index a704d66b..f09aea63 100755
--- a/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java
+++ b/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java
@@ -706,20 +706,21 @@ public class ForecastBean {
              * catch(JsonProcessingException ex) { ex.printStackTrace(); }
              */
 
-            Response resp = this.getManagerResource(modelInformation).runModel(config.getModelId(), request);
-            if (resp.getStatus() == Response.Status.OK.getStatusCode()) {
-                // System.out.println(resp.readEntity(String.class));
-                List<Result> results = (List<Result>) resp.readEntity(new GenericType<List<Result>>() {});
-                // System.out.println("ForecastConfigId=" + forecastConfiguration.getForecastConfigurationId() + ",
-                // resultsize=" + results.size());
-                // We delete all former results before we store the new ones
-                forecastBean.storeResults(forecastConfiguration, results);
-            } else {
-                throw new RunModelException(resp.readEntity(String.class));
+            try(Response resp = this.getManagerResource(modelInformation).runModel(config.getModelId(), request)) {
+            
+                if (resp.getStatus() == Response.Status.OK.getStatusCode()) {
+                    // System.out.println(resp.readEntity(String.class));
+                    List<Result> results = (List<Result>) resp.readEntity(new GenericType<List<Result>>() {});
+                    // System.out.println("ForecastConfigId=" + forecastConfiguration.getForecastConfigurationId() + ",
+                    // resultsize=" + results.size());
+                    // We delete all former results before we store the new ones
+                    forecastBean.storeResults(forecastConfiguration, results);
+                } else {
+                    throw new RunModelException(resp.readEntity(String.class));
+                }
+                // System.out.println("Finished runModel for wsId" +
+                // forecastConfiguration.getWeatherStationPointOfInterestId());
             }
-            // System.out.println("Finished runModel for wsId" +
-            // forecastConfiguration.getWeatherStationPointOfInterestId());
-
         } else {
             throw new PreprocessorException(
                     "Could not find model with id=|" + forecastConfiguration.getModelId() + "|");
-- 
GitLab