From a7073ff8b7f0cd1a211bbe2ba0954d4ec949404f Mon Sep 17 00:00:00 2001 From: Pawel Date: Wed, 22 May 2019 09:15:32 -0400 Subject: Fix sonar issues in WebRTCSocket Issue-ID: PORTAL-587 Signed-off-by: Pawel Change-Id: I3087714f7d3b8b012a8b93b1ac92b88d33cd910d --- .../portalsdk/core/web/socket/WebRTCSocket.java | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'ecomp-sdk/epsdk-core/src/main/java') diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java index ed8e89e3..dc18c3be 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java @@ -33,13 +33,14 @@ * * ============LICENSE_END============================================ * - * + * */ package org.onap.portalsdk.core.web.socket; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import javax.websocket.OnClose; import javax.websocket.OnMessage; import javax.websocket.OnOpen; @@ -55,8 +56,9 @@ public class WebRTCSocket { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WebRTCSocket.class); - private final static Map> channelMap = new Hashtable>(); - private final Map sessionMap = new Hashtable(); + private static final Map> channelMap = new HashMap<>(); + private static final String MESSAGE_FAILED = "mesage failed"; + private final Map sessionMap = new HashMap<>(); private final ObjectMapper mapper = new ObjectMapper(); @OnMessage @@ -69,11 +71,11 @@ public class WebRTCSocket { if (isOpen != null && (Boolean) isOpen) { String channel = (String) jsonObject.get("channel"); Object value = channelMap.get(channel); - Hashtable sourceDestMap; + HashMap sourceDestMap; if (value == null) - sourceDestMap = new Hashtable<>(); + sourceDestMap = new HashMap<>(); else - sourceDestMap = (Hashtable) value; + sourceDestMap = (HashMap) value; sourceDestMap.put(session.getId(), new Object[] { session }); channelMap.put(channel, sourceDestMap); @@ -81,7 +83,7 @@ public class WebRTCSocket { } } catch (Exception je) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", je); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, je); } try { @@ -97,26 +99,27 @@ public class WebRTCSocket { else channel = (String) jsonObject.get("channel"); } catch (Exception json) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", json); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, json); } - Hashtable sourceDestMap = channelMap.get(channel); + HashMap sourceDestMap = channelMap.get(channel); if (sourceDestMap != null) - for (String id : sourceDestMap.keySet()) { - if (!id.equals(session.getId())) { - Session otherSession = (Session) (sourceDestMap.get(id))[0]; + for (Entry entry : sourceDestMap.entrySet()){ + + if (!entry.getKey().equals(session.getId())) { + Session otherSession = (Session) (entry.getValue())[0]; if (otherSession.isOpen()) otherSession.getBasicRemote().sendText(mapper.writeValueAsString(dataObj)); } } } catch (Exception je) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", je); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, je); } } catch (Exception je) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", je); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, je); } } -- cgit 1.2.3-korg