hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1420121 - in /httpcomponents/httpclient/trunk: httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ httpclient/src/main/java/org/apache/http/impl/auth/ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/main/...
Date Tue, 11 Dec 2012 12:20:11 GMT
Author: olegk
Date: Tue Dec 11 12:20:08 2012
New Revision: 1420121

URL: http://svn.apache.org/viewvc?rev=1420121&view=rev
Log:
Added caching specific HttpClient builder

Added:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClients.java
      - copied, changed from r1419448, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java
Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java?rev=1420121&r1=1420120&r2=1420121&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
Tue Dec 11 12:20:08 2012
@@ -118,7 +118,7 @@ import org.apache.http.util.VersionInfo;
  * </p>
  * @since 4.1
  *
- * @deprecated (4.3)
+ * @deprecated (4.3) use {@link CachingHttpClientBuilder} or {@link CachingHttpClients}.
  */
 @Deprecated
 @ThreadSafe // So long as the responseCache implementation is threadsafe

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java?rev=1420121&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
Tue Dec 11 12:20:08 2012
@@ -0,0 +1,97 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.File;
+
+import org.apache.http.client.cache.HttpCacheStorage;
+import org.apache.http.client.cache.ResourceFactory;
+import org.apache.http.impl.client.builder.HttpClientBuilder;
+import org.apache.http.impl.client.execchain.ClientExecChain;
+
+/**
+ * @since (4.3)
+ */
+public class CachingHttpClientBuilder extends HttpClientBuilder {
+
+    private ResourceFactory resourceFactory;
+    private HttpCacheStorage storage;
+    private File cacheDir;
+    private CacheConfig cacheConfig;
+
+    public static CachingHttpClientBuilder create() {
+        return new CachingHttpClientBuilder();
+    }
+
+    protected CachingHttpClientBuilder() {
+        super();
+    }
+
+    public final CachingHttpClientBuilder setResourceFactory(
+            final ResourceFactory resourceFactory) {
+        this.resourceFactory = resourceFactory;
+        return this;
+    }
+
+    public final CachingHttpClientBuilder setHttpCacheStorage(
+            final HttpCacheStorage storage) {
+        this.storage = storage;
+        return this;
+    }
+
+    public final CachingHttpClientBuilder setCacheDir(
+            final File cacheDir) {
+        this.cacheDir = cacheDir;
+        return this;
+    }
+
+    public final CachingHttpClientBuilder setCacheConfig(
+            final CacheConfig cacheConfig) {
+        this.cacheConfig = cacheConfig;
+        return this;
+    }
+
+    @Override
+    protected ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
+        CacheConfig config = this.cacheConfig != null ? this.cacheConfig : CacheConfig.DEFAULT;
+        ResourceFactory resourceFactory = this.resourceFactory;
+        if (resourceFactory == null) {
+            if (this.cacheDir == null) {
+                resourceFactory = new HeapResourceFactory();
+            } else {
+                resourceFactory = new FileResourceFactory(cacheDir);
+            }
+        }
+        HttpCacheStorage storage = this.storage;
+        if (storage == null) {
+            storage = new BasicHttpCacheStorage(cacheConfig);
+        }
+        return new CachingExec(mainExec,
+                new BasicHttpCache(resourceFactory, storage, config), config);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClients.java
(from r1419448, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClients.java?p2=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClients.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java&r1=1419448&r2=1420121&rev=1420121&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClients.java
Tue Dec 11 12:20:08 2012
@@ -25,27 +25,33 @@
  *
  */
 
-package org.apache.http.impl.client;
+package org.apache.http.impl.client.cache;
+
+import java.io.File;
 
 import org.apache.http.annotation.Immutable;
-import org.apache.http.impl.client.builder.HttpClientBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
 
 /**
  * @since 4.3
  */
 @Immutable
-public class HttpClients {
+public class CachingHttpClients {
 
-    private HttpClients() {
+    private CachingHttpClients() {
         super();
     }
 
-    public static HttpClientBuilder custom() {
-        return HttpClientBuilder.create();
+    public static CachingHttpClientBuilder custom() {
+        return CachingHttpClientBuilder.create();
+    }
+
+    public static CloseableHttpClient createMemoryBound() {
+        return CachingHttpClientBuilder.create().build();
     }
 
-    public static CloseableHttpClient createDefault() {
-        return HttpClientBuilder.create().build();
+    public static CloseableHttpClient createFileBound(final File cacheDir) {
+        return CachingHttpClientBuilder.create().setCacheDir(cacheDir).build();
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java?rev=1420121&r1=1420120&r2=1420121&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
Tue Dec 11 12:20:08 2012
@@ -32,7 +32,6 @@ import java.util.Arrays;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
-import javax.crypto.Mac;
 
 import org.apache.commons.codec.binary.Base64;
 import org.apache.http.util.EncodingUtils;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java?rev=1420121&r1=1420120&r2=1420121&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java
Tue Dec 11 12:20:08 2012
@@ -48,4 +48,8 @@ public class HttpClients {
         return HttpClientBuilder.create().build();
     }
 
+    public static CloseableHttpClient createSystem() {
+        return HttpClientBuilder.create().useSystemProperties().build();
+    }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java?rev=1420121&r1=1420120&r2=1420121&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java
Tue Dec 11 12:20:08 2012
@@ -191,7 +191,7 @@ public class HttpClientBuilder {
         return new HttpClientBuilder();
     }
 
-    HttpClientBuilder() {
+    protected HttpClientBuilder() {
         super();
     }
 



Mime
View raw message