code: public static URI applyDefaultPorts(URI uri) throws URISyntaxException {
  
          // contains WSS or WS...
          if (containsWebSocketScheme(uri)) {
              if (uri.getPort() == -1) {
  
                  if (WS_SCHEME.equals(uri.getScheme())) {
                      return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), 80, uri.getPath(), uri.getQuery(), uri.getFragment());
                  } else {
                      // must be WSS...
                      return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), 443, uri.getPath(), uri.getQuery(), uri.getFragment());
                  }
              }
              // contains a custom port:
              return uri;
          }
          throw new IllegalArgumentException("Can not apply WebSocket ports to invalid URI scheme");
      }
docs: If needed applies the default ports (80 / 443) to the given URI.
  
  @param uri the WebSocket URI
  @return URI containing WebSocket ports
  @throws IllegalArgumentException if there is a non valid WS URI
  @throws URISyntaxException given URI can not be parsed