import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
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.glassfish.tyrus.client.ClientManager;
+import org.java_websocket.client.WebSocketClient;
+import org.java_websocket.handshake.ServerHandshake;
import org.onap.policy.api.NotificationHandler;
import org.onap.policy.api.NotificationScheme;
import org.onap.policy.api.NotificationType;
import org.onap.policy.xacml.api.XACMLErrorConstants;
@ClientEndpoint
-public class AutoClientEnd {
+public class AutoClientEnd extends WebSocketClient {
private static StdPDPNotification notification = null;
private static StdPDPNotification oldNotification = null;
- private static ClientManager client = null;
+ private static AutoClientEnd client = null;
private static NotificationScheme scheme = null;
private static NotificationHandler handler = null;
private static String url = null;
private static boolean error = false;
private static Logger logger = FlexLogger.getLogger(AutoClientEnd.class.getName());
+ private AutoClientEnd(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 setAuto(NotificationScheme scheme,
NotificationHandler handler) {
AutoClientEnd.scheme = scheme;
AutoClientEnd.client != null) {
return;
}
-
- // Stop and Start needs to be done.
- client = ClientManager.createClient();
- if(url.contains("https")){
+
+ if (url.contains("https")) {
url = url.replaceAll("https", "wss");
- }else {
+ }
+ else {
url = url.replaceAll("http", "ws");
}
+
+
+ // Stop and Start needs to be done.
try {
logger.info("Starting Auto Notification with the PDP server : " + url);
- client.connectToServer(AutoClientEnd.class, new URI(url + "notifications"));
+ client = new AutoClientEnd(new URI(url + "notifications"));
status = true;
if(error){
// The URL's will be in Sync according to design Spec.
error = false;
}
//
- } catch (DeploymentException | IOException | URISyntaxException e) {
+ } catch (Exception e) {
logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
client = null;
status = false;
if (client == null) {
return;
}
- client.shutdown();
+ client.close();
if(session!=null){
try {
stop = true;