bszabo97 commented on code in PR #1182: URL: https://github.com/apache/solr/pull/1182#discussion_r1127688733
########## solr/core/src/java/org/apache/solr/util/SolrCLI.java: ########## @@ -582,59 +571,41 @@ public static boolean checkCommunicationError(Exception exc) { Throwable rootCause = SolrException.getRootCause(exc); boolean wasCommError = (rootCause instanceof ConnectException - || rootCause instanceof ConnectTimeoutException - || rootCause instanceof NoHttpResponseException + || rootCause instanceof SolrServerException || rootCause instanceof SocketException); return wasCommError; } - /** - * Tries a simple HEAD request and throws SolrException in case of Authorization error - * - * @param url the url to do a HEAD request to - * @param httpClient the http client to use (make sure it has authentication optinos set) - * @return the HTTP response code - * @throws SolrException if auth/autz problems - * @throws IOException if connection failure - */ - private static int attemptHttpHead(String url, HttpClient httpClient) - throws SolrException, IOException { - HttpResponse response = - httpClient.execute(new HttpHead(url), HttpClientUtil.createNewHttpClientRequestContext()); - int code = response.getStatusLine().getStatusCode(); + private static void checkCodeForAuthError(int code) { if (code == UNAUTHORIZED.code || code == FORBIDDEN.code) { throw new SolrException( SolrException.ErrorCode.getErrorCode(code), - "Solr requires authentication for " - + url - + ". Please supply valid credentials. HTTP code=" + "Solr requires authentication for request. Please supply valid credentials. HTTP code=" + code); } - return code; } private static boolean exceptionIsAuthRelated(Exception exc) { return (exc instanceof SolrException && Arrays.asList(UNAUTHORIZED.code, FORBIDDEN.code).contains(((SolrException) exc).code())); } - public static CloseableHttpClient getHttpClient() { - ModifiableSolrParams params = new ModifiableSolrParams(); - params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 128); - params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32); - params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, false); - return HttpClientUtil.createClient(params); + public static SolrClient getSolrClient(String solrUrl) { + return new Http2SolrClient.Builder(solrUrl).maxConnectionsPerHost(32).build(); } - @SuppressWarnings("deprecation") - public static void closeHttpClient(CloseableHttpClient httpClient) { - if (httpClient != null) { - try { - HttpClientUtil.close(httpClient); - } catch (Exception exc) { - // safe to ignore, we're just shutting things down - } + public static String getSolrUrlFromUri(URI uri) { + return uri.getScheme() + "://" + uri.getAuthority() + "/" + uri.getPath().split("/")[1]; + } + + public static ModifiableSolrParams getSolrParamsFromUri(URI uri) { + ModifiableSolrParams paramsMap = new ModifiableSolrParams(); + String[] params = uri.getQuery() == null ? new String[] {} : uri.getQuery().split("&"); + for (String param : params) { + String[] paramSplit = param.split("="); + paramsMap.add(paramSplit[0], paramSplit[1]); Review Comment: I may be mistaken but I think the `getQuery` method returns the decoded version of the query. This is what I found in the javadoc: ``` Returns the decoded query component of this URI. ``` Is this what you meant should be decoded or did I misunderstand something? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org