lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject [1/3] lucene-solr:master: SOLR-4509: Move to non deprecated HttpClient impl classes to remove stale connection check on every request and move connection lifecycle management towards the client.
Date Fri, 01 Apr 2016 16:46:03 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 3f217aba6 -> ce172acb8


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
----------------------------------------------------------------------
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 fe44597..29a56a6 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
@@ -16,6 +16,24 @@
  */
 package org.apache.solr.client.solrj.impl;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.invoke.MethodHandles;
+import java.net.ConnectException;
+import java.net.SocketTimeoutException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -23,6 +41,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.NameValuePair;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig.Builder;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
 import org.apache.http.client.methods.HttpGet;
@@ -30,15 +49,15 @@ 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.conn.ClientConnectionManager;
+import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.mime.FormBodyPart;
 import org.apache.http.entity.mime.HttpMultipartMode;
 import org.apache.http.entity.mime.MultipartEntity;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
 import org.apache.http.entity.mime.content.InputStreamBody;
 import org.apache.http.entity.mime.content.StringBody;
-import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.util.EntityUtils;
@@ -61,24 +80,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.lang.invoke.MethodHandles;
-import java.net.ConnectException;
-import java.net.SocketTimeoutException;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
 /**
  * A SolrClient implementation that talks directly to a Solr server via HTTP
  *
@@ -145,13 +146,15 @@ public class HttpSolrClient extends SolrClient {
   
   private final HttpClient httpClient;
   
-  private volatile boolean followRedirects = false;
+  private volatile Boolean followRedirects = false;
   
   private volatile boolean useMultiPartPost;
   private final boolean internalClient;
 
   private volatile Set<String> queryParams = Collections.emptySet();
-
+  private volatile Integer connectionTimeout;
+  private volatile Integer soTimeout;
+  
   /**
    * @param baseURL
    *          The URL of the Solr server. For example, "
@@ -166,7 +169,12 @@ public class HttpSolrClient extends SolrClient {
     this(baseURL, client, new BinaryResponseParser());
   }
   
+  
   public HttpSolrClient(String baseURL, HttpClient client, ResponseParser parser) {
+    this(baseURL, client, parser, false);
+  }
+  
+  public HttpSolrClient(String baseURL, HttpClient client, ResponseParser parser, boolean allowCompression) {
     this.baseUrl = baseURL;
     if (baseUrl.endsWith("/")) {
       baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
@@ -183,9 +191,8 @@ public class HttpSolrClient extends SolrClient {
     } else {
       internalClient = true;
       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, followRedirects);
+      params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, allowCompression);
       httpClient = HttpClientUtil.createClient(params);
     }
     
@@ -344,6 +351,7 @@ public class HttpSolrClient extends SolrClient {
       if (streams != null) {
         throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "GET can't send streams!");
       }
+
       return new HttpGet(basePath + path + wparams.toQueryString());
     }
 
@@ -370,6 +378,7 @@ public class HttpSolrClient extends SolrClient {
         String fullQueryUrl = url + queryParams.toQueryString();
         HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST == request.getMethod() ?
             new HttpPost(fullQueryUrl) : new HttpPut(fullQueryUrl);
+
         if (!isMultipart) {
           postOrPut.addHeader("Content-Type",
               "application/x-www-form-urlencoded; charset=UTF-8");
@@ -391,6 +400,7 @@ public class HttpSolrClient extends SolrClient {
           }
         }
 
+        // TODO: remove deprecated - first simple attempt failed, see {@link MultipartEntityBuilder}
         if (isMultipart && streams != null) {
           for (ContentStream content : streams) {
             String contentType = content.getContentType();
@@ -473,13 +483,26 @@ public class HttpSolrClient extends SolrClient {
   
   protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException {
     method.addHeader("User-Agent", AGENT);
+ 
+    Builder requestConfigBuilder = HttpClientUtil.createDefaultRequestConfigBuilder();
+    if (soTimeout != null) {
+      requestConfigBuilder.setSocketTimeout(soTimeout);
+    }
+    if (connectionTimeout != null) {
+      requestConfigBuilder.setConnectTimeout(connectionTimeout);
+    }
+    if (followRedirects != null) {
+      requestConfigBuilder.setRedirectsEnabled(followRedirects);
+    }
+
+    method.setConfig(requestConfigBuilder.build());
     
     HttpEntity entity = null;
     InputStream respBody = null;
     boolean shouldClose = true;
     try {
       // Execute the method.
-      final HttpResponse response = httpClient.execute(method);
+      final HttpResponse response = httpClient.execute(method, HttpClientUtil.createNewHttpClientRequestContext());
       int httpStatus = response.getStatusLine().getStatusCode();
       
       // Read the contents
@@ -647,7 +670,7 @@ public class HttpSolrClient extends SolrClient {
    *          Timeout in milliseconds
    **/
   public void setConnectionTimeout(int timeout) {
-    HttpClientUtil.setConnectionTimeout(httpClient, timeout);
+    this.connectionTimeout = timeout;
   }
   
   /**
@@ -658,7 +681,7 @@ public class HttpSolrClient extends SolrClient {
    *          Timeout in milliseconds
    **/
   public void setSoTimeout(int timeout) {
-    HttpClientUtil.setSoTimeout(httpClient, timeout);
+    this.soTimeout = timeout;
   }
   
   /**
@@ -671,22 +694,6 @@ public class HttpSolrClient extends SolrClient {
    */
   public void setFollowRedirects(boolean followRedirects) {
     this.followRedirects = followRedirects;
-    HttpClientUtil.setFollowRedirects(httpClient,  followRedirects);
-  }
-  
-  /**
-   * Allow server-&gt;client communication to be compressed. Currently gzip and
-   * deflate are supported. If the server supports compression the response will
-   * be compressed. This method is only allowed if the http client is of type
-   * DefatulHttpClient.
-   */
-  public void setAllowCompression(boolean allowCompression) {
-    if (httpClient instanceof DefaultHttpClient) {
-      HttpClientUtil.setAllowCompression((DefaultHttpClient) httpClient, allowCompression);
-    } else {
-      throw new UnsupportedOperationException(
-          "HttpClient instance was not of type DefaultHttpClient");
-    }
   }
   
   public void setRequestWriter(RequestWriter requestWriter) {
@@ -694,7 +701,7 @@ public class HttpSolrClient extends SolrClient {
   }
   
   /**
-   * Close the {@link ClientConnectionManager} from the internal client.
+   * Close the {@link HttpClientConnectionManager} from the internal client.
    */
   @Override
   public void close() throws IOException {
@@ -702,33 +709,6 @@ public class HttpSolrClient extends SolrClient {
       HttpClientUtil.close(httpClient);
     }
   }
-
-  /**
-   * Set the maximum number of connections that can be open to a single host at
-   * any given time. If http client was created outside the operation is not
-   * allowed.
-   */
-  public void setDefaultMaxConnectionsPerHost(int max) {
-    if (internalClient) {
-      HttpClientUtil.setMaxConnectionsPerHost(httpClient, max);
-    } else {
-      throw new UnsupportedOperationException(
-          "Client was created outside of HttpSolrServer");
-    }
-  }
-  
-  /**
-   * Set the maximum number of connections that can be open at any given time.
-   * If http client was created outside the operation is not allowed.
-   */
-  public void setMaxTotalConnections(int max) {
-    if (internalClient) {
-      HttpClientUtil.setMaxConnections(httpClient, max);
-    } else {
-      throw new UnsupportedOperationException(
-          "Client was created outside of HttpSolrServer");
-    }
-  }
   
   public boolean isUseMultiPartPost() {
     return useMultiPartPost;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientBuilder.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientBuilder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientBuilder.java
new file mode 100644
index 0000000..6c7c64f
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientBuilder.java
@@ -0,0 +1,192 @@
+/*
+ * 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.lang.invoke.MethodHandles;
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.cookie.CookieSpecProvider;
+import org.apache.http.entity.BufferedHttpEntity;
+import org.apache.http.impl.auth.SPNegoSchemeFactory;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.protocol.HttpContext;
+import org.apache.solr.client.solrj.impl.SolrHttpClientBuilder.AuthSchemeRegistryProvider;
+import org.apache.solr.client.solrj.impl.SolrHttpClientBuilder.CookieSpecRegistryProvider;
+import org.apache.solr.client.solrj.impl.SolrHttpClientBuilder.CredentialsProviderProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kerberos-enabled SolrHttpClientBuilder
+ */
+public class Krb5HttpClientBuilder  {
+  
+  public static final String LOGIN_CONFIG_PROP = "java.security.auth.login.config";
+  private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  
+  private static final Configuration jaasConfig = new SolrJaasConfiguration();
+
+  public Krb5HttpClientBuilder() {
+
+  }
+  
+  public SolrHttpClientBuilder getBuilder() {
+    return getBuilder(HttpClientUtil.getHttpClientBuilder());
+  }
+  
+  public void close() {
+    HttpClientUtil.removeRequestInterceptor(bufferedEntityInterceptor);
+  }
+  
+  public SolrHttpClientBuilder getBuilder(SolrHttpClientBuilder builder) {
+    if (System.getProperty(LOGIN_CONFIG_PROP) != null) {
+      String configValue = System.getProperty(LOGIN_CONFIG_PROP);
+
+      if (configValue != null) {
+        logger.info("Setting up SPNego auth with config: " + configValue);
+        final String useSubjectCredsProp = "javax.security.auth.useSubjectCredsOnly";
+        String useSubjectCredsVal = System.getProperty(useSubjectCredsProp);
+
+        // "javax.security.auth.useSubjectCredsOnly" should be false so that the underlying
+        // authentication mechanism can load the credentials from the JAAS configuration.
+        if (useSubjectCredsVal == null) {
+          System.setProperty(useSubjectCredsProp, "false");
+        }
+        else if (!useSubjectCredsVal.toLowerCase(Locale.ROOT).equals("false")) {
+          // Don't overwrite the prop value if it's already been written to something else,
+          // but log because it is likely the Credentials won't be loaded correctly.
+          logger.warn("System Property: " + useSubjectCredsProp + " set to: " + useSubjectCredsVal
+              + " not false.  SPNego authentication may not be successful.");
+        }
+
+        javax.security.auth.login.Configuration.setConfiguration(jaasConfig);
+        //Enable only SPNEGO authentication scheme.
+
+        builder.setAuthSchemeRegistryProvider(new AuthSchemeRegistryProvider() {
+          @Override
+          public Lookup<AuthSchemeProvider> getAuthSchemeRegistry() {
+            Lookup<AuthSchemeProvider> authProviders = RegistryBuilder.<AuthSchemeProvider>create()
+                .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, false))                
+                .build();
+            return authProviders;
+          }
+        });
+        // Get the credentials from the JAAS configuration rather than here
+        Credentials useJaasCreds = new Credentials() {
+          public String getPassword() {
+            return null;
+          }
+          public Principal getUserPrincipal() {
+            return null;
+          }
+        };
+        
+        HttpClientUtil.setCookiePolicy(SolrPortAwareCookieSpecFactory.POLICY_NAME);
+        
+        builder.setCookieSpecRegistryProvider(new CookieSpecRegistryProvider() {
+          @Override
+          public Lookup<CookieSpecProvider> getCookieSpecRegistry() {
+            SolrPortAwareCookieSpecFactory cookieFactory = new SolrPortAwareCookieSpecFactory();
+
+            Lookup<CookieSpecProvider> cookieRegistry = RegistryBuilder.<CookieSpecProvider> create()
+                .register(SolrPortAwareCookieSpecFactory.POLICY_NAME, cookieFactory).build();
+
+            return cookieRegistry;
+          }
+        });
+        
+        builder.setDefaultCredentialsProvider(new CredentialsProviderProvider() {
+          
+          @Override
+          public CredentialsProvider getCredentialsProvider() {
+            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+            credentialsProvider.setCredentials(AuthScope.ANY, useJaasCreds);
+            return credentialsProvider;
+          }
+        });
+        HttpClientUtil.addRequestInterceptor(bufferedEntityInterceptor);
+      }
+    }
+    
+    return builder;
+  }
+
+  // Set a buffered entity based request interceptor
+  private HttpRequestInterceptor bufferedEntityInterceptor = new HttpRequestInterceptor() {
+    @Override
+    public void process(HttpRequest request, HttpContext context) throws HttpException,
+        IOException {
+      if(request instanceof HttpEntityEnclosingRequest) {
+        HttpEntityEnclosingRequest enclosingRequest = ((HttpEntityEnclosingRequest) request);  
+        HttpEntity requestEntity = enclosingRequest.getEntity();
+        enclosingRequest.setEntity(new BufferedHttpEntity(requestEntity));
+      }
+    }
+  };
+
+  private static class SolrJaasConfiguration extends javax.security.auth.login.Configuration {
+
+    private javax.security.auth.login.Configuration baseConfig;
+
+    // the com.sun.security.jgss appNames
+    private Set<String> initiateAppNames = new HashSet(
+      Arrays.asList("com.sun.security.jgss.krb5.initiate", "com.sun.security.jgss.initiate"));
+
+    public SolrJaasConfiguration() {
+      try {
+        
+        this.baseConfig = javax.security.auth.login.Configuration.getConfiguration();
+      } catch (SecurityException e) {
+        this.baseConfig = null;
+      }
+    }
+
+    @Override
+    public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
+      if (baseConfig == null) return null;
+
+      logger.debug("Login prop: "+System.getProperty(LOGIN_CONFIG_PROP));
+
+      String clientAppName = System.getProperty("solr.kerberos.jaas.appname", "Client");
+      if (initiateAppNames.contains(appName)) {
+        logger.debug("Using AppConfigurationEntry for appName '"+clientAppName+"' instead of: " + appName);
+        return baseConfig.getAppConfigurationEntry(clientAppName);
+      }
+      return baseConfig.getAppConfigurationEntry(appName);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java
deleted file mode 100644
index 8b2705b..0000000
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java
+++ /dev/null
@@ -1,153 +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.lang.invoke.MethodHandles;
-import java.security.Principal;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Set;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.AuthSchemeRegistry;
-import org.apache.http.impl.auth.SPNegoSchemeFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.client.config.AuthSchemes;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.solr.common.params.SolrParams;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.http.entity.BufferedHttpEntity;
-
-/**
- * Kerberos-enabled HttpClientConfigurer
- */
-public class Krb5HttpClientConfigurer extends HttpClientConfigurer {
-  
-  public static final String LOGIN_CONFIG_PROP = "java.security.auth.login.config";
-  private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-  
-  private static final Configuration jaasConfig = new SolrJaasConfiguration();
-
-  public void configure(DefaultHttpClient httpClient, SolrParams config) {
-    super.configure(httpClient, config);
-
-    if (System.getProperty(LOGIN_CONFIG_PROP) != null) {
-      String configValue = System.getProperty(LOGIN_CONFIG_PROP);
-
-      if (configValue != null) {
-        logger.info("Setting up SPNego auth with config: " + configValue);
-        final String useSubjectCredsProp = "javax.security.auth.useSubjectCredsOnly";
-        String useSubjectCredsVal = System.getProperty(useSubjectCredsProp);
-
-        // "javax.security.auth.useSubjectCredsOnly" should be false so that the underlying
-        // authentication mechanism can load the credentials from the JAAS configuration.
-        if (useSubjectCredsVal == null) {
-          System.setProperty(useSubjectCredsProp, "false");
-        }
-        else if (!useSubjectCredsVal.toLowerCase(Locale.ROOT).equals("false")) {
-          // Don't overwrite the prop value if it's already been written to something else,
-          // but log because it is likely the Credentials won't be loaded correctly.
-          logger.warn("System Property: " + useSubjectCredsProp + " set to: " + useSubjectCredsVal
-              + " not false.  SPNego authentication may not be successful.");
-        }
-
-        javax.security.auth.login.Configuration.setConfiguration(jaasConfig);
-        //Enable only SPNEGO authentication scheme.
-        AuthSchemeRegistry registry = new AuthSchemeRegistry();
-        registry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, false));
-        httpClient.setAuthSchemes(registry);
-        // Get the credentials from the JAAS configuration rather than here
-        Credentials useJaasCreds = new Credentials() {
-          public String getPassword() {
-            return null;
-          }
-          public Principal getUserPrincipal() {
-            return null;
-          }
-        };
-
-        SolrPortAwareCookieSpecFactory cookieFactory = new SolrPortAwareCookieSpecFactory();
-        httpClient.getCookieSpecs().register(cookieFactory.POLICY_NAME, cookieFactory);
-        httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookieFactory.POLICY_NAME);
-        
-        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, useJaasCreds);
-
-        httpClient.addRequestInterceptor(bufferedEntityInterceptor);
-      } else {
-        httpClient.getCredentialsProvider().clear();
-      }
-    }
-  }
-
-  // Set a buffered entity based request interceptor
-  private HttpRequestInterceptor bufferedEntityInterceptor = new HttpRequestInterceptor() {
-    @Override
-    public void process(HttpRequest request, HttpContext context) throws HttpException,
-        IOException {
-      if(request instanceof HttpEntityEnclosingRequest) {
-        HttpEntityEnclosingRequest enclosingRequest = ((HttpEntityEnclosingRequest) request);  
-        HttpEntity requestEntity = enclosingRequest.getEntity();
-        enclosingRequest.setEntity(new BufferedHttpEntity(requestEntity));
-      }
-    }
-  };
-
-  private static class SolrJaasConfiguration extends javax.security.auth.login.Configuration {
-
-    private javax.security.auth.login.Configuration baseConfig;
-
-    // the com.sun.security.jgss appNames
-    private Set<String> initiateAppNames = new HashSet(
-      Arrays.asList("com.sun.security.jgss.krb5.initiate", "com.sun.security.jgss.initiate"));
-
-    public SolrJaasConfiguration() {
-      try {
-        
-        this.baseConfig = javax.security.auth.login.Configuration.getConfiguration();
-      } catch (SecurityException e) {
-        this.baseConfig = null;
-      }
-    }
-
-    @Override
-    public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
-      if (baseConfig == null) return null;
-
-      logger.debug("Login prop: "+System.getProperty(LOGIN_CONFIG_PROP));
-
-      String clientAppName = System.getProperty("solr.kerberos.jaas.appname", "Client");
-      if (initiateAppNames.contains(appName)) {
-        logger.debug("Using AppConfigurationEntry for appName '"+clientAppName+"' instead of: " + appName);
-        return baseConfig.getAppConfigurationEntry(clientAppName);
-      }
-      return baseConfig.getAppConfigurationEntry(appName);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
index 6d4711e..fabb933 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
@@ -109,6 +109,9 @@ public class LBHttpSolrClient extends SolrClient {
   private volatile RequestWriter requestWriter;
 
   private Set<String> queryParams = new HashSet<>();
+  private Integer connectionTimeout;
+
+  private Integer soTimeout;
 
   static {
     solrQuery.setRows(0);
@@ -261,6 +264,12 @@ public class LBHttpSolrClient extends SolrClient {
 
   protected HttpSolrClient makeSolrClient(String server) {
     HttpSolrClient client = new HttpSolrClient(server, httpClient, parser);
+    if (connectionTimeout != null) {
+      client.setConnectionTimeout(connectionTimeout);
+    }
+    if (soTimeout != null) {
+      client.setSoTimeout(soTimeout);
+    }
     if (requestWriter != null) {
       client.setRequestWriter(requestWriter);
     }
@@ -459,7 +468,17 @@ public class LBHttpSolrClient extends SolrClient {
   }
 
   public void setConnectionTimeout(int timeout) {
-    HttpClientUtil.setConnectionTimeout(httpClient, timeout);
+    this.connectionTimeout = timeout;
+    synchronized (aliveServers) {
+      Iterator<ServerWrapper> wrappersIt = aliveServers.values().iterator();
+      while (wrappersIt.hasNext()) {
+        wrappersIt.next().client.setConnectionTimeout(timeout);
+      }
+    }
+    Iterator<ServerWrapper> wrappersIt = zombieServers.values().iterator();
+    while (wrappersIt.hasNext()) {
+      wrappersIt.next().client.setConnectionTimeout(timeout);
+    }
   }
 
   /**
@@ -467,7 +486,17 @@ public class LBHttpSolrClient extends SolrClient {
    * not for indexing.
    */
   public void setSoTimeout(int timeout) {
-    HttpClientUtil.setSoTimeout(httpClient, timeout);
+    this.soTimeout = timeout;
+    synchronized (aliveServers) {
+      Iterator<ServerWrapper> wrappersIt = aliveServers.values().iterator();
+      while (wrappersIt.hasNext()) {
+        wrappersIt.next().client.setSoTimeout(timeout);
+      }
+    }
+    Iterator<ServerWrapper> wrappersIt = zombieServers.values().iterator();
+    while (wrappersIt.hasNext()) {
+      wrappersIt.next().client.setSoTimeout(timeout);
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientBuilder.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientBuilder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientBuilder.java
new file mode 100644
index 0000000..98217f8
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientBuilder.java
@@ -0,0 +1,91 @@
+/*
+ * 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 org.apache.http.HttpRequestInterceptor;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.config.Lookup;
+import org.apache.http.cookie.CookieSpecProvider;
+
+/**
+ * Builder class for configuring internal HttpClients. This
+ * relies on the internal HttpClient implementation and is subject to
+ * change.
+ * 
+ * @lucene.experimental
+ */
+public class SolrHttpClientBuilder {
+  public static SolrHttpClientBuilder create() {
+    return new SolrHttpClientBuilder();
+  }
+  
+  public interface HttpRequestInterceptorProvider {
+    public HttpRequestInterceptor getHttpRequestInterceptor();
+  }
+  
+  public interface CredentialsProviderProvider {
+    public CredentialsProvider getCredentialsProvider();
+  }
+  
+  public interface AuthSchemeRegistryProvider {
+    public Lookup<AuthSchemeProvider> getAuthSchemeRegistry();
+  }
+  
+  public interface CookieSpecRegistryProvider {
+    public Lookup<CookieSpecProvider> getCookieSpecRegistry();
+  }
+  
+  private CookieSpecRegistryProvider cookieSpecRegistryProvider;
+  private AuthSchemeRegistryProvider authSchemeRegistryProvider;
+  private CredentialsProviderProvider credentialsProviderProvider;
+
+  protected SolrHttpClientBuilder() {
+    super();
+  }
+
+  public final SolrHttpClientBuilder setCookieSpecRegistryProvider(
+      final CookieSpecRegistryProvider cookieSpecRegistryProvider) {
+    this.cookieSpecRegistryProvider = cookieSpecRegistryProvider;
+    return this;
+  }
+  
+  public final SolrHttpClientBuilder setDefaultCredentialsProvider(
+      final CredentialsProviderProvider credentialsProviderProvider) {
+    this.credentialsProviderProvider = credentialsProviderProvider;
+    return this;
+  }
+  
+  public final SolrHttpClientBuilder setAuthSchemeRegistryProvider(
+      final AuthSchemeRegistryProvider authSchemeRegistryProvider) {
+    this.authSchemeRegistryProvider = authSchemeRegistryProvider;
+    return this;
+  }
+
+  public AuthSchemeRegistryProvider getAuthSchemeRegistryProvider() {
+    return authSchemeRegistryProvider;
+  }
+
+  public CookieSpecRegistryProvider getCookieSpecRegistryProvider() {
+    return cookieSpecRegistryProvider;
+  }
+
+  public CredentialsProviderProvider getCredentialsProviderProvider() {
+    return credentialsProviderProvider;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientContextBuilder.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..b678df7
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpClientContextBuilder.java
@@ -0,0 +1,96 @@
+/*
+ * 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 org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Lookup;
+import org.apache.http.cookie.CookieSpecProvider;
+
+public class SolrHttpClientContextBuilder {
+  public static SolrHttpClientContextBuilder create() {
+    return new SolrHttpClientContextBuilder();
+  }
+  
+  public static abstract class CredentialsProviderProvider {
+    public abstract CredentialsProvider getCredentialsProvider();
+  }
+  
+  public static abstract class AuthSchemeRegistryProvider {
+    public abstract Lookup<AuthSchemeProvider> getAuthSchemeRegistry();
+  }
+  
+  public static abstract class CookieSpecRegistryProvider {
+    public abstract Lookup<CookieSpecProvider> getCookieSpecRegistry();
+  }
+  
+  private CookieSpecRegistryProvider cookieSpecRegistryProvider;
+  private AuthSchemeRegistryProvider authSchemeRegistryProvider;
+  private CredentialsProviderProvider credentialsProviderProvider;
+
+  public SolrHttpClientContextBuilder() {
+    super();
+  }
+
+  public final SolrHttpClientContextBuilder setCookieSpecRegistryProvider(
+      final CookieSpecRegistryProvider cookieSpecRegistryProvider) {
+    this.cookieSpecRegistryProvider = cookieSpecRegistryProvider;
+    return this;
+  }
+  
+  public final SolrHttpClientContextBuilder setDefaultCredentialsProvider(
+      final CredentialsProviderProvider credentialsProviderProvider) {
+    this.credentialsProviderProvider = credentialsProviderProvider;
+    return this;
+  }
+  
+  public final SolrHttpClientContextBuilder setAuthSchemeRegistryProvider(
+      final AuthSchemeRegistryProvider authSchemeRegistryProvider) {
+    this.authSchemeRegistryProvider = authSchemeRegistryProvider;
+    return this;
+  }
+
+  public AuthSchemeRegistryProvider getAuthSchemeRegistryProvider() {
+    return authSchemeRegistryProvider;
+  }
+
+  public CookieSpecRegistryProvider getCookieSpecRegistryProvider() {
+    return cookieSpecRegistryProvider;
+  }
+
+  public CredentialsProviderProvider getCredentialsProviderProvider() {
+    return credentialsProviderProvider;
+  }
+  
+  public HttpClientContext createContext() {
+    HttpClientContext context = new HttpClientContext();
+    if (getCredentialsProviderProvider() != null) {
+      context.setCredentialsProvider(getCredentialsProviderProvider().getCredentialsProvider());
+    }
+    if (getAuthSchemeRegistryProvider() != null) {
+      context.setAuthSchemeRegistry( getAuthSchemeRegistryProvider().getAuthSchemeRegistry());
+    }
+    
+    if (getCookieSpecRegistryProvider() != null) {
+      context.setCookieSpecRegistry(getCookieSpecRegistryProvider().getCookieSpecRegistry());
+    }
+    
+    return context;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test-files/log4j.properties
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test-files/log4j.properties b/solr/solrj/src/test-files/log4j.properties
index 9355270..dae4f6f 100644
--- a/solr/solrj/src/test-files/log4j.properties
+++ b/solr/solrj/src/test-files/log4j.properties
@@ -28,3 +28,5 @@ log4j.logger.org.apache.solr.hadoop=INFO
 
 #log4j.logger.org.apache.solr.common.cloud.ClusterStateUtil=DEBUG
 #log4j.logger.org.apache.solr.cloud.OverseerAutoReplicaFailoverThread=DEBUG
+
+# log4j.logger.org.apache.http.impl.conn.PoolingHttpClientConnectionManager=DEBUG
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
index 04807fe..1d70cd9 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
@@ -42,8 +42,6 @@ public class SolrExampleBinaryTest extends SolrExampleTests {
       String url = jetty.getBaseUrl().toString() + "/collection1";
       HttpSolrClient client = new HttpSolrClient( url );
       client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
-      client.setDefaultMaxConnectionsPerHost(100);
-      client.setMaxTotalConnections(100);
       client.setUseMultiPartPost(random().nextBoolean());
 
       // where the magic happens

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
index f1b77e4..338e449 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
@@ -40,8 +40,6 @@ public class SolrExampleXMLTest extends SolrExampleTests {
       HttpSolrClient client = new HttpSolrClient(url);
       client.setUseMultiPartPost(random().nextBoolean());
       client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
-      client.setDefaultMaxConnectionsPerHost(100);
-      client.setMaxTotalConnections(100);
       client.setParser(new XMLResponseParser());
       client.setRequestWriter(new RequestWriter());
       return client;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
index 75a030d..9fbaffb 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
@@ -38,10 +38,11 @@ public class SolrExceptionTest extends LuceneTestCase {
       // switched to a local address to avoid going out on the net, ns lookup issues, etc.
       // set a 1ms timeout to let the connection fail faster.
       httpClient = HttpClientUtil.createClient(null);
-      HttpClientUtil.setConnectionTimeout(httpClient,  1);
-      SolrClient client = new HttpSolrClient("http://[ff01::114]:11235/solr/", httpClient);
-      SolrQuery query = new SolrQuery("test123");
-      client.query(query);
+      try (HttpSolrClient client = new HttpSolrClient("http://[ff01::114]:11235/solr/", httpClient)) {
+        client.setConnectionTimeout(1);
+        SolrQuery query = new SolrQuery("test123");
+        client.query(query);
+      }
       httpClient.close();
     } catch (SolrServerException sse) {
       gotExpectedError = true;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
----------------------------------------------------------------------
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 dbef180..317d4cd 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
@@ -23,9 +23,11 @@ import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.solr.client.solrj.impl.BinaryRequestWriter;
 import org.apache.solr.client.solrj.impl.BinaryResponseParser;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.util.Utils;
 import org.apache.solr.util.ExternalPaths;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -79,7 +81,8 @@ 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);
+    HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext());
+    Utils.consumeFully(response.getEntity());
     assertEquals(200, response.getStatusLine().getStatusCode());
     client.commit();
     assertNumFound("*:*", 2);
@@ -133,8 +136,6 @@ public class SolrSchemalessExampleTest extends SolrExampleTestsBase {
       String url = jetty.getBaseUrl().toString() + "/collection1";
       HttpSolrClient client = new HttpSolrClient(url);
       client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
-      client.setDefaultMaxConnectionsPerHost(100);
-      client.setMaxTotalConnections(100);
       client.setUseMultiPartPost(random().nextBoolean());
       
       if (random().nextBoolean()) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java
index 5bebd64..70cd77d 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java
@@ -33,7 +33,6 @@ import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.client.solrj.response.SolrResponseBase;
 import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.util.TimeOut;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -92,7 +91,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {
   public void setUp() throws Exception {
     super.setUp();
     httpClient = HttpClientUtil.createClient(null);
-    HttpClientUtil.setConnectionTimeout(httpClient,  1000);
+
     for (int i = 0; i < solr.length; i++) {
       solr[i] = new SolrInstance("solr/collection1" + i, createTempDir("instance-" + i).toFile(), 0);
       solr[i].setUp();
@@ -125,7 +124,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {
         aSolr.tearDown();
       }
     }
-    httpClient.close();
+    HttpClientUtil.close(httpClient);
     super.tearDown();
   }
 
@@ -204,12 +203,12 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {
     for (int i = 0; i < solr.length; i++) {
       s[i] = solr[i].getUrl();
     }
-    ModifiableSolrParams params = new ModifiableSolrParams();
-    params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 250);
-    params.set(HttpClientUtil.PROP_SO_TIMEOUT, 250);
-    CloseableHttpClient myHttpClient = HttpClientUtil.createClient(params);
+
+    CloseableHttpClient myHttpClient = HttpClientUtil.createClient(null);
     try {
       LBHttpSolrClient client = new LBHttpSolrClient(myHttpClient, s);
+      client.setConnectionTimeout(250);
+      client.setSoTimeout(250);
       client.setAliveCheckInterval(500);
   
       // Kill a server and test again
@@ -225,7 +224,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {
       // Wait for the alive check to complete
       waitForServer(30, client, 3, "solr1");
     } finally {
-      myHttpClient.close();
+      HttpClientUtil.close(myHttpClient);
     }
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
----------------------------------------------------------------------
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 fa22f80..467b570 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
@@ -31,6 +31,7 @@ import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.solr.SolrJettyTestBase;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
 import org.apache.solr.util.ExternalPaths;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.HttpConnectionFactory;
@@ -108,7 +109,7 @@ public class JettyWebappTest extends SolrTestCaseJ4
 
     HttpClient client = HttpClients.createDefault();
     HttpRequestBase m = new HttpGet(adminPath);
-    HttpResponse response = client.execute(m);
+    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));

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
----------------------------------------------------------------------
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 0356196..d8347ce 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
@@ -23,6 +23,7 @@ import org.apache.http.entity.InputStreamEntity;
 import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
 import org.apache.solr.client.solrj.SolrExampleTests;
 import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.common.SolrDocument;
@@ -75,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);
+    HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext());
     assertEquals(200, response.getStatusLine().getStatusCode());
     client.commit();
     QueryResponse rsp = getSolrClient().query(new SolrQuery("*:*"));

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java
----------------------------------------------------------------------
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 2c7ac9d..ad20e95 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
@@ -16,15 +16,11 @@
  */
 package org.apache.solr.client.solrj.impl;
 
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.invoke.MethodHandles;
 import java.net.URISyntaxException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -35,6 +31,11 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
@@ -43,15 +44,14 @@ import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
 import org.apache.http.ParseException;
 import org.apache.http.client.CookieStore;
+import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.params.HttpClientParams;
-import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.methods.HttpRequestWrapper;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.cookie.CookieSpec;
-import org.apache.http.cookie.CookieSpecRegistry;
 import org.apache.http.impl.client.BasicCookieStore;
 import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.RequestWrapper;
 import org.apache.http.impl.cookie.BasicClientCookie;
 import org.apache.http.protocol.HttpContext;
 import org.apache.solr.SolrJettyTestBase;
@@ -68,6 +68,7 @@ import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SuppressForbidden;
 import org.apache.solr.util.SSLTestConfig;
@@ -524,49 +525,60 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
   
   @Test
   public void testCompression() throws Exception {
+    SolrQuery q = new SolrQuery("*:*");
+    
     try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) {
-      SolrQuery q = new SolrQuery("*:*");
-      
       // verify request header gets set
       DebugServlet.clear();
       try {
         client.query(q);
       } catch (ParseException ignored) {}
-      assertNull(DebugServlet.headers.get("Accept-Encoding"));
-      client.setAllowCompression(true);
+      assertNull(DebugServlet.headers.toString(), DebugServlet.headers.get("Accept-Encoding")); 
+    }
+    
+    try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo", null, null, true)) {
       try {
         client.query(q);
       } catch (ParseException ignored) {}
       assertNotNull(DebugServlet.headers.get("Accept-Encoding"));
-      client.setAllowCompression(false);
+    }
+    
+    try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo", null, null, false)) {
       try {
         client.query(q);
       } catch (ParseException ignored) {}
-      assertNull(DebugServlet.headers.get("Accept-Encoding"));
     }
+
+    assertNull(DebugServlet.headers.get("Accept-Encoding"));
     
     // verify server compresses output
     HttpGet get = new HttpGet(jetty.getBaseUrl().toString() + "/collection1" +
                               "/select?q=foo&wt=xml");
     get.setHeader("Accept-Encoding", "gzip");
-    CloseableHttpClient httpclient = HttpClientUtil.createClient(null);
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, true);
+    
+    RequestConfig config = RequestConfig.custom().setDecompressionEnabled(false).build();   
+    get.setConfig(config);
+    
+    CloseableHttpClient httpclient = HttpClientUtil.createClient(params);
     HttpEntity entity = null;
     try {
-      HttpResponse response = httpclient.execute(get);
+      HttpResponse response = httpclient.execute(get, HttpClientUtil.createNewHttpClientRequestContext());
       entity = response.getEntity();
       Header ceheader = entity.getContentEncoding();
+      assertNotNull(Arrays.asList(response.getAllHeaders()).toString(), ceheader);
       assertEquals("gzip", ceheader.getValue());
     } finally {
       if (entity != null) {
         entity.getContent().close();
       }
-      httpclient.close();
+      HttpClientUtil.close(httpclient);
     }
     
     // verify compressed response can be handled
     try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/collection1")) {
-      client.setAllowCompression(true);
-      SolrQuery q = new SolrQuery("foo");
+      q = new SolrQuery("foo");
       QueryResponse response = client.query(q);
       assertEquals(0, response.getStatus());
     }
@@ -589,28 +601,11 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
     }
 
   }
-  
-  @Test
-  public void testSetParametersExternalClient() throws IOException{
-
-    try (CloseableHttpClient httpClient = HttpClientUtil.createClient(null);
-         HttpSolrClient solrClient = new HttpSolrClient(jetty.getBaseUrl().toString(), httpClient)) {
-
-      try {
-        solrClient.setMaxTotalConnections(1);
-        fail("Operation should not succeed.");
-      } catch (UnsupportedOperationException ignored) {}
-      try {
-        solrClient.setDefaultMaxConnectionsPerHost(1);
-        fail("Operation should not succeed.");
-      } catch (UnsupportedOperationException ignored) {}
-
-    }
-  }
 
   @Test
   public void testGetRawStream() throws SolrServerException, IOException{
-    try (CloseableHttpClient client = HttpClientUtil.createClient(null)) {
+    CloseableHttpClient client = HttpClientUtil.createClient(null);
+    try {
       HttpSolrClient solrClient = new HttpSolrClient(jetty.getBaseUrl().toString() + "/collection1",
           client, null);
       QueryRequest req = new QueryRequest();
@@ -618,6 +613,8 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
       InputStream stream = (InputStream) response.get("stream");
       assertNotNull(stream);
       stream.close();
+    } finally {
+      HttpClientUtil.close(client);;
     }
   }
 
@@ -646,7 +643,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
     IOException {
       log.info("Intercepted params: "+context);
 
-      RequestWrapper wrapper = (RequestWrapper) request;
+      HttpRequestWrapper wrapper = (HttpRequestWrapper) request;
       URIBuilder uribuilder = new URIBuilder(wrapper.getURI());
       uribuilder.addParameter("b", "\u4321");
       try {
@@ -672,17 +669,15 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
       cookie.setPath("/");
       cookie.setDomain(jetty.getBaseUrl().getHost());
 
-      CookieStore cookieStore = new BasicCookieStore();        
-      CookieSpecRegistry registry = (CookieSpecRegistry) context.getAttribute(ClientContext.COOKIESPEC_REGISTRY);
-      String policy = HttpClientParams.getCookiePolicy(request.getParams());
-      CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
+      CookieStore cookieStore = new BasicCookieStore();
+      CookieSpec cookieSpec = new SolrPortAwareCookieSpecFactory().create(context);
+     // CookieSpec cookieSpec = registry.lookup(policy).create(context);
       // Add the cookies to the request
       List<Header> headers = cookieSpec.formatCookies(Collections.singletonList(cookie));
       for (Header header : headers) {
         request.addHeader(header);
       }
-      context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
-      context.setAttribute(ClientContext.COOKIE_SPEC, cookieSpec);
+      context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
     }
   };
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index 77d8d0f..8c50e8e 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -631,15 +631,13 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase {
   }
 
   public void customHttpClientTest() throws IOException {
-
-    ModifiableSolrParams params = new ModifiableSolrParams();
-    params.set(HttpClientUtil.PROP_SO_TIMEOUT, 1000);
-
-    try (CloseableHttpClient client = HttpClientUtil.createClient(params);
-         CloudSolrClient solrClient = new CloudSolrClient(zkServer.getZkAddress(), client)) {
+    CloseableHttpClient client = HttpClientUtil.createClient(null);
+    try (CloudSolrClient solrClient = new CloudSolrClient(zkServer.getZkAddress(), client)) {
 
       assertTrue(solrClient.getLbClient().getHttpClient() == client);
 
+    } finally {
+      HttpClientUtil.close(client);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ExternalHttpClientTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ExternalHttpClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ExternalHttpClientTest.java
deleted file mode 100644
index c788ae3..0000000
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ExternalHttpClientTest.java
+++ /dev/null
@@ -1,75 +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 org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.solr.SolrJettyTestBase;
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrQuery;
-import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.embedded.JettyConfig;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-@SolrTestCaseJ4.SuppressSSL
-public class ExternalHttpClientTest extends SolrJettyTestBase {
-  @BeforeClass
-  public static void beforeTest() throws Exception {
-    JettyConfig jettyConfig = JettyConfig.builder()
-        .withServlet(new ServletHolder(BasicHttpSolrClientTest.SlowServlet.class), "/slow/*")
-        .withSSLConfig(sslConfig)
-        .build();
-    createJetty(legacyExampleCollection1SolrHome(), jettyConfig);
-  }
-
-  /**
-   * The internal client created by HttpSolrClient is a SystemDefaultHttpClient
-   * which takes care of merging request level params (such as timeout) with the
-   * configured defaults.
-   *
-   * However, if an external HttpClient is passed to HttpSolrClient,
-   * the logic in InternalHttpClient.executeMethod replaces the configured defaults
-   * by request level params if they exist. That is why we must test a setting such
-   * as timeout with an external client to assert that the defaults are indeed being
-   * used
-   *
-   * See SOLR-6245 for more details
-   */
-  @Test
-  public void testTimeoutWithExternalClient() throws Exception {
-
-    HttpClientBuilder builder = HttpClientBuilder.create();
-    RequestConfig config = RequestConfig.custom().setSocketTimeout(2000).build();
-    builder.setDefaultRequestConfig(config);
-
-    try (CloseableHttpClient httpClient = builder.build();
-         HttpSolrClient solrClient = new HttpSolrClient(jetty.getBaseUrl().toString() + "/slow/foo", httpClient)) {
-
-      SolrQuery q = new SolrQuery("*:*");
-      try {
-        solrClient.query(q, SolrRequest.METHOD.GET);
-        fail("No exception thrown.");
-      } catch (SolrServerException e) {
-        assertTrue(e.getMessage().contains("Timeout"));
-      }
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClientUtilTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClientUtilTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClientUtilTest.java
deleted file mode 100644
index c881b7a..0000000
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClientUtilTest.java
+++ /dev/null
@@ -1,162 +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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.http.auth.AuthScope;
-import org.apache.http.client.config.AuthSchemes;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
-import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.conn.ssl.X509HostnameVerifier;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.AbstractHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.util.SSLTestConfig;
-import org.junit.Test;
-
-public class HttpClientUtilTest {
-
-  @Test
-  public void testNoParamsSucceeds() throws IOException {
-    CloseableHttpClient client = HttpClientUtil.createClient(null);
-    client.close();
-  }
-
-  @Test
-  public void testSetParams() {
-    ModifiableSolrParams params = new ModifiableSolrParams();
-    params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, true);
-    params.set(HttpClientUtil.PROP_BASIC_AUTH_PASS, "pass");
-    params.set(HttpClientUtil.PROP_BASIC_AUTH_USER, "user");
-    params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 12345);
-    params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, true);
-    params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 22345);
-    params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32345);
-    params.set(HttpClientUtil.PROP_SO_TIMEOUT, 42345);
-    params.set(HttpClientUtil.PROP_USE_RETRY, false);
-    DefaultHttpClient client = (DefaultHttpClient) HttpClientUtil.createClient(params);
-    try {
-      assertEquals(12345, HttpConnectionParams.getConnectionTimeout(client.getParams()));
-      assertEquals(PoolingClientConnectionManager.class, client.getConnectionManager().getClass());
-      assertEquals(22345, ((PoolingClientConnectionManager)client.getConnectionManager()).getMaxTotal());
-      assertEquals(32345, ((PoolingClientConnectionManager)client.getConnectionManager()).getDefaultMaxPerRoute());
-      assertEquals(42345, HttpConnectionParams.getSoTimeout(client.getParams()));
-      assertEquals(HttpClientUtil.NO_RETRY, client.getHttpRequestRetryHandler());
-      assertEquals("pass", client.getCredentialsProvider().getCredentials(new AuthScope("127.0.0.1", 1234)).getPassword());
-      assertEquals("user", client.getCredentialsProvider().getCredentials(new AuthScope("127.0.0.1", 1234)).getUserPrincipal().getName());
-      assertEquals(true, client.getParams().getParameter(ClientPNames.HANDLE_REDIRECTS));
-    } finally {
-      client.close();
-    }
-  }
-
-  @Test
-  public void testAuthSchemeConfiguration() {
-    System.setProperty(Krb5HttpClientConfigurer.LOGIN_CONFIG_PROP, "test");
-    try {
-      HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer());
-      AbstractHttpClient client = (AbstractHttpClient)HttpClientUtil.createClient(null);
-      assertEquals(1, client.getAuthSchemes().getSchemeNames().size());
-      assertTrue(AuthSchemes.SPNEGO.equalsIgnoreCase(client.getAuthSchemes().getSchemeNames().get(0)));
-    } finally {
-      //Cleanup the system property.
-      System.clearProperty(Krb5HttpClientConfigurer.LOGIN_CONFIG_PROP);
-    }
-  }
-
-  @Test
-  public void testReplaceConfigurer() throws IOException{
-    
-    try {
-    final AtomicInteger counter = new AtomicInteger();
-    HttpClientConfigurer custom = new HttpClientConfigurer(){
-      @Override
-      public void configure(DefaultHttpClient httpClient, SolrParams config) {
-        super.configure(httpClient, config);
-        counter.set(config.getInt("custom-param", -1));
-      }
-      
-    };
-    
-    HttpClientUtil.setConfigurer(custom);
-    
-    ModifiableSolrParams params = new ModifiableSolrParams();
-    params.set("custom-param", 5);
-    HttpClientUtil.createClient(params).close();
-    assertEquals(5, counter.get());
-    } finally {
-      //restore default configurer
-      HttpClientUtil.setConfigurer(new HttpClientConfigurer());
-    }
-
-  }
-  
-  @Test
-  @SuppressWarnings("deprecation")
-  public void testSSLSystemProperties() throws IOException {
-    CloseableHttpClient client = HttpClientUtil.createClient(null);
-    try {
-      SSLTestConfig.setSSLSystemProperties();
-      assertNotNull("HTTPS scheme could not be created using the javax.net.ssl.* system properties.", 
-          client.getConnectionManager().getSchemeRegistry().get("https"));
-      
-      System.clearProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
-      client.close();
-      client = HttpClientUtil.createClient(null);
-      assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(client).getClass());
-      
-      System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "true");
-      client.close();
-      client = HttpClientUtil.createClient(null);
-      assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(client).getClass());
-      
-      System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "");
-      client.close();
-      client = HttpClientUtil.createClient(null);
-      assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(client).getClass());
-      
-      System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "false");
-      client.close();
-      client = HttpClientUtil.createClient(null);
-      assertEquals(AllowAllHostnameVerifier.class, getHostnameVerifier(client).getClass());
-    } finally {
-      SSLTestConfig.clearSSLSystemProperties();
-      System.clearProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
-      client.close();
-    }
-  }
-  
-  @SuppressWarnings("deprecation")
-  private X509HostnameVerifier getHostnameVerifier(HttpClient client) {
-    return ((SSLSocketFactory) client.getConnectionManager().getSchemeRegistry()
-        .get("https").getSchemeSocketFactory()).getHostnameVerifier();
-  }
-  
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientTest.java
index dba18d0..94af2ca 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientTest.java
@@ -38,18 +38,23 @@ public class LBHttpSolrClientTest {
    */
   @Test
   public void testLBHttpSolrClientHttpClientResponseParserStringArray() throws IOException {
-
-    try (CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
+    CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
+    try (
          LBHttpSolrClient testClient = new LBHttpSolrClient(httpClient, (ResponseParser) null);
          HttpSolrClient httpSolrClient = testClient.makeSolrClient("http://127.0.0.1:8080")) {
       assertNull("Generated server should have null parser.", httpSolrClient.getParser());
+    } finally {
+      HttpClientUtil.close(httpClient);
     }
 
     ResponseParser parser = new BinaryResponseParser();
-    try (CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
-         LBHttpSolrClient testClient = new LBHttpSolrClient(httpClient, parser);
-         HttpSolrClient httpSolrClient = testClient.makeSolrClient("http://127.0.0.1:8080")) {
-      assertEquals("Invalid parser passed to generated server.", parser, httpSolrClient.getParser());
+    httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
+    try {
+      try ( LBHttpSolrClient testClient = new LBHttpSolrClient(httpClient, parser); HttpSolrClient httpSolrClient = testClient.makeSolrClient("http://127.0.0.1:8080")) {
+        assertEquals("Invalid parser passed to generated server.", parser, httpSolrClient.getParser());
+      }
+    } finally {
+      HttpClientUtil.close(httpClient);
     }
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
index 72051b1..be36bf3 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
@@ -105,12 +105,11 @@ public class SchemaTest extends RestTestBase {
   }
 
   @After
-  public void cleanup() throws Exception {
+  public void cleanup() throws Exception  {
     if (jetty != null) {
       jetty.stop();
       jetty = null;
     }
-    client = null;
     if (restTestHarness != null) {
       restTestHarness.close();
     }
@@ -424,7 +423,8 @@ public class SchemaTest extends RestTestBase {
     fieldAttributes.put("type", "string");
     SchemaRequest.AddDynamicField addDFieldUpdateSchemaRequest =
         new SchemaRequest.AddDynamicField(fieldAttributes);
-    SchemaResponse.UpdateResponse addDFieldFirstResponse = addDFieldUpdateSchemaRequest.process(getSolrClient());
+    SolrClient client = getSolrClient();
+    SchemaResponse.UpdateResponse addDFieldFirstResponse = addDFieldUpdateSchemaRequest.process(client);
     assertValidSchemaResponse(addDFieldFirstResponse);
 
     SchemaResponse.UpdateResponse addDFieldSecondResponse = addDFieldUpdateSchemaRequest.process(getSolrClient());
@@ -680,7 +680,8 @@ public class SchemaTest extends RestTestBase {
     fieldTypeDefinition.setAttributes(fieldTypeAttributes);
     SchemaRequest.AddFieldType addFieldTypeRequest =
         new SchemaRequest.AddFieldType(fieldTypeDefinition);
-    SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient());
+    SolrClient c = getSolrClient();
+    SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(c);
     assertValidSchemaResponse(addFieldTypeResponse);
 
     SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
----------------------------------------------------------------------
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 a751459..4ae46f8 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -229,9 +229,6 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
   protected boolean verifyStress = true;
   protected int nThreads = 3;
 
-  protected int clientConnectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
-  protected int clientSoTimeout = 90000;
-
   public static int ORDERED = 1;
   public static int SKIP = 2;
   public static int SKIPVAL = 4;
@@ -443,10 +440,6 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
     try {
       // setup the client...
       HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME);
-      client.setConnectionTimeout(clientConnectionTimeout);
-      client.setSoTimeout(clientSoTimeout);
-      client.setDefaultMaxConnectionsPerHost(100);
-      client.setMaxTotalConnections(100);
       return client;
     }
     catch (Exception ex) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
----------------------------------------------------------------------
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 0e77a47..5924593 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
@@ -22,10 +22,10 @@ import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
 import org.apache.solr.client.solrj.embedded.JettyConfig;
 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.eclipse.jetty.servlet.ServletHolder;
+import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.slf4j.Logger;
@@ -119,6 +119,11 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
     return jetty;
   }
 
+  @After
+  public void afterClass() throws Exception {
+    if (client != null) client.close();
+    client = null;
+  }
 
   @AfterClass
   public static void afterSolrJettyTestBase() throws Exception {
@@ -126,8 +131,6 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
       jetty.stop();
       jetty = null;
     }
-    if (client != null) client.close();
-    client = null;
   }
 
 
@@ -153,15 +156,18 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
         String url = jetty.getBaseUrl().toString() + "/" + "collection1";
         HttpSolrClient client = new HttpSolrClient( url );
         client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
-        client.setDefaultMaxConnectionsPerHost(100);
-        client.setMaxTotalConnections(100);
         return client;
       }
       catch( Exception ex ) {
         throw new RuntimeException( ex );
       }
     } else {
-      return new EmbeddedSolrServer( h.getCoreContainer(), "collection1" );
+      return new EmbeddedSolrServer( h.getCoreContainer(), "collection1" ) {
+        @Override
+        public void close() {
+          // do not close core container
+        }
+      };
     }
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
----------------------------------------------------------------------
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 3ce252f..6b28eb8 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -66,7 +66,6 @@ import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
 import org.apache.lucene.util.QuickPatchThreadsFilter;
 import org.apache.lucene.util.TestUtil;
 import org.apache.solr.client.solrj.embedded.JettyConfig;
-import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
 import org.apache.solr.client.solrj.impl.HttpClientUtil;
 import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.cloud.IpTables;
@@ -226,7 +225,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
     
     sslConfig = buildSSLConfig();
     //will use ssl specific or default depending on sslConfig
-    HttpClientUtil.setConfigurer(sslConfig.getHttpClientConfigurer());
+    HttpClientUtil.setHttpClientBuilder(sslConfig.getHttpClientBuilder());
     if(isSSLMode()) {
       // SolrCloud tests should usually clear this
       System.setProperty("urlScheme", "https");
@@ -269,9 +268,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
       System.clearProperty("useCompoundFile");
       System.clearProperty("urlScheme");
       
-      if (isSSLMode()) {
-        HttpClientUtil.setConfigurer(new HttpClientConfigurer());
-      }
+      HttpClientUtil.resetHttpClientBuilder();
 
       // clean up static
       sslConfig = null;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index a584dbd..090dfe8 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -1629,8 +1629,6 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
       HttpSolrClient client = new HttpSolrClient(url);
       client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
       client.setSoTimeout(60000);
-      client.setDefaultMaxConnectionsPerHost(100);
-      client.setMaxTotalConnections(100);
       return client;
     } catch (Exception ex) {
       throw new RuntimeException(ex);
@@ -1642,8 +1640,6 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
       // setup the server...
       HttpSolrClient client = new HttpSolrClient(baseUrl + "/" + collection);
       client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
-      client.setDefaultMaxConnectionsPerHost(100);
-      client.setMaxTotalConnections(100);
       return client;
     }
     catch (Exception ex) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
----------------------------------------------------------------------
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 de5f662..3f2a699 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
@@ -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).getEntity();
+      entity = httpClient.execute(request, HttpClientUtil.createNewHttpClientRequestContext()).getEntity();
       return EntityUtils.toString(entity, StandardCharsets.UTF_8);
     } finally {
       EntityUtils.consumeQuietly(entity);
@@ -213,6 +213,6 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
 
   @Override
   public void close() throws IOException {
-    httpClient.close();
+    HttpClientUtil.close(httpClient);
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce172acb/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
index 8d626dc..68c4b07 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
@@ -25,15 +25,21 @@ import java.security.UnrecoverableKeyException;
 
 import javax.net.ssl.SSLContext;
 
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.conn.ssl.SSLContexts;
 import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.solr.client.solrj.embedded.SSLConfig;
-import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
-import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.HttpClientUtil.SchemaRegistryProvider;
+import org.apache.solr.client.solrj.impl.SolrHttpClientBuilder;
 import org.eclipse.jetty.util.resource.Resource;
 import org.eclipse.jetty.util.security.CertificateUtils;
 
@@ -44,7 +50,6 @@ public class SSLTestConfig extends SSLConfig {
   private static String TEST_KEYSTORE_PATH = TEST_KEYSTORE != null
       && TEST_KEYSTORE.exists() ? TEST_KEYSTORE.getAbsolutePath() : null;
   private static String TEST_KEYSTORE_PASSWORD = "secret";
-  private static HttpClientConfigurer DEFAULT_CONFIGURER = new HttpClientConfigurer();
   
   public SSLTestConfig() {
     this(false, false);
@@ -59,12 +64,13 @@ public class SSLTestConfig extends SSLConfig {
   }
   
   /**
-   * Will provide an HttpClientConfigurer for SSL support (adds https and
+   * Will provide an SolrHttpClientBuilder for SSL support (adds https and
    * removes http schemes) is SSL is enabled, otherwise return the default
-   * configurer
+   * SolrHttpClientBuilder
    */
-  public HttpClientConfigurer getHttpClientConfigurer() {
-    return isSSLMode() ? new SSLHttpClientConfigurer() : DEFAULT_CONFIGURER;
+  public SolrHttpClientBuilder getHttpClientBuilder() {
+    SolrHttpClientBuilder builder = HttpClientUtil.getHttpClientBuilder();
+    return isSSLMode() ? new SSLHttpClientBuilderProvider().getBuilder(builder) : builder;
   }
 
   /**
@@ -88,20 +94,53 @@ public class SSLTestConfig extends SSLConfig {
     }
   }
   
-  private class SSLHttpClientConfigurer extends HttpClientConfigurer {
-    @SuppressWarnings("deprecation")
-    public void configure(DefaultHttpClient httpClient, SolrParams config) {
-      super.configure(httpClient, config);
-      SchemeRegistry registry = httpClient.getConnectionManager().getSchemeRegistry();
-      // Make sure no tests cheat by using HTTP
-      registry.unregister("http");
-      try {
-        registry.register(new Scheme("https", 443, new SSLSocketFactory(buildSSLContext())));
-      } catch (KeyManagementException | UnrecoverableKeyException
-          | NoSuchAlgorithmException | KeyStoreException ex) {
-        throw new IllegalStateException("Unable to setup https scheme for HTTPClient to test SSL.", ex);
-      }
+  private class SSLHttpClientBuilderProvider  {
+    
+
+    public SolrHttpClientBuilder getBuilder(SolrHttpClientBuilder builder) {
+
+      HttpClientUtil.setSchemeRegistryProvider(new SchemaRegistryProvider() {
+        
+        @Override
+        public Registry<ConnectionSocketFactory> getSchemaRegistry() {
+          SSLConnectionSocketFactory sslConnectionFactory;
+          try {
+            boolean sslCheckPeerName = toBooleanDefaultIfNull(
+                toBooleanObject(System.getProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME)), true);
+            if (sslCheckPeerName == false) {
+              sslConnectionFactory = new SSLConnectionSocketFactory(buildSSLContext(),
+                  SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+            } else {
+              sslConnectionFactory = new SSLConnectionSocketFactory(buildSSLContext());
+            }
+          } catch (KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
+            throw new IllegalStateException("Unable to setup https scheme for HTTPClient to test SSL.", e);
+          }
+          return  RegistryBuilder.<ConnectionSocketFactory>create()
+              .register("https", sslConnectionFactory).build();
+        }
+      });
+      HttpClientUtil.setHttpClientBuilder(builder);
+      return builder;
+    }
+
+  }
+  
+  public static boolean toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull) {
+    if (bool == null) {
+      return valueIfNull;
+    }
+    return bool.booleanValue() ? true : false;
+  }
+  
+  public static Boolean toBooleanObject(String str) {
+    if ("true".equalsIgnoreCase(str)) {
+      return Boolean.TRUE;
+    } else if ("false".equalsIgnoreCase(str)) {
+      return Boolean.FALSE;
     }
+    // no match
+    return null;
   }
   
   public static void setSSLSystemProperties() {


Mime
View raw message