import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.concurrent.CountDownLatch;
import javax.websocket.ClientEndpoint;
-import javax.websocket.DeploymentException;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
-//import org.apache.log4j.Logger;
-import org.glassfish.tyrus.client.ClientManager;
+import org.java_websocket.client.WebSocketClient;
+import org.java_websocket.handshake.ServerHandshake;
import org.onap.policy.api.NotificationScheme;
import org.onap.policy.api.NotificationType;
import org.onap.policy.api.PDPNotification;
import org.onap.policy.common.logging.flexlogger.*;
@ClientEndpoint
-public class ManualClientEnd {
+public class ManualClientEnd extends WebSocketClient {
private static CountDownLatch latch;
private static StdPDPNotification notification = null;
private static String resultJson = null;
private static Logger logger = FlexLogger.getLogger(ManualClientEnd.class.getName());
+ private static ManualClientEnd client;
+ public ManualClientEnd(URI serverUri) {
+ super(serverUri);
+ }
+
+ @Override
+ public void onClose(int arg0, String arg1, boolean arg2) {
+ // Not implemented
+ }
+
+ @Override
+ public void onError(Exception arg0) {
+ // Not implemented
+ }
+
+ @Override
+ public void onMessage(String arg0) {
+ // Not implemented
+ }
+
+ @Override
+ public void onOpen(ServerHandshake arg0) {
+ // Not implemented
+ }
+
public static void start(String url) {
latch = new CountDownLatch(1);
- ClientManager client = ClientManager.createClient();
- if(url.contains("https")){
+
+ if (url.contains("https")) {
url = url.replaceAll("https", "wss");
- }else {
+ }
+ else {
url = url.replaceAll("http", "ws");
}
+
try {
- client.connectToServer(ManualClientEnd.class, new URI(url+"notifications"));
+ client = new ManualClientEnd(new URI(url+"notifications"));
latch.await();
- } catch (DeploymentException | URISyntaxException | InterruptedException e) {
- logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
- } catch (IOException e) {
+ } catch (Exception e) {
logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
}
}
return null;
} else {
if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
- boolean removed = false, updated = false;
+ boolean removed = false;
+ boolean updated = false;
if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
removed = true;
}
public void onClose(Session session) {
logger.info("Session ended with "+ session.getId());
latch.countDown();
+ client.close();
}
@OnMessage
- public void onMessage(String message, Session session){
+ public static void onMessage(String message, Session session){
logger.debug(" Manual Notification Recieved Message : " + message +" Session info is : "+ session.getId());
resultJson = message;
try {