private static HttpUrl convertToOkHttpUrl(HttpClient baseHttpClient, String basePath, String groupPrefix) { final URI uri = baseHttpClient.uri(); final SessionProtocol sessionProtocol = Scheme.tryParse(uri.getScheme()) .map(Scheme::sessionProtocol) .orElseGet(() -> SessionProtocol.of(uri.getScheme())); final String authority = uri.getAuthority(); final String protocol = sessionProtocol.isTls() ? "https" : "http"; final HttpUrl parsed; if (authority.startsWith("group:")) { parsed = HttpUrl.parse(protocol + "://" + authority.replace("group:", groupPrefix) + basePath); } else { parsed = HttpUrl.parse(protocol + "://" + authority + basePath); } assert parsed != null; return parsed; } }
/** * Makes sure the scheme of the specified {@link URI} is supported by this {@link ClientFactory}. * * @param uri the {@link URI} of the server endpoint * @return the parsed {@link Scheme} * * @throws IllegalArgumentException if the scheme of the specified {@link URI} is not supported by this * {@link ClientFactory} */ protected final Scheme validateScheme(URI uri) { requireNonNull(uri, "uri"); final String scheme = uri.getScheme(); if (scheme == null) { throw new IllegalArgumentException("URI with missing scheme: " + uri); } if (uri.getAuthority() == null) { throw new IllegalArgumentException("URI with missing authority: " + uri); } final Optional<Scheme> parsedSchemeOpt = Scheme.tryParse(scheme); if (!parsedSchemeOpt.isPresent()) { throw new IllegalArgumentException("URI with unknown scheme: " + uri); } final Scheme parsedScheme = parsedSchemeOpt.get(); final Set<Scheme> supportedSchemes = supportedSchemes(); if (!supportedSchemes.contains(parsedScheme)) { throw new IllegalArgumentException( "URI with unsupported scheme: " + uri + " (expected: " + supportedSchemes + ')'); } return parsedScheme; }
} else { sessionProtocol = Scheme.tryParse(schemeStr) .orElseThrow(() -> new IllegalArgumentException("uri.scheme is not valid: " + uri)) .sessionProtocol();