hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1758106 - /httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java
Date Sun, 28 Aug 2016 13:02:35 GMT
Author: olegk
Date: Sun Aug 28 13:02:35 2016
New Revision: 1758106

URL: http://svn.apache.org/viewvc?rev=1758106&view=rev
Log:
Support changing system default ProxySelector
Contributed by Robin Stevens <stevensro at gmail.com>

The `ProxySelectorRoutePlanner` class which got deprecated in favor of the `SystemDefaultRoutePlanner`
could deal with:
- `null` as default `ProxySelector`
- a change in the default `ProxySelector`

This change ports that behavior to the `SystemDefaultRoutePlanner`.

Modified:
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java?rev=1758106&r1=1758105&r2=1758106&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java
Sun Aug 28 13:02:35 2016
@@ -54,13 +54,19 @@ public class SystemDefaultRoutePlanner e
 
     private final ProxySelector proxySelector;
 
+    /**
+     * @param proxySelector the proxy selector, or {@code null} for the system default
+     */
     public SystemDefaultRoutePlanner(
             final SchemePortResolver schemePortResolver,
             final ProxySelector proxySelector) {
         super(schemePortResolver);
-        this.proxySelector = proxySelector != null ? proxySelector : ProxySelector.getDefault();
+        this.proxySelector = proxySelector;
     }
 
+    /**
+     * @param proxySelector the proxy selector, or {@code null} for the system default
+     */
     public SystemDefaultRoutePlanner(final ProxySelector proxySelector) {
         this(null, proxySelector);
     }
@@ -76,7 +82,15 @@ public class SystemDefaultRoutePlanner e
         } catch (final URISyntaxException ex) {
             throw new HttpException("Cannot convert host to URI: " + target, ex);
         }
-        final List<Proxy> proxies = this.proxySelector.select(targetURI);
+        ProxySelector proxySelectorInstance = this.proxySelector;
+        if (proxySelectorInstance == null) {
+            proxySelectorInstance = ProxySelector.getDefault();
+        }
+        if (proxySelectorInstance == null) {
+            //The proxy selector can be "unset", so we must be able to deal with a null selector
+            return null;
+        }
+        final List<Proxy> proxies = proxySelectorInstance.select(targetURI);
         final Proxy p = chooseProxy(proxies);
         HttpHost result = null;
         if (p.type() == Proxy.Type.HTTP) {



Mime
View raw message