diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index aeb39b85604..be205a4ae3c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -156,9 +156,6 @@ Bug Fixes at a node before its local state had updated with the new collection data (Alan Woodward) -* SOLR-9604: Pooled SSL connections were not being re-used (Alan Woodward, - Mikhail Khludnev, hossman) - Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java index 68658195ada..e5d26531fbe 100644 --- a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java +++ b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java @@ -16,11 +16,8 @@ */ package org.apache.solr.security; -import javax.servlet.FilterChain; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.lang.invoke.MethodHandles; import java.nio.ByteBuffer; @@ -30,6 +27,12 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import javax.servlet.FilterChain; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; + import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; @@ -55,8 +58,6 @@ import org.apache.solr.util.CryptoKeys; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static java.nio.charset.StandardCharsets.UTF_8; - public class PKIAuthenticationPlugin extends AuthenticationPlugin implements HttpClientBuilderPlugin { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -197,8 +198,7 @@ public class PKIAuthenticationPlugin extends AuthenticationPlugin implements Htt try { String uri = url + PATH + "?wt=json&omitHeader=true"; log.debug("Fetching fresh public key from : {}",uri); - HttpResponse rsp = cores.getUpdateShardHandler().getHttpClient() - .execute(new HttpGet(uri), HttpClientUtil.createNewHttpClientRequestContext(this)); + HttpResponse rsp = cores.getUpdateShardHandler().getHttpClient().execute(new HttpGet(uri), HttpClientUtil.createNewHttpClientRequestContext()); byte[] bytes = EntityUtils.toByteArray(rsp.getEntity()); Map m = (Map) Utils.fromJSON(bytes); String key = (String) m.get("key"); diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java index cb01fa44f20..bc5edd5cf70 100644 --- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java +++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java @@ -558,8 +558,7 @@ public class HttpSolrCall { method.removeHeaders(CONTENT_LENGTH_HEADER); } - final HttpResponse response - = solrDispatchFilter.httpClient.execute(method, HttpClientUtil.createNewHttpClientRequestContext(cores)); + final HttpResponse response = solrDispatchFilter.httpClient.execute(method, HttpClientUtil.createNewHttpClientRequestContext()); int httpStatus = response.getStatusLine().getStatusCode(); httpEntity = response.getEntity(); diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java index ee16742f3df..f1a31a1d66f 100644 --- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java @@ -647,7 +647,7 @@ public class SolrCLI { // ensure we're requesting JSON back from Solr HttpGet httpGet = new HttpGet(new URIBuilder(getUrl).setParameter(CommonParams.WT, CommonParams.JSON).build()); // make the request and get back a parsed JSON object - Map json = httpClient.execute(httpGet, new SolrResponseHandler(), HttpClientUtil.createNewHttpClientRequestContext(null)); + Map json = httpClient.execute(httpGet, new SolrResponseHandler(), HttpClientUtil.createNewHttpClientRequestContext()); // check the response JSON from Solr to see if it is an error Long statusCode = asLong("/responseHeader/status", json); if (statusCode == -1) { diff --git a/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java index 1a59633024d..4c4b52eb867 100644 --- a/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java +++ b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java @@ -90,7 +90,7 @@ public class TestAuthorizationFramework extends AbstractFullDistribZkTestBase { List hierarchy = StrUtils.splitSmart(objPath, '/'); for (int i = 0; i < count; i++) { HttpGet get = new HttpGet(url); - s = EntityUtils.toString(cl.execute(get, HttpClientUtil.createNewHttpClientRequestContext(null)).getEntity()); + s = EntityUtils.toString(cl.execute(get, HttpClientUtil.createNewHttpClientRequestContext()).getEntity()); Map m = (Map) Utils.fromJSONString(s); Object actual = Utils.getObjectByPath(m, true, hierarchy); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java index 86c8b4510c9..f209672b247 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java @@ -320,8 +320,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient { method.addHeader("User-Agent", HttpSolrClient.AGENT); method.addHeader("Content-Type", contentType); - response = client.getHttpClient() - .execute(method, HttpClientUtil.createNewHttpClientRequestContext(scheduler)); + response = client.getHttpClient().execute(method, HttpClientUtil.createNewHttpClientRequestContext()); rspBody = response.getEntity().getContent(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java index d6457599c53..b9580b8dc4c 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java @@ -198,12 +198,7 @@ public class HttpClientUtil { * configuration (no additional configuration) is created. */ public static CloseableHttpClient createClient(SolrParams params) { - return createClient(params, createPoolingConnectionManager()); - } - - /** test usage subject to change @lucene.experimental */ - static PoolingHttpClientConnectionManager createPoolingConnectionManager() { - return new PoolingHttpClientConnectionManager(schemaRegistryProvider.getSchemaRegistry()); + return createClient(params, new PoolingHttpClientConnectionManager(schemaRegistryProvider.getSchemaRegistry())); } public static CloseableHttpClient createClient(SolrParams params, PoolingHttpClientConnectionManager cm) { @@ -401,25 +396,10 @@ public class HttpClientUtil { } /** - * @deprecated Use {@link #createNewHttpClientRequestContext(Object)} + * */ - @Deprecated public static HttpClientContext createNewHttpClientRequestContext() { - return httpClientRequestContextBuilder.createContext(null); - } - - /** - * Create a HttpClientContext object - * - * If the client is going to be re-used, then you should pass in an object that - * can be used by internal connection pools as a cache key. This is particularly - * important if client authentication is enabled, as SSL connections will not - * be re-used if no cache key is provided. - * - * @param cacheKey an Object to be used as a cache key for pooling connections - */ - public static HttpClientContext createNewHttpClientRequestContext(Object cacheKey) { - return httpClientRequestContextBuilder.createContext(cacheKey); + return httpClientRequestContextBuilder.createContext(); } public static Builder createDefaultRequestConfigBuilder() { diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java index d1f26b9b032..e43fd333ad8 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java @@ -47,7 +47,6 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.entity.ContentType; import org.apache.http.entity.InputStreamEntity; @@ -509,8 +508,7 @@ public class HttpSolrClient extends SolrClient { boolean shouldClose = true; try { // Execute the method. - HttpClientContext httpClientRequestContext = HttpClientUtil.createNewHttpClientRequestContext(this); - final HttpResponse response = httpClient.execute(method, httpClientRequestContext); + final HttpResponse response = httpClient.execute(method, HttpClientUtil.createNewHttpClientRequestContext()); int httpStatus = response.getStatusLine().getStatusCode(); // Read the contents diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientContextBuilder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientContextBuilder.java index f57848db1ed..b678df7ea19 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientContextBuilder.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientContextBuilder.java @@ -76,16 +76,8 @@ public class SolrHttpClientContextBuilder { public CredentialsProviderProvider getCredentialsProviderProvider() { return credentialsProviderProvider; } - - /** - * @deprecated use {@link #createContext(Object)} - */ - @Deprecated - public HttpClientContext createContext() { - return createContext(null); - } - public HttpClientContext createContext(Object userToken) { + public HttpClientContext createContext() { HttpClientContext context = new HttpClientContext(); if (getCredentialsProviderProvider() != null) { context.setCredentialsProvider(getCredentialsProviderProvider().getCredentialsProvider()); @@ -97,8 +89,6 @@ public class SolrHttpClientContextBuilder { if (getCookieSpecRegistryProvider() != null) { context.setCookieSpecRegistry(getCookieSpecRegistryProvider().getCookieSpecRegistry()); } - - context.setUserToken(userToken); return context; } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java index 1f5aa2b479e..d81667b3210 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java @@ -16,14 +16,6 @@ */ package org.apache.solr.client.solrj; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.OutputStreamWriter; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; - import org.apache.commons.io.FileUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -40,6 +32,14 @@ import org.apache.solr.util.ExternalPaths; import org.junit.BeforeClass; import org.junit.Test; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.OutputStreamWriter; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; + public class SolrSchemalessExampleTest extends SolrExampleTestsBase { @BeforeClass @@ -80,7 +80,7 @@ public class SolrSchemalessExampleTest extends SolrExampleTestsBase { HttpPost post = new HttpPost(client.getBaseURL() + "/update/json/docs"); post.setHeader("Content-Type", "application/json"); post.setEntity(new InputStreamEntity(new ByteArrayInputStream(json.getBytes("UTF-8")), -1)); - HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext(null)); + HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext()); Utils.consumeFully(response.getEntity()); assertEquals(200, response.getStatusLine().getStatusCode()); client.commit(); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java index 7af8d60c30b..6c13e40b77b 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java @@ -111,7 +111,7 @@ public class JettyWebappTest extends SolrTestCaseJ4 HttpClient client = HttpClients.createDefault(); HttpRequestBase m = new HttpGet(adminPath); - HttpResponse response = client.execute(m, HttpClientUtil.createNewHttpClientRequestContext(null)); + HttpResponse response = client.execute(m, HttpClientUtil.createNewHttpClientRequestContext()); assertEquals(200, response.getStatusLine().getStatusCode()); Header header = response.getFirstHeader("X-Frame-Options"); assertEquals("DENY", header.getValue().toUpperCase(Locale.ROOT)); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java index 89a0cef51bd..a8832e7d2a6 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java @@ -16,9 +16,6 @@ */ package org.apache.solr.client.solrj.embedded; -import java.io.ByteArrayInputStream; -import java.util.Map; - import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; @@ -35,6 +32,9 @@ import org.junit.BeforeClass; import org.junit.Test; import org.noggit.ObjectBuilder; +import java.io.ByteArrayInputStream; +import java.util.Map; + /** * TODO? perhaps use: * http://docs.codehaus.org/display/JETTY/ServletTester @@ -76,7 +76,7 @@ public class SolrExampleJettyTest extends SolrExampleTests { HttpPost post = new HttpPost(client.getBaseURL() + "/update/json/docs"); post.setHeader("Content-Type", "application/json"); post.setEntity(new InputStreamEntity(new ByteArrayInputStream(json.getBytes("UTF-8")), -1)); - HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext(null)); + HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext()); assertEquals(200, response.getStatusLine().getStatusCode()); client.commit(); QueryResponse rsp = getSolrClient().query(new SolrQuery("*:*")); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java index c1b0081e29c..11d2784d9ae 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java @@ -565,7 +565,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { CloseableHttpClient httpclient = HttpClientUtil.createClient(params); HttpEntity entity = null; try { - HttpResponse response = httpclient.execute(get, HttpClientUtil.createNewHttpClientRequestContext(null)); + HttpResponse response = httpclient.execute(get, HttpClientUtil.createNewHttpClientRequestContext()); entity = response.getEntity(); Header ceheader = entity.getContentEncoding(); assertNotNull(Arrays.asList(response.getAllHeaders()).toString(), ceheader); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientSSLAuthConPoolTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientSSLAuthConPoolTest.java deleted file mode 100644 index f2d5c65c928..00000000000 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientSSLAuthConPoolTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.client.solrj.impl; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.pool.PoolStats; -import org.apache.solr.SolrJettyTestBase; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.embedded.JettySolrRunner; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.util.RandomizeSSL; -import org.junit.AfterClass; -import org.junit.BeforeClass; - -@RandomizeSSL(1.0) -public class HttpSolrClientSSLAuthConPoolTest extends SolrJettyTestBase { - - private static JettySolrRunner yetty; - - @BeforeClass - public static void beforeTest() throws Exception { - createJetty(legacyExampleCollection1SolrHome()); - // stealing the first made jetty - yetty = jetty; - createJetty(legacyExampleCollection1SolrHome()); - } - - @AfterClass - public static void stopYetty() throws Exception { - yetty.stop(); - yetty = null; - } - - public void testPoolSize() throws SolrServerException, IOException { - PoolingHttpClientConnectionManager pool = HttpClientUtil.createPoolingConnectionManager(); - final HttpSolrClient client1 ; - final String fooUrl; - { - fooUrl = jetty.getBaseUrl().toString() + "/" + "collection1"; - CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams(), pool, - false /* let client shutdown it*/); - client1 = getHttpSolrClient(fooUrl, httpClient); - client1.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); - } - final String barUrl = yetty.getBaseUrl().toString() + "/" + "collection1"; - - List urls = new ArrayList<>(); - for(int i=0; i<17; i++) { - urls.add(fooUrl); - } - for(int i=0; i<31; i++) { - urls.add(barUrl); - } - - Collections.shuffle(urls, random()); - - try { - int i=0; - for (String url : urls) { - if (!client1.getBaseURL().equals(url)) { - client1.setBaseURL(url); - } - client1.add(new SolrInputDocument("id", ""+(i++))); - } - client1.setBaseURL(fooUrl); - client1.commit(); - assertEquals(17, client1.query(new SolrQuery("*:*")).getResults().getNumFound()); - - client1.setBaseURL(barUrl); - client1.commit(); - assertEquals(31, client1.query(new SolrQuery("*:*")).getResults().getNumFound()); - - PoolStats stats = pool.getTotalStats(); - assertEquals("oh "+stats, 2, stats.getAvailable()); - } finally { - for (HttpSolrClient c : new HttpSolrClient []{ client1}) { - HttpClientUtil.close(c.getHttpClient()); - c.close(); - } - } - } -} diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java index 6bf9c5653f0..3f2a699cae9 100644 --- a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java +++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java @@ -15,13 +15,6 @@ * limitations under the License. */ package org.apache.solr.util; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpressionException; -import java.io.Closeable; -import java.io.IOException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; - import org.apache.http.HttpEntity; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; @@ -35,6 +28,13 @@ import org.apache.http.util.EntityUtils; import org.apache.solr.client.solrj.impl.HttpClientUtil; import org.apache.solr.common.params.ModifiableSolrParams; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import java.io.Closeable; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + /** * Facilitates testing Solr's REST API via a provided embedded Jetty */ @@ -204,7 +204,7 @@ public class RestTestHarness extends BaseTestHarness implements Closeable { private String getResponse(HttpUriRequest request) throws IOException { HttpEntity entity = null; try { - entity = httpClient.execute(request, HttpClientUtil.createNewHttpClientRequestContext(this)).getEntity(); + entity = httpClient.execute(request, HttpClientUtil.createNewHttpClientRequestContext()).getEntity(); return EntityUtils.toString(entity, StandardCharsets.UTF_8); } finally { EntityUtils.consumeQuietly(entity);