aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket
diff options
context:
space:
mode:
authorshikha0203 <shivani.khare@est.tech>2023-02-21 13:56:55 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-22 13:03:00 +0000
commit7b00f9af119e560d7974aab8aa405a6decbaa398 (patch)
treeec4533c48f01166e5494b1ba3cea157f861b5650 /openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket
parent59e446fb77ccf05aeae9b7046bd80e10124707c0 (diff)
Fix NotificationWebsocketHandler- Add null test before using nullable values
Issue-ID: SDC-4408 Signed-off-by: shikha0203 <shivani.khare@est.tech> Change-Id: I06d386c1e4234351461f792354091b6f1c472010
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket')
-rw-r--r--openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket/src/main/java/org/openecomp/sdc/notification/websocket/NotificationWebsocketHandler.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket/src/main/java/org/openecomp/sdc/notification/websocket/NotificationWebsocketHandler.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket/src/main/java/org/openecomp/sdc/notification/websocket/NotificationWebsocketHandler.java
index 7f21dee9a2..c5b9dab73c 100644
--- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket/src/main/java/org/openecomp/sdc/notification/websocket/NotificationWebsocketHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-websocket/src/main/java/org/openecomp/sdc/notification/websocket/NotificationWebsocketHandler.java
@@ -21,10 +21,13 @@ package org.openecomp.sdc.notification.websocket;
import com.google.gson.Gson;
import java.io.IOException;
+import java.net.URI;
+import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
+import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.notification.types.NotificationsStatusDto;
@@ -79,19 +82,26 @@ public class NotificationWebsocketHandler extends TextWebSocketHandler {
private String getOwnerId(WebSocketSession session) {
HttpHeaders handshakeHeaders = session.getHandshakeHeaders();
- if (handshakeHeaders.containsKey(COOKIE)) {
- String[] cookies = handshakeHeaders.get(COOKIE).get(0).split("; ");
- Optional<String> cookie = extractValue(cookies, USER_ID_HEADER_PARAM);
- if (cookie.isPresent()) {
- return cookie.get();
+ if (handshakeHeaders.containsKey(COOKIE)) {
+ final List<String> handshakeHeadersOrEmpty = handshakeHeaders.getOrEmpty(COOKIE);
+ if (CollectionUtils.isNotEmpty(handshakeHeadersOrEmpty)) {
+ final Optional<String> cookie = extractValue(handshakeHeadersOrEmpty.get(0).split("; "), USER_ID_HEADER_PARAM);
+ if (cookie.isPresent()) {
+ return cookie.get();
+ }
+ }
}
- }
LOGGER.error("No " + USER_ID_HEADER_PARAM + " specified in the session cookies.");
return null;
}
private UUID getLastEventId(WebSocketSession session) {
- String uriQuery = session.getUri().getQuery();
+ URI uri = session.getUri();
+ if (uri == null) {
+ LOGGER.warn("No " + LAST_DELIVERED_QUERY_PARAM + " specified in the request URI.");
+ return null;
+ }
+ String uriQuery = uri.getQuery();
if (uriQuery != null) {
String[] queries = uriQuery.split("; ");
Optional<String> paramValue = extractValue(queries, LAST_DELIVERED_QUERY_PARAM);