extract host from websocket to add route (#8922)

* extract host from websocket to add route

* move method to NetUtils

* imports

* import
This commit is contained in:
dahn 2024-06-28 15:32:19 +02:00 committed by GitHub
parent c7f1ba5b8e
commit 6575375537
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -16,6 +16,7 @@
// under the License.
package com.cloud.consoleproxy;
import com.cloud.utils.net.NetUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.eclipse.jetty.websocket.api.Session;
@ -284,6 +285,7 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
try {
if (StringUtils.isNotBlank(websocketUrl)) {
s_logger.info(String.format("Connect to VNC over websocket URL: %s", websocketUrl));
ConsoleProxy.ensureRoute(NetUtils.extractHost(websocketUrl));
client.connectToWebSocket(websocketUrl, session);
} else if (tunnelUrl != null && !tunnelUrl.isEmpty() && tunnelSession != null
&& !tunnelSession.isEmpty()) {

View File

@ -30,6 +30,7 @@ import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
@ -98,6 +99,10 @@ public class NetUtils {
public final static int IPV6_EUI64_11TH_BYTE = -1;
public final static int IPV6_EUI64_12TH_BYTE = -2;
public static String extractHost(String uri) throws URISyntaxException {
return (new URI(uri)).getHost();
}
public enum InternetProtocol {
IPv4, IPv6, DualStack;