You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by pluenl <pl...@chello.at> on 2008/06/04 07:07:22 UTC
persisting Response with HttpCore - implementing cache
I've implemented a proxy application (using HttpClient 3.1) with some
manipulation logic.
Now I want to implement a cache for some requests/responses.
I've had a look in the API (and the mailing list) but could not find out how to
use HttpCore to create a Response-object, write it to the file system and
recreate the response for a later (cached) request from the file system.
What are the key classes to construct a Response without a socket from scratch
respectivly from file and how can I write the response (as serialized on a
socket stream) to a file parsing it again?
Thanks in advance,
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: persisting Response with HttpCore - implementing cache
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2008-06-27 at 07:28 +0200, pluenl wrote:
> Oleg,
>
> thank you for your help.
> Sorry that I didn't answer yet, but my time was short so that I could
> have a look at all only yesterday.
>
> Am I right that HttpWriter/HttpParser only process the headers and the
> message body writing/parsing is done via Entity(De)Serializer?
>
Yes, you are.
> I adopted the Buffer-Mockups to use FileOutputStream but I do not use
> the AbstractHttpClientConnection.
>
> I think the code I've implemented by now does what I need, but can you
> please just have a look if there is a potentially problem in my code
> e.g. use of internal API that may change?
>
Looks all right to me
Oleg
> Thanks in advance
> Martin
>
> Here's the code extract (writing and reading response only):
>
> String filename = "c:/temp/response.txt";
>
> EntitySerializer serializer = new EntitySerializer(new
> StrictContentLengthStrategy());
> FileOutputStream fos = new FileOutputStream(filename);
> SessionOutputBufferMockup sobm = new
> SessionOutputBufferMockup(fos);
> HttpResponseWriter writer = new HttpResponseWriter(sobm,
> BasicLineFormatter.DEFAULT, new BasicHttpParams());
> writer.write(response);
> serializer.serialize(sobm, response, response.getEntity());
> fos.close();
>
> EntityDeserializer entityDeserializer = new
> EntityDeserializer(new LaxContentLengthStrategy());
> FileInputStream fis = new FileInputStream(filename);
> SessionInputBufferMockup sibm = new
> SessionInputBufferMockup(fis, 1024);
> HttpResponseParser responseParser = new HttpResponseParser(
> sibm,
> BasicLineParser.DEFAULT,
> new DefaultHttpResponseFactory(),
> new BasicHttpParams());
>
> response = (HttpResponse) responseParser.parse();
>
> response.setEntity(entityDeserializer.deserialize(sibm,response));
> fis.close();
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: persisting Response with HttpCore - implementing cache
Posted by pluenl <pl...@chello.at>.
Oleg,
thank you for your help.
Sorry that I didn't answer yet, but my time was short so that I could
have a look at all only yesterday.
Am I right that HttpWriter/HttpParser only process the headers and the
message body writing/parsing is done via Entity(De)Serializer?
I adopted the Buffer-Mockups to use FileOutputStream but I do not use
the AbstractHttpClientConnection.
I think the code I've implemented by now does what I need, but can you
please just have a look if there is a potentially problem in my code
e.g. use of internal API that may change?
Thanks in advance
Martin
Here's the code extract (writing and reading response only):
String filename = "c:/temp/response.txt";
EntitySerializer serializer = new EntitySerializer(new
StrictContentLengthStrategy());
FileOutputStream fos = new FileOutputStream(filename);
SessionOutputBufferMockup sobm = new
SessionOutputBufferMockup(fos);
HttpResponseWriter writer = new HttpResponseWriter(sobm,
BasicLineFormatter.DEFAULT, new BasicHttpParams());
writer.write(response);
serializer.serialize(sobm, response, response.getEntity());
fos.close();
EntityDeserializer entityDeserializer = new
EntityDeserializer(new LaxContentLengthStrategy());
FileInputStream fis = new FileInputStream(filename);
SessionInputBufferMockup sibm = new
SessionInputBufferMockup(fis, 1024);
HttpResponseParser responseParser = new HttpResponseParser(
sibm,
BasicLineParser.DEFAULT,
new DefaultHttpResponseFactory(),
new BasicHttpParams());
response = (HttpResponse) responseParser.parse();
response.setEntity(entityDeserializer.deserialize(sibm,response));
fis.close();
Re: persisting Response with HttpCore - implementing cache
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-06-04 at 07:07 +0200, pluenl wrote:
> I've implemented a proxy application (using HttpClient 3.1) with some
> manipulation logic.
>
> Now I want to implement a cache for some requests/responses.
>
> I've had a look in the API (and the mailing list) but could not find out how to
> use HttpCore to create a Response-object, write it to the file system and
> recreate the response for a later (cached) request from the file system.
Martin,
What is it exactly intend to cache? HTTP content body, content +
headers, raw data stream?
>
> What are the key classes to construct a Response without a socket from scratch
> respectivly from file and how can I write the response (as serialized on a
> socket stream) to a file parsing it again?
The response head only:
http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java
In order to generate a complete response object with a content entity
you will have to extend this class:
http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.html
You will also need to create mock input / output session buffers,
something similar to those:
http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/mockup/SessionInputBufferMockup.java
http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/mockup/SessionOutputBufferMockup.java
Hope this helps
Oleg
>
> Thanks in advance,
> Martin
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org