SOLR-6625: Remove the HttpContext which provides our request

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1693931 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2015-08-03 16:23:01 +00:00
parent bf853057ce
commit 40e2cded26
9 changed files with 0 additions and 226 deletions

View File

@ -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 + "]";
}
}

View File

@ -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(",");

View File

@ -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());
}
}
}

View File

@ -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) {

View File

@ -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+"]";
}
}

View File

@ -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);
}
/**

View File

@ -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 {

View File

@ -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);

View File

@ -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();