Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-6625: Remove the HttpContext which provides our request

Noble Paul40e2cded267b
diff --git a/solr/core/src/java/org/apache/solr/request/SolrQueryRequestContext.java b/solr/core/src/java/org/apache/solr/request/SolrQueryRequestContext.java
deleted file mode 100644
index e1473376bc8..00000000000
--- a/solr/core/src/java/org/apache/solr/request/SolrQueryRequestContext.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.apache.solr.request;
-
-
-import org.apache.solr.client.solrj.impl.SolrHttpContext;
-
-/*
- * 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.
- */
-
-/**
- * A HttpContext derivative to encapsulate a server-side SolrQueryRequest
- * object.
- */
-public class SolrQueryRequestContext extends SolrHttpContext {
- final private SolrQueryRequest solrQueryRequest;
-
- public SolrQueryRequestContext(SolrQueryRequest solrQueryRequest) {
- this.solrQueryRequest = solrQueryRequest;
- setAttribute(SolrHttpContext.class.getName(), this);
- }
-
- public SolrQueryRequest getSolrQueryRequest() {
- return solrQueryRequest;
- }
-
- @Override
- public String toString() {
- return "[SolrQueryRequestContext contains: " + solrQueryRequest + "]";
- }
-}
-
-
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
index 1e1481fa772..208755db333 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -52,7 +52,6 @@ import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.security.AuthenticationPlugin;
-import org.apache.solr.util.SolrHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -94,8 +93,6 @@ public class SolrDispatchFilter extends BaseSolrFilter {
{
log.info("SolrDispatchFilter.init(): {}", this.getClass().getClassLoader());
- HttpClientUtil.HttpClientFactory.setHttpClientImpl(SolrHttpClient.SolrDefaultHttpClient.class, SolrHttpClient.SolrSystemDefaultHttpClient.class);
-
String exclude = config.getInitParameter("excludePatterns");
if(exclude != null) {
String[] excludeArray = exclude.split(",");
diff --git a/solr/core/src/java/org/apache/solr/util/SolrHttpClient.java b/solr/core/src/java/org/apache/solr/util/SolrHttpClient.java
deleted file mode 100644
index 2222a2229ef..00000000000
--- a/solr/core/src/java/org/apache/solr/util/SolrHttpClient.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.apache.solr.util;
-
-import java.io.IOException;
-
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.client.SystemDefaultHttpClient;
-import org.apache.http.protocol.HttpContext;
-import org.apache.solr.client.solrj.impl.SolrHttpContext;
-import org.apache.solr.request.SolrQueryRequestContext;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestInfo;
-
-/*
- * 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.
- */
-
-public class SolrHttpClient {
-
- private static HttpContext getHttpContext() {
- SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
- SolrQueryRequest request = requestInfo == null ? null : requestInfo.getReq();
- return request == null ? SolrHttpContext.EMPTY_CONTEXT: new SolrQueryRequestContext(request);
- }
-
- public static class SolrSystemDefaultHttpClient extends SystemDefaultHttpClient {
-
- public SolrSystemDefaultHttpClient() {
- super();
- }
-
- @Override
- public CloseableHttpResponse execute(HttpUriRequest request)
- throws IOException {
- return super.execute(request, getHttpContext());
- }
-
- @Override
- public CloseableHttpResponse execute(HttpHost target, HttpRequest request)
- throws IOException, ClientProtocolException {
- return super.execute(target, request, getHttpContext());
- }
-
- @Override
- public <T> T execute(HttpUriRequest request,
- ResponseHandler<? extends T> responseHandler) throws IOException,
- ClientProtocolException {
- return super.execute(request, responseHandler, getHttpContext());
- }
- }
-
- public static class SolrDefaultHttpClient extends DefaultHttpClient {
-
- public SolrDefaultHttpClient(ClientConnectionManager cm) {
- super(cm);
- }
-
- @Override
- public CloseableHttpResponse execute(HttpUriRequest request)
- throws IOException {
- return super.execute(request, getHttpContext());
- }
-
- @Override
- public CloseableHttpResponse execute(HttpHost target, HttpRequest request)
- throws IOException, ClientProtocolException {
- return super.execute(target, request, getHttpContext());
- }
-
- @Override
- public <T> T execute(HttpUriRequest request,
- ResponseHandler<? extends T> responseHandler) throws IOException,
- ClientProtocolException {
- return super.execute(request, responseHandler, getHttpContext());
- }
- }
-}
-
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientConfigurer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientConfigurer.java
index a3a8fecf426..67eeadff938 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientConfigurer.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientConfigurer.java
@@ -81,18 +81,6 @@ public class HttpClientConfigurer {
if(sslCheckPeerName == false) {
HttpClientUtil.setHostNameVerifier(httpClient, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
-
- // Intercept every request made through httpclient and validate it has a SolrHttpContext object.
- httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
- @Override
- public void process(final HttpRequest request, final HttpContext context) {
- // Verify that a context object was passed in
- final Object solrContext = context.getAttribute(SolrHttpContext.SOLR_CONTEXT_KEY);
- if (solrContext == null || solrContext instanceof SolrHttpContext == false) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "A SolrHttpContext object must be passed in as context. Context: " + context);
- }
- }
- });
}
public static boolean toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull) {
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpContext.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpContext.java
deleted file mode 100644
index c2f9893ec86..00000000000
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpContext.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.apache.solr.client.solrj.impl;
-
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.protocol.HttpContext;
-import org.apache.solr.client.solrj.SolrRequest;
-
-/*
- * 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.
- */
-
-/**
- * A HttpContext derivative to encapsulate a client-side SolrRequest
- * object.
- */
-public class SolrHttpContext extends HttpClientContext {
- final protected static String SOLR_CONTEXT_KEY = "solr.context";
-
- private SolrRequest solrRequest;
-
- public static HttpContext EMPTY_CONTEXT = new SolrHttpContext();
-
- protected SolrHttpContext() {
- setAttribute(SOLR_CONTEXT_KEY, this);
- }
-
- public SolrHttpContext(SolrRequest request) {
- this.solrRequest = request;
- setAttribute(SOLR_CONTEXT_KEY, this);
- }
-
- public SolrRequest getSolrRequest() {
- return solrRequest;
- }
-
- @Override
- public String toString() {
- return "[SolrHttpContext contains: "+solrRequest+"]";
- }
-}
diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
index 414b39d8e08..89a12ea1315 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -39,7 +39,6 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.util.DateFormatUtil;
-import org.apache.solr.util.SolrHttpClient;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -104,8 +103,6 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
public static void initialize() {
assumeFalse("SOLR-4147: ibm 64bit has jvm bugs!", Constants.JRE_IS_64BIT && Constants.JAVA_VENDOR.startsWith("IBM"));
r = new Random(random().nextLong());
-
- HttpClientUtil.HttpClientFactory.setHttpClientImpl(SolrHttpClient.SolrDefaultHttpClient.class, SolrHttpClient.SolrSystemDefaultHttpClient.class);
}
/**
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
index 9903aa60a66..8141f253975 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
@@ -26,7 +26,6 @@ import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.util.ExternalPaths;
-import org.apache.solr.util.SolrHttpClient;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -44,10 +43,6 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
{
private static Logger log = LoggerFactory.getLogger(SolrJettyTestBase.class);
- static {
- HttpClientUtil.HttpClientFactory.setHttpClientImpl(SolrHttpClient.SolrDefaultHttpClient.class, SolrHttpClient.SolrSystemDefaultHttpClient.class);
- }
-
@BeforeClass
public static void beforeSolrJettyTestBase() throws Exception {
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 3830bfe760b..ac62d6f01b7 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -100,7 +100,6 @@ import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.util.DateFormatUtil;
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
import org.apache.solr.util.SSLTestConfig;
-import org.apache.solr.util.SolrHttpClient;
import org.apache.solr.util.TestHarness;
import org.apache.zookeeper.KeeperException;
import org.junit.AfterClass;
@@ -141,10 +140,6 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
public static int DEFAULT_CONNECTION_TIMEOUT = 60000; // default socket connection timeout in ms
- static {
- HttpClientUtil.HttpClientFactory.setHttpClientImpl(SolrHttpClient.SolrDefaultHttpClient.class, SolrHttpClient.SolrSystemDefaultHttpClient.class);
- }
-
protected void writeCoreProperties(Path coreDirectory, String corename) throws IOException {
Properties props = new Properties();
props.setProperty("name", corename);
diff --git a/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
index 853e3789dff..ba0a460fc54 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
@@ -40,10 +40,6 @@ abstract public class BaseTestHarness {
private static final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<>();
private static final ThreadLocal<XPath> xpathTL = new ThreadLocal<>();
- static {
- HttpClientUtil.HttpClientFactory.setHttpClientImpl(SolrHttpClient.SolrDefaultHttpClient.class, SolrHttpClient.SolrSystemDefaultHttpClient.class);
- }
-
public static DocumentBuilder getXmlDocumentBuilder() {
try {
DocumentBuilder builder = builderTL.get();