openvidu-server: check websocket uris to its own method

pull/375/head
pabloFuente 2019-07-10 11:30:05 +02:00
parent 3b46860776
commit 705119d15a
2 changed files with 19 additions and 4 deletions

View File

@ -394,6 +394,9 @@ public class OpenviduConfig {
Gson gson = new Gson();
JsonArray kmsUrisArray = gson.fromJson(kmsUris, JsonArray.class);
this.kmsUrisList = JsonUtils.toStringList(kmsUrisArray);
for (String uri : kmsUrisList) {
this.checkWebsocketUri(uri);
}
}
public void initiateOpenViduWebhookEndpoint(String endpoint) throws Exception {
@ -451,4 +454,14 @@ public class OpenviduConfig {
log.info("OpenVidu Webhook events: {}", this.getOpenViduWebhookEvents().toString());
}
public void checkWebsocketUri(String uri) throws MalformedURLException {
try {
String parsedUri = uri.replaceAll("^ws://", "http://").replaceAll("^wss://", "https://");
new URL(parsedUri);
} catch (MalformedURLException e) {
log.error("URI {} is not a valid WebSocket endpoint", uri);
throw e;
}
}
}

View File

@ -68,13 +68,15 @@ public class Kms {
this.uri = uri;
this.id = "KMS-" + RandomStringUtils.randomAlphanumeric(6).toUpperCase();
String parsedUri = uri.replaceAll("^ws://", "http://").replaceAll("^wss://", "https://");
URL url = null;
try {
String parsedUri = "http://" + uri.replaceAll("^ws://", "").replaceAll("^wss://", "");
URL url = new URL(parsedUri);
this.ip = url.getHost();
url = new URL(parsedUri);
} catch (MalformedURLException e) {
log.error("KMS uri {} is not a valid WebSocket endpoint", uri);
log.error(e.getMessage());
}
this.ip = url.getHost();
this.loadManager = loadManager;
}