hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1545356 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
Date Mon, 25 Nov 2013 18:05:24 GMT
Author: olegk
Date: Mon Nov 25 18:05:24 2013
New Revision: 1545356

URL: http://svn.apache.org/r1545356
Log:
HTTPCLIENT-1437: Made Executor#execute thread safe

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1545356&r1=1545355&r2=1545356&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Mon Nov 25 18:05:24 2013
@@ -1,6 +1,9 @@
 Changes since 4.3.1
 -------------------
 
+* [HTTPCLIENT-1437] Made Executor#execute thread safe.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1119] SNI support (Oracle Java 1.7+ only).
   Contributed by Bruno Harbulot <bruno at distributedmatter.net>  
 

Modified: httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java?rev=1545356&r1=1545355&r2=1545356&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
(original)
+++ httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
Mon Nov 25 18:05:24 2013
@@ -59,7 +59,6 @@ import org.apache.http.impl.client.Basic
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.message.BasicHeader;
-import org.apache.http.protocol.BasicHttpContext;
 
 /**
  * An Executor for fluent requests
@@ -108,23 +107,19 @@ public class Executor {
     }
 
     private final HttpClient httpclient;
-    private final BasicHttpContext localContext;
     private final AuthCache authCache;
+    private final CredentialsProvider credentialsProvider;
 
-    private CredentialsProvider credentialsProvider;
-    private CookieStore cookieStore;
+    private volatile CookieStore cookieStore;
 
     Executor(final HttpClient httpclient) {
         super();
         this.httpclient = httpclient;
-        this.localContext = new BasicHttpContext();
+        this.credentialsProvider = new BasicCredentialsProvider();
         this.authCache = new BasicAuthCache();
     }
 
     public Executor auth(final AuthScope authScope, final Credentials creds) {
-        if (this.credentialsProvider == null) {
-            this.credentialsProvider = new BasicCredentialsProvider();
-        }
         this.credentialsProvider.setCredentials(authScope, creds);
         return this;
     }
@@ -179,9 +174,7 @@ public class Executor {
     }
 
     public Executor clearAuth() {
-        if (this.credentialsProvider != null) {
-            this.credentialsProvider.clear();
-        }
+        this.credentialsProvider.clear();
         return this;
     }
 
@@ -191,9 +184,7 @@ public class Executor {
     }
 
     public Executor clearCookies() {
-        if (this.cookieStore != null) {
-            this.cookieStore.clear();
-        }
+        this.cookieStore.clear();
         return this;
     }
 
@@ -207,12 +198,13 @@ public class Executor {
      */
     public Response execute(
             final Request request) throws ClientProtocolException, IOException {
-        this.localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
-        this.localContext.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache);
-        this.localContext.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
+        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);
         final HttpRequestBase httprequest = request.prepareRequest();
         httprequest.reset();
-        return new Response(this.httpclient.execute(httprequest, this.localContext));
+        return new Response(this.httpclient.execute(httprequest, localContext));
     }
 
     /**



Mime
View raw message