You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Craig (Created) (JIRA)" <ji...@apache.org> on 2011/11/23 18:41:39 UTC
[jira] [Created] (HTTPCLIENT-1147) When HttpClient-Cache cannot
open cache file, should act like miss
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
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
[jira] [Commented] (HTTPCLIENT-1147) When HttpClient-Cache cannot
open cache file, should act like miss
Posted by "Joe Campbell (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1147?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13157631#comment-13157631 ]
Joe Campbell commented on HTTPCLIENT-1147:
------------------------------------------
So the attached patch should take care of this problem. The test has to be reworked a little bit - because right now it is doing external I/O (to get a URL resource) and some file based I/O (because of the directory configuration mentioned in this issue). I believe that there has to be an easier way to test this issue.
> 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.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
[jira] [Updated] (HTTPCLIENT-1147) When HttpClient-Cache cannot
open cache file, should act like miss
Posted by "Oleg Kalnichevski (Updated) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1147?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski updated HTTPCLIENT-1147:
------------------------------------------
Fix Version/s: 4.2 Alpha2
Jon, could you please look into that?
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.2 Alpha2
>
>
> 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
[jira] [Issue Comment Edited] (HTTPCLIENT-1147) When
HttpClient-Cache cannot open cache file, should act like miss
Posted by "Sebb (Issue Comment Edited) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1147?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13198859#comment-13198859 ]
Sebb edited comment on HTTPCLIENT-1147 at 2/2/12 4:38 PM:
----------------------------------------------------------
Adding a method to an interface does not break binary compatibility; however it will in general be source incompatible (unless all 3rd party implementation are subclasses of a base implementation that is also updated).
See http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html#45347
was (Author: sebb@apache.org):
Adding a method to an interface does not break binary compatibility; however it will in general be source incompatible (unless all 3rd party implementation are subclasses of a base implementation that is also updated).
See http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html#45347
[currently broken, but it was working a few months ago]
> 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 Beta1
>
> 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
[jira] [Commented] (HTTPCLIENT-1147) When HttpClient-Cache cannot
open cache file, should act like miss
Posted by "Oleg Kalnichevski (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1147?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13198695#comment-13198695 ]
Oleg Kalnichevski commented on HTTPCLIENT-1147:
-----------------------------------------------
I did a lousy job reviewing the patch. I missed the fact that the patch broke API compatibility by adding an additional method to the Resource interface.
I backed out those changes as they seem to have no impact on the resolution of the original issue. The test case testing the fix still pass for me even without API breaking changes.
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 Beta1
>
> 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
[jira] [Commented] (HTTPCLIENT-1147) When HttpClient-Cache cannot
open cache file, should act like miss
Posted by "Sebb (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1147?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13198859#comment-13198859 ]
Sebb commented on HTTPCLIENT-1147:
----------------------------------
Adding a method to an interface does not break binary compatibility; however it will in general be source incompatible (unless all 3rd party implementation are subclasses of a base implementation that is also updated).
See http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html#45347
[currently broken, but it was working a few months ago]
> 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 Beta1
>
> 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
[jira] [Updated] (HTTPCLIENT-1147) When HttpClient-Cache cannot
open cache file, should act like miss
Posted by "Joe Campbell (Updated) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1147?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Joe Campbell updated HTTPCLIENT-1147:
-------------------------------------
Attachment: issue_1147.patch
This patch is provided with permission of my employer with rights granted to the asf.
> 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.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
[jira] [Resolved] (HTTPCLIENT-1147) When HttpClient-Cache cannot
open cache file, should act like miss
Posted by "Oleg Kalnichevski (Resolved) (JIRA)" <ji...@apache.org>.
[ 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