Java 17 Upgrade
Updated dependencies to latest versions
Made Java 17 changes
Moved apex dependencies versions to main apex pom
Issue-ID: POLICY-4675
Change-Id: Ia5cd5670a1f024f5402cbd7371162ce3313930ef
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
diff --git a/tools/model-generator/pom.xml b/tools/model-generator/pom.xml
index a9b93d3..6dc029b 100644
--- a/tools/model-generator/pom.xml
+++ b/tools/model-generator/pom.xml
@@ -19,12 +19,12 @@
============LICENSE_END=========================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.apex-pdp.tools</groupId>
<artifactId>tools</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>model-generator</artifactId>
@@ -63,16 +63,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
<plugins>
- <!-- Copy required resources and examples -->
+ <!-- Copy required resources and examples -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
@@ -158,7 +153,7 @@
</goals>
</pluginExecutionFilter>
<action>
- <ignore />
+ <ignore/>
</action>
</pluginExecution>
</pluginExecutions>
diff --git a/tools/pom.xml b/tools/pom.xml
index 0951be9..1ca134e 100644
--- a/tools/pom.xml
+++ b/tools/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp</groupId>
<artifactId>apex-pdp</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.apex-pdp.tools</groupId>
diff --git a/tools/simple-wsclient/pom.xml b/tools/simple-wsclient/pom.xml
index d2e6957..6d33b7a 100644
--- a/tools/simple-wsclient/pom.xml
+++ b/tools/simple-wsclient/pom.xml
@@ -1,6 +1,7 @@
<!--
============LICENSE_START=======================================================
Copyright (C) 2018 Ericsson. All rights reserved.
+ Modifications Copyright (C) 2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,7 +23,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.tools</groupId>
<artifactId>tools</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>simple-wsclient</artifactId>
@@ -31,14 +32,30 @@
<dependencies>
<dependency>
- <groupId>org.java-websocket</groupId>
- <artifactId>Java-WebSocket</artifactId>
+ <groupId>jakarta.websocket</groupId>
+ <artifactId>jakarta.websocket-api</artifactId>
+ <version>${version.websocket.jakarta}</version>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.websocket</groupId>
+ <artifactId>jakarta.websocket-client-api</artifactId>
+ <version>${version.websocket.jakarta}</version>
</dependency>
<dependency>
<groupId>org.onap.policy.apex-pdp.tools</groupId>
<artifactId>tools-common</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-jakarta-client</artifactId>
+ <version>${version.jetty}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-jakarta-server</artifactId>
+ <version>${version.jetty}</version>
+ </dependency>
</dependencies>
<build>
diff --git a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleConsole.java b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleConsole.java
index 8e607eb..2e6714f 100644
--- a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleConsole.java
+++ b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleConsole.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,17 @@
package org.onap.policy.apex.tools.simple.wsclient;
+import jakarta.websocket.ClientEndpoint;
+import jakarta.websocket.CloseReason;
+import jakarta.websocket.CloseReason.CloseCodes;
+import jakarta.websocket.ContainerProvider;
+import jakarta.websocket.DeploymentException;
+import jakarta.websocket.OnClose;
+import jakarta.websocket.OnError;
+import jakarta.websocket.OnMessage;
+import jakarta.websocket.OnOpen;
+import jakarta.websocket.Session;
+import jakarta.websocket.WebSocketContainer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -29,16 +41,14 @@
import java.net.URISyntaxException;
import java.nio.channels.NotYetConnectedException;
import org.apache.commons.lang3.Validate;
-import org.java_websocket.client.WebSocketClient;
-import org.java_websocket.framing.CloseFrame;
-import org.java_websocket.handshake.ServerHandshake;
/**
* Simple WS client with a console for events.
*
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
-public class SimpleConsole extends WebSocketClient {
+@ClientEndpoint
+public class SimpleConsole {
/** Application name, used as prompt. */
private final String appName;
@@ -46,6 +56,8 @@
// Output and error streams
private PrintStream outStream;
private PrintStream errStream;
+ // The Websocket Session
+ private Session userSession;
/**
* Creates a new simple echo object.
@@ -56,42 +68,54 @@
* @param outStream the stream for message output
* @param errStream the stream for error messages
* @throws URISyntaxException is URI could not be created from server/port settings
+ * @throws IOException on IO exceptions
+ * @throws DeploymentException on deployment exceptions
* @throws RuntimeException if server or port where blank
*/
public SimpleConsole(final String server, final String port, final String appName, PrintStream outStream,
- PrintStream errStream) throws URISyntaxException {
- super(new URI("ws://" + server + ":" + port));
+ PrintStream errStream) throws URISyntaxException, DeploymentException, IOException {
Validate.notBlank(appName, "SimpleConsole: given application name was blank");
+ WebSocketContainer container = ContainerProvider.getWebSocketContainer();
+ container.connectToServer(this, new URI("ws://" + server + ":" + port));
+
this.appName = appName;
this.outStream = outStream;
this.errStream = errStream;
}
- @Override
- public void onClose(final int code, final String reason, final boolean remote) {
- outStream.println(this.appName + ": Connection closed by " + (remote ? "APEX" : "me"));
+ /**
+ * Callback hook for Connection close events.
+ *
+ * @param userSession the userSession which is getting closed.
+ * @param reason the reason for connection close
+ */
+ @OnClose
+ public void onClose(Session userSession, CloseReason reason) {
+ outStream.println(this.appName + ": Connection closed");
+
outStream.print(" ==-->> ");
- switch (code) {
- case CloseFrame.NORMAL:
+ CloseCodes reasonCloseCode = CloseCodes.valueOf(reason.getCloseCode().toString());
+ switch (reasonCloseCode) {
+ case NORMAL_CLOSURE:
outStream.println("normal");
break;
- case CloseFrame.GOING_AWAY:
+ case GOING_AWAY:
outStream.println("APEX going away");
break;
- case CloseFrame.PROTOCOL_ERROR:
+ case PROTOCOL_ERROR:
outStream.println("some protocol error");
break;
- case CloseFrame.REFUSE:
+ case CANNOT_ACCEPT:
outStream.println("received unacceptable type of data");
break;
- case CloseFrame.NO_UTF8:
+ case CLOSED_ABNORMALLY:
outStream.println("expected UTF-8, found something else");
break;
- case CloseFrame.TOOBIG:
+ case TOO_BIG:
outStream.println("message too big");
break;
- case CloseFrame.UNEXPECTED_CONDITION:
+ case UNEXPECTED_CONDITION:
outStream.println("unexpected server condition");
break;
default:
@@ -101,19 +125,32 @@
outStream.print(" ==-->> " + reason);
}
- @Override
+
+ @OnError
public void onError(final Exception ex) {
errStream.println(this.appName + ": " + ex.getMessage());
}
- @Override
- public void onMessage(final String message) {
+ /**
+ * Callback hook for Message Events. This method will be invoked when a client send a message.
+ *
+ * @param message The text message
+ */
+ @OnMessage
+ public void onMessage(String message) {
// this client does not expect messages
}
- @Override
- public void onOpen(final ServerHandshake handshakedata) {
- outStream.println(this.appName + ": opened connection to APEX (" + handshakedata.getHttpStatusMessage() + ")");
+ /**
+ * Callback hook for Connection open events.
+ *
+ * @param userSession the userSession which is opened.
+ */
+ @OnOpen
+ public void onOpen(Session userSession) {
+ outStream.println(this.appName + ": opened connection to APEX (" + userSession.getRequestURI() + ")");
+
+ this.userSession = userSession;
}
/**
@@ -124,15 +161,6 @@
* @throws IOException on an IO problem on standard in
*/
public void runClient() throws IOException {
- final Thread thread = new Thread() {
- @Override
- public void run() {
- connect();
- }
- };
- thread.setName("ClientThread");
- thread.start();
-
final var in = new BufferedReader(new InputStreamReader(System.in));
var event = new StringBuilder();
String line;
@@ -143,15 +171,15 @@
final String current = line.trim();
if ("".equals(current)) {
- this.send(event.toString());
+ this.userSession.getBasicRemote().sendText(event.toString());
event = new StringBuilder();
} else {
event.append(current);
}
}
- thread.interrupt();
- this.close(CloseFrame.NORMAL);
+ this.userSession.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Normal Closure"));
}
+
}
diff --git a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java
index 672594c..8c7aec0 100644
--- a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java
+++ b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,20 +21,30 @@
package org.onap.policy.apex.tools.simple.wsclient;
+import jakarta.websocket.ClientEndpoint;
+import jakarta.websocket.CloseReason;
+import jakarta.websocket.CloseReason.CloseCodes;
+import jakarta.websocket.ContainerProvider;
+import jakarta.websocket.DeploymentException;
+import jakarta.websocket.OnClose;
+import jakarta.websocket.OnError;
+import jakarta.websocket.OnMessage;
+import jakarta.websocket.OnOpen;
+import jakarta.websocket.Session;
+import jakarta.websocket.WebSocketContainer;
+import java.io.IOException;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.lang3.Validate;
-import org.java_websocket.client.WebSocketClient;
-import org.java_websocket.framing.CloseFrame;
-import org.java_websocket.handshake.ServerHandshake;
/**
* Simple WS client as an echo.
*
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
-public class SimpleEcho extends WebSocketClient {
+@ClientEndpoint
+public class SimpleEcho {
/** Application name, used as prompt. */
private final String appName;
@@ -51,42 +62,54 @@
* @param outStream the stream for message output
* @param errStream the stream for error messages
* @throws URISyntaxException is URI could not be created from server/port settings
+ * @throws IOException on IO exceptions
+ * @throws DeploymentException on deployment exceptions
* @throws RuntimeException if server or port where blank
*/
public SimpleEcho(final String server, final String port, final String appName, PrintStream outStream,
- PrintStream errStream) throws URISyntaxException {
- super(new URI("ws://" + server + ":" + port));
+ PrintStream errStream) throws URISyntaxException, DeploymentException, IOException {
+
Validate.notBlank(appName, "SimpleEcho: given application name was blank");
-
+ WebSocketContainer container = ContainerProvider.getWebSocketContainer();
+ container.connectToServer(this, new URI("ws://" + server + ":" + port));
+
this.appName = appName;
this.outStream = outStream;
this.errStream = errStream;
}
- @Override
- public void onClose(final int code, final String reason, final boolean remote) {
- outStream.println(this.appName + ": Connection closed by " + (remote ? "APEX" : "me"));
+ /**
+ * Callback hook for Connection close events.
+ *
+ * @param userSession the userSession which is getting closed.
+ * @param reason the reason for connection close
+ */
+ @OnClose
+ public void onClose(Session userSession, CloseReason reason) {
+ outStream.println(this.appName + ": Connection closed");
outStream.print(" ==-->> ");
- switch (code) {
- case CloseFrame.NORMAL:
+
+ CloseCodes reasonCloseCode = CloseCodes.valueOf(reason.getCloseCode().toString());
+ switch (reasonCloseCode) {
+ case NORMAL_CLOSURE:
outStream.println("normal");
break;
- case CloseFrame.GOING_AWAY:
+ case GOING_AWAY:
outStream.println("APEX going away");
break;
- case CloseFrame.PROTOCOL_ERROR:
+ case PROTOCOL_ERROR:
outStream.println("some protocol error");
break;
- case CloseFrame.REFUSE:
+ case CANNOT_ACCEPT:
outStream.println("received unacceptable type of data");
break;
- case CloseFrame.NO_UTF8:
+ case CLOSED_ABNORMALLY:
outStream.println("expected UTF-8, found something else");
break;
- case CloseFrame.TOOBIG:
+ case TOO_BIG:
outStream.println("message too big");
break;
- case CloseFrame.UNEXPECTED_CONDITION:
+ case UNEXPECTED_CONDITION:
outStream.println("unexpected server condition");
break;
default:
@@ -96,13 +119,18 @@
outStream.print(" ==-->> " + reason);
}
- @Override
+ @OnError
public void onError(final Exception ex) {
errStream.println(this.appName + ": " + ex.getMessage());
}
- @Override
- public void onMessage(final String message) {
+ /**
+ * Callback hook for Message Events. This method will be invoked when a client send a message.
+ *
+ * @param message The text message
+ */
+ @OnMessage
+ public void onMessage(String message) {
outStream.println(this.appName + ": received");
outStream.println("---------------------------------");
outStream.println(message);
@@ -110,9 +138,13 @@
outStream.println();
}
- @Override
- public void onOpen(final ServerHandshake handshakedata) {
- outStream.println(this.appName + ": opened connection to APEX (" + handshakedata.getHttpStatusMessage() + ")");
+ /**
+ * Callback hook for Connection open events.
+ *
+ * @param userSession the userSession which is opened.
+ */
+ @OnOpen
+ public void onOpen(Session userSession) {
+ outStream.println(this.appName + ": opened connection to APEX (" + userSession.getRequestURI() + ")");
}
-
}
diff --git a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java
index e3af4dc..405013b 100644
--- a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java
+++ b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
package org.onap.policy.apex.tools.simple.wsclient;
+import jakarta.websocket.DeploymentException;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -141,8 +143,7 @@
outStream.println();
try {
- final var simpleEcho = new SimpleEcho(server, port, APP_NAME, outStream, outStream);
- simpleEcho.connect();
+ new SimpleEcho(server, port, APP_NAME, outStream, outStream);
} catch (final URISyntaxException uex) {
String message = APP_NAME + ": URI exception, could not create URI from server and port settings";
outStream.println(message);
@@ -155,6 +156,18 @@
String message = APP_NAME + ": illegal argument, server or port were blank";
outStream.println(message);
LOGGER.warn(message, iex);
+ } catch (DeploymentException dex) {
+ String message = APP_NAME + ": could not deploy client";
+ outStream.println(message);
+ LOGGER.warn(message, dex);
+ } catch (IOException iox) {
+ String message = APP_NAME + ": illegal argument, IO execption on client";
+ outStream.println(message);
+ LOGGER.warn(message, iox);
+ } catch (Exception xex) {
+ String message = APP_NAME + ": Unknown execption on client";
+ outStream.println(message);
+ LOGGER.warn(message, xex);
}
}
@@ -199,10 +212,18 @@
String message = APP_NAME + ": not yet connected, connection to server took too long";
outStream.println(message);
LOGGER.warn(message, nex);
+ } catch (DeploymentException dex) {
+ String message = APP_NAME + ": could not deploy client";
+ outStream.println(message);
+ LOGGER.warn(message, dex);
} catch (final IOException ioe) {
String message = APP_NAME + ": IO exception, something went wrong on the standard input";
outStream.println(message);
LOGGER.warn(message, ioe);
+ } catch (Exception xex) {
+ String message = APP_NAME + ": Unknown execption on client";
+ outStream.println(message);
+ LOGGER.warn(message, xex);
}
}
diff --git a/tools/tools-common/pom.xml b/tools/tools-common/pom.xml
index 3599003..71fcb3c 100644
--- a/tools/tools-common/pom.xml
+++ b/tools/tools-common/pom.xml
@@ -17,12 +17,13 @@
SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.apex-pdp.tools</groupId>
<artifactId>tools</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>tools-common</artifactId>
@@ -46,11 +47,6 @@
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>