summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/websocketmanager/provider/src
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-08-24 06:16:11 +0200
committerMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-08-24 06:17:47 +0200
commitc8f7e3f376992b202ba26464b9b329d6c4b2821d (patch)
treec61507b22b28ccc536485a8bf291826d0461b031 /sdnr/wt/websocketmanager/provider/src
parent2a55fbf61c4450bfc2bb3f90b060c3aa65af91f3 (diff)
fix some sdnr sonar bugs
sonar fixes for some sdnr components Issue-ID: SDNC-1590 Change-Id: I02e44b6f5477bcd0490c3499caf20228eb9772ed Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/websocketmanager/provider/src')
-rw-r--r--sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java31
-rw-r--r--sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java10
2 files changed, 31 insertions, 10 deletions
diff --git a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
index 7c12c4baa..7cc6d7272 100644
--- a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
+++ b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
@@ -80,8 +80,12 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
.get(SEND_MESSAGE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
LOG.info("message sent");
}
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ } catch (ExecutionException | TimeoutException e) {
LOG.warn("problem pushing message: ", e);
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted!", e);
+ // Restore interrupted state...
+ Thread.currentThread().interrupt();
}
if (messageQueue.isEmpty()) {
@@ -163,7 +167,7 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
closed = false;
this.sendingSyncThread.start();
clientList.put(String.valueOf(this.hashCode()), this);
- LOG.debug("client connected from " + this.getRemoteAdr());
+ LOG.debug("client connected from {}", this.getRemoteAdr());
}
@Override
@@ -171,12 +175,12 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
clientList.remove(String.valueOf(this.hashCode()));
this.sendingSyncThread.interrupt();
closed = true;
- LOG.debug("client disconnected from " + this.getRemoteAdr());
+ LOG.debug("client disconnected from {}", this.getRemoteAdr());
}
@Override
public void onWebSocketError(Throwable cause) {
- LOG.debug("error caused on " + this.getRemoteAdr() + " :" + cause.getMessage());
+ LOG.debug("error caused on {}: ",this.getRemoteAdr(), cause);
}
private String getRemoteAdr() {
@@ -212,11 +216,11 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
}
} catch (JsonProcessingException e) {
- LOG.warn("problem set scope: " + e.getMessage());
+ LOG.warn("problem set scope: {}" ,e.getMessage());
try {
this.send(mapper.writeValueAsString(ScopeRegistrationResponse.error(e.getMessage())));
} catch (JsonProcessingException e1) {
- LOG.warn("problem sending error response via ws: " + e1);
+ LOG.warn("problem sending error response via ws: ", e1);
}
}
return ret;
@@ -232,7 +236,7 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
this.sendToAll(notification.getNodeId(), notification.getType(), request);
}
} catch (Exception e) {
- LOG.warn("handle ws request failed:" + e.getMessage());
+ LOG.warn("handle ws request failed:",e);
}
}
@@ -241,7 +245,9 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
LOG.trace("sending {}", msg);
this.messageQueue.put(msg);
} catch (InterruptedException e) {
- LOG.warn("problem putting message into sending queue: " + e.getMessage());
+ LOG.warn("problem putting message into sending queue: {}", e.getMessage());
+ // Restore interrupted state...
+ Thread.currentThread().interrupt();
}
}
@@ -294,8 +300,13 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
}
public static void broadCast(DOMNotificationOutput domNotificationOutput) {
- // TODO Auto-generated method stub
-
+ if (clientList.size() > 0) {
+ Set<Entry<String, WebSocketManagerSocket>> e = clientList.entrySet();
+ WebSocketManagerSocket s = e.iterator().next().getValue();
+ if (s != null) {
+ s.sendToAll(domNotificationOutput);
+ }
+ }
}
}
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
index 885ded348..ca3d6918c 100644
--- a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
+++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
@@ -58,6 +58,16 @@ public class UserScopeTest {
}
+ @Test
+ public void testSchemaInfoClass() {
+ ReducedSchemaInfo si = new ReducedSchemaInfo(ProblemNotification.QNAME);
+ assertTrue(si.equals(ProblemNotification.QNAME));
+ assertFalse(si.equals(ObjectCreationNotification.QNAME));
+ si.setRevision(null);
+ assertFalse(si.equals(ProblemNotification.QNAME));
+
+ }
+
private static final Scope buildScope(String nodeId, String namespace, String revision,
List<String> notifications) {
Scope scope = new Scope();