private void parseUrl(String urlStr) throws WebSocketException {
        try {
            URI uri = new URI(urlStr);
            if (!(uri.getScheme().equals("ws") || uri.getScheme().equals("wss"))) {
                throw new WebSocketException(E3007, uri.toString());
            }
            if (uri.getScheme().equals("wss")) {
                useSsl = true;
            }
            path = (uri.getPath().equals("") ? "/" : uri.getPath()) + (uri.getQuery() != null ? "?" + uri.getQuery() : "");
            int port = uri.getPort();
            if (port < 0) {
                if (uri.getScheme().equals("ws")) {
                    port = 80;
                } else if (uri.getScheme().equals("wss")) {
                    port = 443;
                    useSsl = true;
                } else {
                    throw new WebSocketException(E3008, uri.toString());
                }
            }
            endpointAddress = new InetSocketAddress(uri.getHost(), port);
            location = uri;
        } catch (URISyntaxException e) {
            throw new WebSocketException(E3009, e);
        }
    }