summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@ericsson.com>2018-06-11 12:04:33 +0100
committerwaqas.ikram <waqas.ikram@ericsson.com>2018-06-11 13:10:42 +0100
commit275a9d6e8c8caa883a119339926fba475969b8d5 (patch)
tree644b7fc816f41862e4912eea96862ece7b5c134f /core
parentd0746b062ca6b85eae756db6eb6c4dead037a35a (diff)
Fixing sonar bugs
Change-Id: I05a81755ce132810c9535babb7bae5b9b9e0bd60 Issue-ID: POLICY-859 Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
Diffstat (limited to 'core')
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java37
1 files changed, 11 insertions, 26 deletions
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 9d62a9f92..7e9a31a4f 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
@@ -20,8 +20,6 @@
package org.onap.policy.apex.core.infrastructure.messaging.impl.ws;
-import com.google.common.eventbus.Subscribe;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -40,6 +38,8 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
+import com.google.common.eventbus.Subscribe;
+
/**
* 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.
@@ -88,9 +88,9 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS
// Read the messages from the web socket and place them on the message queue for handling by
// the queue
// processing thread
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(new ByteArrayInputStream(dataByteBuffer.array()));
+
+ try (final ByteArrayInputStream stream = new ByteArrayInputStream(dataByteBuffer.array());
+ final ObjectInputStream ois = new ObjectInputStream(stream);) {
@SuppressWarnings("unchecked")
final MessageHolder<MESSAGE> messageHolder = (MessageHolder<MESSAGE>) ois.readObject();
@@ -99,15 +99,15 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS
messageHolder == null ? "Apex Engine " : messageHolder.getSenderHostAddress());
}
- final List<MESSAGE> messages = messageHolder.getMessages();
- if (messages != null) {
- messageBlockQueue.add(new MessageBlock<MESSAGE>(messages, incomingData.getConn()));
+ if (messageHolder != null) {
+ final List<MESSAGE> messages = messageHolder.getMessages();
+ if (messages != null) {
+ messageBlockQueue.add(new MessageBlock<MESSAGE>(messages, incomingData.getConn()));
+ }
}
- } catch (IOException | ClassNotFoundException e) {
+ } catch (final IOException | ClassNotFoundException e) {
LOGGER.error("Failed to process message received");
LOGGER.catching(e);
- } finally {
- closeObjectStream(ois);
}
}
@@ -130,21 +130,6 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS
}
/**
- * Close the {@link ObjectInputStream} stream.
- *
- * @param ois is an instance of {@link ObjectInputStream}
- */
- private void closeObjectStream(final ObjectInputStream ois) {
- if (ois != null) {
- try {
- ois.close();
- } catch (final IOException e) {
- LOGGER.catching(e);
- }
- }
- }
-
- /**
* This thread monitors the message queue and processes messages as they appear on the queue.
*
* @see java.lang.Runnable#run()