X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PDP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Frest%2Fnotifications%2FNotificationServer.java;h=4c2d1ef577ae1be33fa49fe853c640b0d0fbc8e4;hb=c5d97e8a9a6bea71f3be329a2e44bdbe5fe50882;hp=690d8c517d6014dfe955d8249fa99aa209e8c6ce;hpb=073cc188efe9abb4c010cf674e34e2cf46ef1c52;p=policy%2Fengine.git diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java index 690d8c517..4c2d1ef57 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PDP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; +import org.onap.policy.api.PolicyEngineException; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -66,8 +67,6 @@ public class NotificationServer { private static final Logger LOGGER = FlexLogger.getLogger(NotificationServer.class); private static Queue queue = new ConcurrentLinkedQueue<>(); private static String update = null; - private static String hosts = null; - private static URL aURL = null; @OnOpen public void openConnection(Session session) { @@ -88,7 +87,7 @@ public class NotificationServer { } @OnMessage - public void Message(String message, Session session) { + public void message(String message, Session session) { if(message.equalsIgnoreCase("Manual")) { try { @@ -101,14 +100,14 @@ public class NotificationServer { } } - public static void sendNotification(String notification, String propNotificationType, String pdpURL) throws Exception { + public static void sendNotification(String notification, String propNotificationType, String pdpURL) throws PolicyEngineException, IOException, InterruptedException { LOGGER.debug("Notification set to " + propNotificationType); if (propNotificationType.equals("ueb")){ String topic = null; try { - aURL = new URL(pdpURL); + URL aURL = new URL(pdpURL); topic = aURL.getHost() + aURL.getPort(); } catch (MalformedURLException e1) { pdpURL = pdpURL.replace("/", ""); @@ -116,7 +115,7 @@ public class NotificationServer { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in parsing out pdpURL for UEB notfication "); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e1, "Error in parsing out pdpURL for UEB notfication "); } - hosts = XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_SERVERS); + String hosts = XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_SERVERS); String apiKey = XACMLProperties.getProperty(XACMLRestProperties.PROP_UEB_API_KEY); String apiSecret = XACMLProperties.getProperty(XACMLRestProperties.PROP_UEB_API_SECRET); @@ -125,13 +124,13 @@ public class NotificationServer { try { if(hosts==null || topic==null || apiKey==null || apiSecret==null){ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file "); - throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file "); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file "); } - hosts.trim(); - topic.trim(); - apiKey.trim(); - apiSecret.trim(); + hosts = hosts.trim(); + topic = topic.trim(); + apiKey = apiKey.trim(); + apiSecret = apiSecret.trim(); pub = new CambriaClientBuilders.PublisherBuilder () .usingHosts ( hosts ) .onTopic ( topic ) @@ -175,13 +174,13 @@ public class NotificationServer { try { if(dmaapServers==null || topic==null){ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "DMaaP properties are missing from the property file "); - throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "DMaaP properties are missing from the property file "); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "DMaaP properties are missing from the property file "); } - dmaapServers.trim(); - topic.trim(); - aafLogin.trim(); - aafPassword.trim(); + dmaapServers= dmaapServers.trim(); + topic= topic.trim(); + aafLogin= aafLogin.trim(); + aafPassword= aafPassword.trim(); List dmaapList = null; if(dmaapServers.contains(",")) { @@ -209,11 +208,15 @@ public class NotificationServer { for(Session session: queue) { try { + LOGGER.info("\n Sending Notification: " + notification + " for client session id: " + session.getId() + "\n " + + "PDPUrl is " + pdpURL); + LOGGER.info("NotificationServer: sending text message"); session.getBasicRemote().sendText(notification); } catch (IOException e) { LOGGER.info(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in sending the Event Notification: "+ e.getMessage() + e); } } + NotificationService.sendNotification(notification); }