hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1681815 - /httpcomponents/httpclient/branches/4.5.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
Date Tue, 26 May 2015 18:59:47 GMT
Author: olegk
Date: Tue May 26 18:59:46 2015
New Revision: 1681815

URL: http://svn.apache.org/r1681815
Log:
HTTPCLIENT-1650: fluent Executor to create a local CredentialsProvide instance only if credentials
are explicitly set

Modified:
    httpcomponents/httpclient/branches/4.5.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java

Modified: httpcomponents/httpclient/branches/4.5.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java?rev=1681815&r1=1681814&r2=1681815&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
Tue May 26 18:59:46 2015
@@ -111,19 +111,28 @@ public class Executor {
     }
 
     private final HttpClient httpclient;
-    private final AuthCache authCache;
-    private final CredentialsProvider credentialsProvider;
-
+    private volatile AuthCache authCache;
+    private volatile CredentialsProvider credentialsProvider;
     private volatile CookieStore cookieStore;
 
     Executor(final HttpClient httpclient) {
         super();
         this.httpclient = httpclient;
-        this.credentialsProvider = new BasicCredentialsProvider();
         this.authCache = new BasicAuthCache();
     }
 
+    /**
+     * @since 4.5
+     */
+    public Executor use(final CredentialsProvider credentialsProvider) {
+        this.credentialsProvider = credentialsProvider;
+        return this;
+    }
+
     public Executor auth(final AuthScope authScope, final Credentials creds) {
+        if (this.credentialsProvider == null) {
+            this.credentialsProvider = new BasicCredentialsProvider();
+        }
         this.credentialsProvider.setCredentials(authScope, creds);
         return this;
     }
@@ -200,17 +209,33 @@ public class Executor {
     }
 
     public Executor clearAuth() {
-        this.credentialsProvider.clear();
+        if (this.credentialsProvider != null) {
+            this.credentialsProvider.clear();
+        }
         return this;
     }
 
+    /**
+     * @deprecated (4.5) Use {@link #use(CookieStore)}.
+     */
+    @Deprecated
     public Executor cookieStore(final CookieStore cookieStore) {
         this.cookieStore = cookieStore;
         return this;
     }
 
+    /**
+     * @since 4.5
+     */
+    public Executor use(final CookieStore cookieStore) {
+        this.cookieStore = cookieStore;
+        return this;
+    }
+
     public Executor clearCookies() {
-        this.cookieStore.clear();
+        if (this.cookieStore != null) {
+            this.cookieStore.clear();
+        }
         return this;
     }
 
@@ -225,9 +250,15 @@ public class Executor {
     public Response execute(
             final Request request) throws ClientProtocolException, IOException {
         final HttpClientContext localContext = HttpClientContext.create();
-        localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
-        localContext.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache);
-        localContext.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
+        if (this.credentialsProvider != null) {
+            localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
+        }
+        if (this.authCache != null) {
+            localContext.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache);
+        }
+        if (this.cookieStore != null) {
+            localContext.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
+        }
         return new Response(request.internalExecute(this.httpclient, localContext));
     }
 



Mime
View raw message