From ed1a8388c0a9b297514dc75b6724875414e20e8e Mon Sep 17 00:00:00 2001 From: Christopher Broderick Date: Thu, 12 Jun 2025 10:34:06 +0000 Subject: [PATCH] Fix database connection initialisation for HealthCheck module. --- RELEASE-NOTES.md | 18 +++--- Server/pom.xml | 2 +- .../msgtracking/DbTrackingModule.java | 59 ++----------------- changes.txt | 20 ++++--- pom.xml | 4 +- 5 files changed, 29 insertions(+), 74 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index e7dc817b..a36dcecd 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,24 +1,28 @@ # OpenAS2 Server -# Version 4.5.1 +# Version 4.5.2 # RELEASE NOTES ----- -The OpenAS2 project is pleased to announce the release of OpenAS2 4.5.1 +The OpenAS2 project is pleased to announce the release of OpenAS2 4.5.2 -The release download file is: OpenAS2Server-4.5.1.zip +The release download file is: OpenAS2Server-4.5.2.zip The zip file contains a PDF document (OpenAS2HowTo.pdf) providing information on installing and using the application. ## NOTE: Testing covers Java 11 to 21. ## Java 8 is NO LONGER SUPPORTED. -Version 4.5.1 - 2025-06-04 +Version 4.5.2 - 2025-06-12 This is a bugfix release. -1. Fix dynamic content-type functionality. +1. Fix database connection setup for healthcheck module. ##Upgrade Notes See the openAS2HowTo appendix for the general process on upgrading OpenAS2. + Below are some specific things to focus on depending on which version you are upgrading from. + + **You must review all notes for the relevant intermediate versions from your version to this release version.** + ### Upgrading to 4.0 or newer from any older version: 1. Ensure you implement all logging that you had configured for ealrier versions using the logback configuration or replace with another framework that works with SLF4J facade. See the OpenAS2HowTo.pdf logging section for more details. 2. The property for email configuration in the config.xml changed: @@ -47,10 +51,6 @@ This is a bugfix release. 5. Run this command: java -cp ../lib/\* org.openas2.upgrades.MigratePollingModuleConfig config.xml partnerships.xml 6. A backup will be created of the original file (with .00 extension|) that can be removed if the conversion is successful. - Below are some specific things to focus on depending on which version you are upgrading from. - - **You must review all notes for the relevant intermediate versions from your version to this release version.** - ### If upgrading from versions older than 2.12.0: 1. If you are using the DB tracking module with the default H2 database then you will need to follow the DB upgrade steps "Appendix: Updating database structure" defined in the OpenAS2HowTo.pdf to ensure you do not lose your existing data because the new H2 version has issues with old databases. 2. A change to the way the private key is looked up in the receiver handler means that if you have duplicated a certificate in the keystore, some partnerships may start to fail. This fix may fix other strange certificate issues when receiving messages. To fix partnership failures that occur after the upgrade, find the duplicates and remove them making sure the one you leave behind is the one with the correct private key. Alternatively, use the **use_new_certificate_lookup_mode** attribute at partnership level set to **false** and the old mechanism will be used but this is not advised as a long term solution as it will eventually be removed in a future version. diff --git a/Server/pom.xml b/Server/pom.xml index aae4b6f2..8a294998 100644 --- a/Server/pom.xml +++ b/Server/pom.xml @@ -7,7 +7,7 @@ net.sf.openas2 OpenAS2 - 4.5.1 + 4.5.2 ../pom.xml diff --git a/Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java b/Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java index 6d9c6d94..d6b97fa3 100644 --- a/Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java +++ b/Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java @@ -97,9 +97,7 @@ protected CompositeParameters createParser() { } protected void persist(Message msg, Map map) { - Connection conn = null; - try { - conn = dbHandler.getConnection(); + try (Connection conn = dbHandler.getConnection()) { Statement s = conn.createStatement(); String msgIdField = FIELDS.MSG_ID; ResultSet rs = s.executeQuery( @@ -180,26 +178,15 @@ protected void persist(Message msg, Map map) { msg.setLogMsg("Failed to persist a tracking event: " + org.openas2.util.Logging.getExceptionMsg(e) + " ::: Data map: " + map); logger.error(msg.getLogMsg(), e); - } finally { - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } } } public ArrayList> listMessages() { - Connection conn = null; ArrayList> rows = new ArrayList>(); - try { - conn = dbHandler.getConnection(); + try (Connection conn = dbHandler.getConnection()) { Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("SELECT " + FIELDS.MSG_ID + ",CREATE_DT,SENDER_ID,RECEIVER_ID,MSG_ID,FILE_NAME,ENCRYPTION_ALGORITHM,SIGNATURE_ALGORITHM,MDN_MODE,STATE FROM " @@ -216,24 +203,14 @@ public ArrayList> listMessages() { } } catch (Exception e) { e.printStackTrace(); - } finally { - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } } return rows; } public HashMap showMessage(String msg_id) { - Connection conn = null; HashMap row = new HashMap(); - try { - conn = dbHandler.getConnection(); + try (Connection conn = dbHandler.getConnection()) { PreparedStatement s = conn .prepareStatement("SELECT * FROM " + tableName + " WHERE " + FIELDS.MSG_ID + " = ?"); s.setString(1, msg_id); @@ -248,23 +225,13 @@ public HashMap showMessage(String msg_id) { } } catch (Exception e) { e.printStackTrace(); - } finally { - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } } return row; } public ArrayList> getDataCharts(HashMap map) { - Connection conn = null; ArrayList> rows = new ArrayList>(); - try { - conn = dbHandler.getConnection(); + try (Connection conn = dbHandler.getConnection()) { Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("SELECT " + FIELDS.MSG_ID + ",STATE,STATUS,CREATE_DT FROM " + tableName + " WHERE CREATE_DT BETWEEN CAST('" + map.get("startDate").toString() @@ -282,14 +249,6 @@ public ArrayList> getDataCharts(HashMap } } catch (Exception e) { e.printStackTrace(); - } finally { - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } } return rows; } @@ -370,21 +329,13 @@ public void stop() { @Override public boolean healthcheck(List failures) { - Connection conn = null; - try { + try (Connection conn = dbHandler.getConnection()) { Statement s = conn.createStatement(); s.executeQuery("SELECT COUNT(*) FROM " + tableName); } catch (Exception e) { failures.add(this.getClass().getSimpleName() + " - Failed to check DB tracking module connection to DB: " + e.getMessage() + " :: Connect String: " + jdbcConnectString); return false; - } finally { - if (conn != null) { - try { - conn.close(); - } catch (Exception e) { - } - } } return true; } diff --git a/changes.txt b/changes.txt index 0d3a0773..57aab4b3 100644 --- a/changes.txt +++ b/changes.txt @@ -1,42 +1,46 @@ **IMPORTANT NOTE**: Please review upgrade notes in the RELEASE-NOTES.md if you are upgrading -Version 4.5.1 - 2025-06-04 +Version 4.5.2 - 2025-06-12 This is a bugfix release. + 1. Fix database connection setup for healthcheck module. + +Version 4.5.1 - 2025-06-04 -1. Fix dynamic content-type functionality. +This is a bugfix release. + 1. Fix dynamic content-type functionality. Version 4.5.0 - 2025-05-18 This is an enhancement release. -1. Add configuration paramerter "resend_on_ssl_exception" to enter into a resend loop when an SSL exception occurs connecting to a partner. + 1. Add configuration paramerter "resend_on_ssl_exception" to enter into a resend loop when an SSL exception occurs connecting to a partner. Version 4.4.0 - 2025-05-10 This is an enhancement release. -1. Log the file size of the file being processed in the AS2 vmessage builder. + 1. Log the file size of the file being processed in the AS2 vmessage builder. Version 4.3.0 - 2025-04-20 This is an enhancement release. -1. Support retaining the original file name as received into the OpenAS2 server before processing so that it can be referenced in dynamic variables. + 1. Support retaining the original file name as received into the OpenAS2 server before processing so that it can be referenced in dynamic variables. Version 4.2.0 - 2025-03-29 This is an enhancement release. -1. Support AS2 systems that do not set the "Content-Transfer-Encoding" mime body part header on the outer mime body part but instead pass it as an HTTP header. + 1. Support AS2 systems that do not set the "Content-Transfer-Encoding" mime body part header on the outer mime body part but instead pass it as an HTTP header. Version 4.1.1 - 2025-03-19 This is a bugfix release. -1. Fix the proxy support implementation. -2. Fix handling of file cleanup when resend loop is entered. + 1. Fix the proxy support implementation. + 2. Fix handling of file cleanup when resend loop is entered. Version 4.1.0 - 2024-12-04 diff --git a/pom.xml b/pom.xml index 3506bfd2..a4ac9faa 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 net.sf.openas2 OpenAS2 - 4.5.1 + 4.5.2 OpenAS2 pom @@ -108,7 +108,7 @@ org.junit.jupiter junit-jupiter - 5.13.0 + 5.13.1 test