Skip to content

Commit 170448e

Browse files
authored
Fix database connection initialisation for HealthCheck module. (#449)
Also migrate to using try with resource for DB connections
1 parent 20b45da commit 170448e

File tree

5 files changed

+29
-74
lines changed

5 files changed

+29
-74
lines changed

RELEASE-NOTES.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
# OpenAS2 Server
2-
# Version 4.5.1
2+
# Version 4.5.2
33
# RELEASE NOTES
44
-----
5-
The OpenAS2 project is pleased to announce the release of OpenAS2 4.5.1
5+
The OpenAS2 project is pleased to announce the release of OpenAS2 4.5.2
66

7-
The release download file is: OpenAS2Server-4.5.1.zip
7+
The release download file is: OpenAS2Server-4.5.2.zip
88

99
The zip file contains a PDF document (OpenAS2HowTo.pdf) providing information on installing and using the application.
1010
## NOTE: Testing covers Java 11 to 21.
1111
## Java 8 is NO LONGER SUPPORTED.
1212

13-
Version 4.5.1 - 2025-06-04
13+
Version 4.5.2 - 2025-06-12
1414

1515
This is a bugfix release.
1616

17-
1. Fix dynamic content-type functionality.
17+
1. Fix database connection setup for healthcheck module.
1818

1919
##Upgrade Notes
2020
See the openAS2HowTo appendix for the general process on upgrading OpenAS2.
2121

22+
Below are some specific things to focus on depending on which version you are upgrading from.
23+
24+
**You must review all notes for the relevant intermediate versions from your version to this release version.**
25+
2226
### Upgrading to 4.0 or newer from any older version:
2327
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.
2428
2. The property for email configuration in the config.xml changed:
@@ -47,10 +51,6 @@ This is a bugfix release.
4751
5. Run this command: java -cp ../lib/\* org.openas2.upgrades.MigratePollingModuleConfig config.xml partnerships.xml
4852
6. A backup will be created of the original file (with .00 extension|) that can be removed if the conversion is successful.
4953

50-
Below are some specific things to focus on depending on which version you are upgrading from.
51-
52-
**You must review all notes for the relevant intermediate versions from your version to this release version.**
53-
5454
### If upgrading from versions older than 2.12.0:
5555
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.
5656
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.

Server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- DO NOT CHANGE THIS "groupId" WITHOUT CHANGING XMLSession.getManifestAttributes.MANIFEST_VENDOR_ID_ATTRIB -->
88
<groupId>net.sf.openas2</groupId>
99
<artifactId>OpenAS2</artifactId>
10-
<version>4.5.1</version>
10+
<version>4.5.2</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ protected CompositeParameters createParser() {
9797
}
9898

9999
protected void persist(Message msg, Map<String, String> map) {
100-
Connection conn = null;
101-
try {
102-
conn = dbHandler.getConnection();
100+
try (Connection conn = dbHandler.getConnection()) {
103101
Statement s = conn.createStatement();
104102
String msgIdField = FIELDS.MSG_ID;
105103
ResultSet rs = s.executeQuery(
@@ -180,26 +178,15 @@ protected void persist(Message msg, Map<String, String> map) {
180178
msg.setLogMsg("Failed to persist a tracking event: " + org.openas2.util.Logging.getExceptionMsg(e)
181179
+ " ::: Data map: " + map);
182180
logger.error(msg.getLogMsg(), e);
183-
} finally {
184-
if (conn != null) {
185-
try {
186-
conn.close();
187-
} catch (SQLException e) {
188-
// TODO Auto-generated catch block
189-
e.printStackTrace();
190-
}
191-
}
192181
}
193182

194183
}
195184

196185
public ArrayList<HashMap<String, String>> listMessages() {
197186

198-
Connection conn = null;
199187
ArrayList<HashMap<String, String>> rows = new ArrayList<HashMap<String, String>>();
200188

201-
try {
202-
conn = dbHandler.getConnection();
189+
try (Connection conn = dbHandler.getConnection()) {
203190
Statement s = conn.createStatement();
204191
ResultSet rs = s.executeQuery("SELECT " + FIELDS.MSG_ID
205192
+ ",CREATE_DT,SENDER_ID,RECEIVER_ID,MSG_ID,FILE_NAME,ENCRYPTION_ALGORITHM,SIGNATURE_ALGORITHM,MDN_MODE,STATE FROM "
@@ -216,24 +203,14 @@ public ArrayList<HashMap<String, String>> listMessages() {
216203
}
217204
} catch (Exception e) {
218205
e.printStackTrace();
219-
} finally {
220-
if (conn != null) {
221-
try {
222-
conn.close();
223-
} catch (SQLException e) {
224-
e.printStackTrace();
225-
}
226-
}
227206
}
228207
return rows;
229208
}
230209

231210
public HashMap<String, String> showMessage(String msg_id) {
232211

233-
Connection conn = null;
234212
HashMap<String, String> row = new HashMap<String, String>();
235-
try {
236-
conn = dbHandler.getConnection();
213+
try (Connection conn = dbHandler.getConnection()) {
237214
PreparedStatement s = conn
238215
.prepareStatement("SELECT * FROM " + tableName + " WHERE " + FIELDS.MSG_ID + " = ?");
239216
s.setString(1, msg_id);
@@ -248,23 +225,13 @@ public HashMap<String, String> showMessage(String msg_id) {
248225
}
249226
} catch (Exception e) {
250227
e.printStackTrace();
251-
} finally {
252-
if (conn != null) {
253-
try {
254-
conn.close();
255-
} catch (SQLException e) {
256-
e.printStackTrace();
257-
}
258-
}
259228
}
260229
return row;
261230
}
262231

263232
public ArrayList<HashMap<String, String>> getDataCharts(HashMap<String, String> map) {
264-
Connection conn = null;
265233
ArrayList<HashMap<String, String>> rows = new ArrayList<HashMap<String, String>>();
266-
try {
267-
conn = dbHandler.getConnection();
234+
try (Connection conn = dbHandler.getConnection()) {
268235
Statement s = conn.createStatement();
269236
ResultSet rs = s.executeQuery("SELECT " + FIELDS.MSG_ID + ",STATE,STATUS,CREATE_DT FROM " + tableName
270237
+ " WHERE CREATE_DT BETWEEN CAST('" + map.get("startDate").toString()
@@ -282,14 +249,6 @@ public ArrayList<HashMap<String, String>> getDataCharts(HashMap<String, String>
282249
}
283250
} catch (Exception e) {
284251
e.printStackTrace();
285-
} finally {
286-
if (conn != null) {
287-
try {
288-
conn.close();
289-
} catch (SQLException e) {
290-
e.printStackTrace();
291-
}
292-
}
293252
}
294253
return rows;
295254
}
@@ -370,21 +329,13 @@ public void stop() {
370329

371330
@Override
372331
public boolean healthcheck(List<String> failures) {
373-
Connection conn = null;
374-
try {
332+
try (Connection conn = dbHandler.getConnection()) {
375333
Statement s = conn.createStatement();
376334
s.executeQuery("SELECT COUNT(*) FROM " + tableName);
377335
} catch (Exception e) {
378336
failures.add(this.getClass().getSimpleName() + " - Failed to check DB tracking module connection to DB: "
379337
+ e.getMessage() + " :: Connect String: " + jdbcConnectString);
380338
return false;
381-
} finally {
382-
if (conn != null) {
383-
try {
384-
conn.close();
385-
} catch (Exception e) {
386-
}
387-
}
388339
}
389340
return true;
390341
}

changes.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
**IMPORTANT NOTE**: Please review upgrade notes in the RELEASE-NOTES.md if you are upgrading
22

3-
Version 4.5.1 - 2025-06-04
3+
Version 4.5.2 - 2025-06-12
44

55
This is a bugfix release.
6+
1. Fix database connection setup for healthcheck module.
7+
8+
Version 4.5.1 - 2025-06-04
69

7-
1. Fix dynamic content-type functionality.
10+
This is a bugfix release.
811

12+
1. Fix dynamic content-type functionality.
913

1014
Version 4.5.0 - 2025-05-18
1115

1216
This is an enhancement release.
1317

14-
1. Add configuration paramerter "resend_on_ssl_exception" to enter into a resend loop when an SSL exception occurs connecting to a partner.
18+
1. Add configuration paramerter "resend_on_ssl_exception" to enter into a resend loop when an SSL exception occurs connecting to a partner.
1519

1620
Version 4.4.0 - 2025-05-10
1721

1822
This is an enhancement release.
1923

20-
1. Log the file size of the file being processed in the AS2 vmessage builder.
24+
1. Log the file size of the file being processed in the AS2 vmessage builder.
2125

2226
Version 4.3.0 - 2025-04-20
2327

2428
This is an enhancement release.
2529

26-
1. Support retaining the original file name as received into the OpenAS2 server before processing so that it can be referenced in dynamic variables.
30+
1. Support retaining the original file name as received into the OpenAS2 server before processing so that it can be referenced in dynamic variables.
2731

2832
Version 4.2.0 - 2025-03-29
2933

3034
This is an enhancement release.
3135

32-
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.
36+
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.
3337

3438
Version 4.1.1 - 2025-03-19
3539

3640
This is a bugfix release.
3741

38-
1. Fix the proxy support implementation.
39-
2. Fix handling of file cleanup when resend loop is entered.
42+
1. Fix the proxy support implementation.
43+
2. Fix handling of file cleanup when resend loop is entered.
4044

4145
Version 4.1.0 - 2024-12-04
4246

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>net.sf.openas2</groupId>
77
<artifactId>OpenAS2</artifactId>
8-
<version>4.5.1</version>
8+
<version>4.5.2</version>
99
<name>OpenAS2</name>
1010
<packaging>pom</packaging>
1111

@@ -108,7 +108,7 @@
108108
<dependency>
109109
<groupId>org.junit.jupiter</groupId>
110110
<artifactId>junit-jupiter</artifactId>
111-
<version>5.13.0</version>
111+
<version>5.13.1</version>
112112
<scope>test</scope>
113113
</dependency>
114114
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->

0 commit comments

Comments
 (0)