aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/dao/MessageDaoImpl.java27
-rw-r--r--lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/impl/MessageInterceptorImpl.java6
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java3
-rw-r--r--lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceManagerImpl.java4
-rw-r--r--lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtils.java2
-rw-r--r--lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java1
-rw-r--r--lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java4
-rw-r--r--lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java1
8 files changed, 37 insertions, 11 deletions
diff --git a/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/dao/MessageDaoImpl.java b/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/dao/MessageDaoImpl.java
index f04ea6259..e9a9ed6d2 100644
--- a/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/dao/MessageDaoImpl.java
+++ b/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/dao/MessageDaoImpl.java
@@ -66,19 +66,33 @@ public class MessageDaoImpl implements MessageDao {
@Override
public void updateMessageStarted(long messageId, Date timestamp) {
- updateMessageStatus("started_timestamp", messageId, null, timestamp);
+ // duplicate code with updateMessageCompleted to avoid SQL injection issue for sonar
+ try (Connection con = dataSource.getConnection()) {
+ try {
+ con.setAutoCommit(false);
+ String sql = "UPDATE message SET started_timestamp = ? WHERE message_id = ?";
+ try (PreparedStatement ps = con.prepareStatement(sql)) {
+ ps.setTimestamp(1, new Timestamp(timestamp.getTime()));
+ ps.setLong(2, messageId);
+ ps.executeUpdate();
+ }
+ con.commit();
+ } catch (SQLException ex) {
+ con.rollback();
+ throw ex;
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException("Error updating message status in DB: " + e.getMessage(), e);
+ }
}
@Override
public void updateMessageCompleted(long messageId, String resolution, Date timestamp) {
- updateMessageStatus("completed_timestamp", messageId, resolution, timestamp);
- }
-
- private void updateMessageStatus(String timestampColumn, long messageId, String resolution, Date timestamp) {
+ // duplicate code with updateMessageStarted to avoid SQL injection issue for sonar
try (Connection con = dataSource.getConnection()) {
try {
con.setAutoCommit(false);
- String sql = "UPDATE message SET " + timestampColumn + " = ? WHERE message_id = ?";
+ String sql = "UPDATE message SET completed_timestamp = ? WHERE message_id = ?";
try (PreparedStatement ps = con.prepareStatement(sql)) {
ps.setTimestamp(1, new Timestamp(timestamp.getTime()));
ps.setLong(2, messageId);
@@ -92,6 +106,7 @@ public class MessageDaoImpl implements MessageDao {
} catch (SQLException e) {
throw new RuntimeException("Error updating message status in DB: " + e.getMessage(), e);
}
+
}
@Override
diff --git a/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/impl/MessageInterceptorImpl.java b/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/impl/MessageInterceptorImpl.java
index 89f29b327..a07b3c4e7 100644
--- a/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/impl/MessageInterceptorImpl.java
+++ b/lib/doorman/src/main/java/org/onap/ccsdk/features/lib/doorman/impl/MessageInterceptorImpl.java
@@ -180,10 +180,12 @@ public class MessageInterceptorImpl implements MessageInterceptor {
private Event waitForNewAction(int holdTime) {
long startTime = System.currentTimeMillis();
long currentTime = startTime;
- while (currentTime - startTime <= (holdTime + 1) * 1000) {
+ while (currentTime - startTime <= (holdTime + 1) * 1000L) {
try {
Thread.sleep(5000);
- } catch (Exception e) {
+ } catch (InterruptedException e) {
+ log.info("Break sleep : " + e.getMessage());
+ Thread.currentThread().interrupt();
}
MessageAction nextAction = messageDao.getNextAction(message.getMessageId());
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java
index b2f69dbcf..5fc06cb3c 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java
@@ -104,6 +104,7 @@ public class MessageQueueTest {
try {
Thread.sleep(startTime);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
}
MessageData r = interceptor.processRequest(request);
@@ -112,6 +113,7 @@ public class MessageQueueTest {
try {
Thread.sleep(processTime);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
}
interceptor.processResponse(response);
@@ -158,6 +160,7 @@ public class MessageQueueTest {
try {
Thread.sleep(processTime);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
}
}
}
diff --git a/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceManagerImpl.java b/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceManagerImpl.java
index 2cdef3537..9016579bc 100644
--- a/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceManagerImpl.java
+++ b/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceManagerImpl.java
@@ -415,7 +415,9 @@ public class NpmServiceManagerImpl implements NpmServiceManager {
try {
logger.trace("Initializing NPM Configurations from:({})", configFilePath);
if (new File(configFilePath).exists()) {
- npmConfigurations.load(new FileInputStream(configFilePath));
+ try (FileInputStream configInputStream = new FileInputStream(configFilePath)) {
+ npmConfigurations.load(configInputStream);
+ }
} else {
logger.warn("Config File:({}) not found, Initializing NPM with default configurations.", configFilePath);
configFilePath = "properties" + File.separator + NpmConstants.NPM_CONFIG_PROPERTIES_FILE_NAME;
diff --git a/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtils.java b/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtils.java
index 735d6d91f..8b74e318b 100644
--- a/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtils.java
+++ b/lib/network-prioritization/src/main/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtils.java
@@ -61,7 +61,7 @@ public class NpmUtils {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(instance);
} catch (JsonProcessingException e) {
- e.printStackTrace();
+ logger.warn(e.getMessage(), e);
}
return null;
}
diff --git a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java
index 63fe111df..a63b7d481 100644
--- a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java
+++ b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java
@@ -84,6 +84,7 @@ public class LockHelperImpl implements LockHelper {
try {
Thread.sleep(lockWait * 1000L);
} catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
}
}
}
diff --git a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java
index e92700055..419977890 100644
--- a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java
+++ b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java
@@ -1,5 +1,6 @@
package org.onap.ccsdk.features.lib.rlock;
+import java.security.SecureRandom;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -99,6 +100,7 @@ public abstract class SynchronizedFunction {
}
private static String generateLockRequester() {
- return "SynchronizedFunction-" + (int) (Math.random() * 1000000);
+ SecureRandom random = new SecureRandom();
+ return "SynchronizedFunction-" + (random.nextInt() % 1000000);
}
}
diff --git a/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java b/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java
index cce377e2c..4f205d16d 100644
--- a/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java
+++ b/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java
@@ -42,6 +42,7 @@ public class TestLockHelper {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
log.warn("Thread interrupted: " + e.getMessage(), e);
}