From 6a9b54b275feff5369419a86997e94d0a95fc48e Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Thu, 7 Jun 2018 16:01:35 +0100 Subject: Fixing Sonar bugs and Vulnerabilities Change-Id: Id5a95f23f1308dbb9f7f0c0f5567e238ecf830af Issue-ID: POLICY-859 Signed-off-by: waqas.ikram --- .../messaging/impl/ws/RawMessageHandler.java | 24 +++--- .../messaging/impl/ws/client/MessagingClient.java | 25 +++--- .../impl/ws/server/MessageServerImpl.java | 10 ++- .../messaging/util/MessagingUtils.java | 89 ++++++++++------------ .../infrastructure/threading/ThreadUtilities.java | 2 + 5 files changed, 81 insertions(+), 69 deletions(-) (limited to 'core/core-infrastructure') diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java index 534bee8af..9d62a9f92 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java @@ -41,8 +41,8 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards the messages to the - * DataHandler instance that has subscribed to the RawMessageHandler instance. + * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards + * the messages to the DataHandler instance that has subscribed to the RawMessageHandler instance. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) * @param the generic type of message being received @@ -85,7 +85,8 @@ public class RawMessageHandler implements WebSocketMessageListener implements WebSocketMessageListener messageHolder = (MessageHolder) ois.readObject(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("message {} recieved from the client {} ", messageHolder.toString(), + LOGGER.debug("message {} recieved from the client {} ", messageHolder, messageHolder == null ? "Apex Engine " : messageHolder.getSenderHostAddress()); } @@ -111,7 +112,8 @@ public class RawMessageHandler implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener the generic type @@ -39,12 +39,13 @@ public class MessagingClient extends InternalMessageBusClient // The length of time to wait for a connection to a web socket server before aborting private static final int CONNECTION_TIMEOUT_TIME_MS = 3000; - // The length of time to wait before checking if a connection to a web socket server has worked or not + // The length of time to wait before checking if a connection to a web socket server has worked + // or not private static final int CONNECTION_TRY_INTERVAL_MS = 100; /** - * Constructor of this class, uses its {@link InternalMessageBusClient} superclass to set up the web socket and - * handle incoming message forwarding. + * Constructor of this class, uses its {@link InternalMessageBusClient} superclass to set up the + * web socket and handle incoming message forwarding. * * @param serverUri The URI of the service */ @@ -80,7 +81,11 @@ public class MessagingClient extends InternalMessageBusClient public void startConnection() { // Open the web socket final WebSocket connection = super.getConnection(); - if (connection != null && !connection.isOpen()) { + + if (connection == null) { + throw new IllegalStateException("Could not connect to the server"); + } + if (!connection.isOpen()) { connect(); } @@ -129,8 +134,9 @@ public class MessagingClient extends InternalMessageBusClient /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex.core. - * infrastructure. messaging.MessageHolder) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex + * .core. infrastructure. messaging.MessageHolder) */ @Override public void send(final MessageHolder commands) { @@ -142,7 +148,8 @@ public class MessagingClient extends InternalMessageBusClient /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) */ @Override public void send(final String messageString) { diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java index fc401576f..ee6e1a329 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java @@ -98,6 +98,8 @@ public class MessageServerImpl extends InternalMessageBusServer extends InternalMessageBusServer message) { @@ -134,7 +137,8 @@ public class MessageServerImpl extends InternalMessageBusServer