Return-Path: X-Original-To: apmail-hc-dev-archive@www.apache.org Delivered-To: apmail-hc-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BCBE89647 for ; Fri, 2 Dec 2011 14:20:01 +0000 (UTC) Received: (qmail 13685 invoked by uid 500); 2 Dec 2011 14:20:01 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 13647 invoked by uid 500); 2 Dec 2011 14:20:01 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 13639 invoked by uid 99); 2 Dec 2011 14:20:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 14:20:01 +0000 X-ASF-Spam-Status: No, hits=-2001.2 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 14:20:00 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 6D707AF357 for ; Fri, 2 Dec 2011 14:19:40 +0000 (UTC) Date: Fri, 2 Dec 2011 14:19:40 +0000 (UTC) From: "Oleg Kalnichevski (Resolved) (JIRA)" To: dev@hc.apache.org Message-ID: <94155769.34967.1322835580449.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <329772301.6468.1322070099790.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Resolved] (HTTPCLIENT-1147) When HttpClient-Cache cannot open cache file, should act like miss MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1147?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Oleg Kalnichevski resolved HTTPCLIENT-1147. ------------------------------------------- Resolution: Fixed Fix Version/s: 4.1.3 Patch checked in to both trunk and 4.1.x branch. Please test. Joe, many thanks for contributing the patch. Oleg > When HttpClient-Cache cannot open cache file, should act like miss > ------------------------------------------------------------------ > > Key: HTTPCLIENT-1147 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1147 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: Cache > Affects Versions: 4.2 Alpha1 > Reporter: Craig > Fix For: 4.1.3, 4.2 Alpha2 > > Attachments: issue_1147.patch > > > Set up HttpClient-Cache like this: > final String cacheDir = "cachedir"; > HttpClient cachingHttpClient; > final CacheConfig cacheConfig = new CacheConfig(); > cacheConfig.setSharedCache(false); > cacheConfig.setMaxObjectSizeBytes(262144); //256kb > if(! new File(cacheDir, "httpclient-cache").exists()){ > if(!new File(cacheDir, "httpclient-cache").mkdir()){ > throw new RuntimeException("failed to create httpclient cache directory: " + new File(cacheDir, "httpclient-cache").getAbsolutePath()); > } > } > final ResourceFactory resourceFactory = new FileResourceFactory(new File(cacheDir, "httpclient-cache")); > final HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig); > cachingHttpClient = new CachingHttpClient(client, resourceFactory, httpCacheStorage, cacheConfig); > Then make a request: > final HttpGet get = new HttpGet(url); > final HttpResponse response = cachingHttpClient.execute(get); > final StatusLine statusLine = response.getStatusLine(); > if (statusLine.getStatusCode() >= 300) { > if(statusLine.getStatusCode() == 404) > throw new NoResultException(); > throw new HttpResponseException(statusLine.getStatusCode(), > statusLine.getReasonPhrase()); > } > response.getEntity().getContent(); > Everything worked as expected. > Now delete the cache directory ("cachedir/httpclient-cache" in this example). > And make the same request again. > Actual: > Caused by: java.lang.IllegalStateException: Content has been consumed > at org.apache.http.entity.BasicHttpEntity.getContent(BasicHttpEntity.java:84) > at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:100) > Expected: > HttpClient shouldn't throw an exception - it should just perform the request again acting like a cache miss. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org