You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by ZedroS Schwart <ze...@gmail.com> on 2009/07/28 00:02:31 UTC
Caching a resource on the browser side
hi
We need to provide a flash application (www.amcharts.com if anyone is
interested) with some content through some files.
As the files are users specific (and determined with data from the
session), we went for some page delivering the content like this :
public AMChartDataProviderPage(final PageParameters parameters)
{
Object object = parameters.get(DATA_KEY);
if ((object == null) || !(object instanceof String) ||
"".equals(object))
{
throw new IllegalStateException("Expected parameter " +
DATA_KEY + " not provided or empty");
}
String dataId = (String) object;
ByteArrayResource resourceStream;
try
{
resourceStream = new ByteArrayResource("text/csv",
IOHelper.getResourceAsByteArray(dataId + ".csv"));
}
catch (IOException e)
{
throw ExceptionHelper.wrap(e);
}
getRequestCycle().setRequestTarget(new
ResourceStreamRequestTarget(resourceStream.getResourceStream()));
}
However, I don't manage to get this resource to be cached on the user
browser side, despite the resource being cacheable. From what I've
seen, setHeaders() in WebResource is never called... Neither did I
manage to set them myself (on the page they're never called neither...
and the request cycle has no webresponse on which to define the
header).
Any clue ?
thanks in advance
zedros
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Caching a resource on the browser side
Posted by Erik van Oosten <e....@grons.nl>.
According to http://code.google.com/speed/page-speed/docs/caching.html
you should not set both Expires and Cache-Control: max-age.
I suggest you:
- also set Cache-control: public (see the article).
- get rid of the session cookie when the cvs file is first retrieved.
I think the cookie is the culprit.
Regards,
Erik.
ZedroS Schwart wrote:
> I finally managed to set the headers this way :
> WebResponse response = (WebResponse) getRequestCycle().getResponse();
> response.setDateHeader("Date", System.currentTimeMillis());
> response.setDateHeader("Expires", System.currentTimeMillis() +
> CACHE_DURATION);
> response.setHeader("Cache-Control", "max-age=" +
> CACHE_DURATION + ", must-revalidate");
> response.setLastModifiedTime(Time.valueOf(new Date(90, 1,
> 1).getTime()));
> response.setContentType("text/csv");
>
> I see them all in live http headers but... the browser keeps
> requesting the file I send back :
> http://localhost:8080/charts/data/dataId/AOX
>
>
>
> GET /charts/data/dataId/AOX HTTP/1.1
>
> Host: localhost:8080
>
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
> Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
>
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
>
> Accept-Language: en,de;q=0.5
>
> Accept-Encoding: gzip,deflate
>
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>
> Keep-Alive: 300
>
> Connection: keep-alive
>
> Cookie: JSESSIONID=vk0x2bf8xnpb
>
>
>
> HTTP/1.x 200 OK
>
> Last-Modified: Wed, 31 Jan 1990 23:00:00 GMT
>
> Expires: Tue, 04 Aug 2009 09:53:23 GMT
>
> Cache-Control: max-age=3600000, must-revalidate
>
> Content-Type: text/csv; charset=UTF-8
>
> Content-Length: 5659
>
> Date: Tue, 04 Aug 2009 08:53:23 GMT
>
> Server: Jetty(6.1.16)
>
>
> if anyone knows how to resolve that
>
> ++
>
> On Wed, Jul 29, 2009 at 12:10 AM, ZedroS
> Schwart<ze...@gmail.com> wrote:
>
>> hi Juri
>>
>> I did it the same way as you did and it worked fine. Even more : I
>> didn't even see lines in http header (???).
>>
>> However, it doesn't fit my use case : I need to get the link to the
>> file to embed it in a javascript. Previously I did it this way :
>> PageParameters parameters = new PageParameters();
>> parameters.add(AMChartDataProviderPage.DATA_KEY, set.getDataId());
>> return RequestCycle.get().urlFor(AMChartDataProviderPage.class,
>> parameters).toString();
>>
>> however I don't know how to do it with what you provided...
>>
>> ++
>>
>> On Tue, Jul 28, 2009 at 10:32 AM, Juri Prokofiev<pr...@gmail.com> wrote:
>>
>>> It works for me.
>>>
>>> ResourceLink csvLink = new ResourceLink("csvLink", new
>>> ResourceReference(AnnouncementCsvResource.ID), params);
>>> add(csvLink);
>>>
>>> public class AnnouncementCsvResource extends WebResource
>>> {
>>> public static final String ID = "csv";
>>> @Override
>>> public IResourceStream getResourceStream()
>>> {
>>> return new CsvResourceStream();
>>> }
>>>
>>> @Override
>>> protected void setHeaders(WebResponse response)
>>> {
>>> super.setHeaders(response);
>>> response.setAttachmentHeader("announcements.csv");
>>> response.setHeader("Cache-Control", "no-cache");
>>> }
>>>
>>> private class CsvResourceStream extends AbstractStringResourceStream
>>> {
>>> @Override
>>> public String getContentType()
>>> {
>>> return "text/plain";
>>> }
>>>
>>> @Override
>>> protected Charset getCharset()
>>> {
>>> return Charset.forName("ISO-8859-1");
>>> }
>>>
>>> @Override
>>> protected String getString()
>>> {
>>> return "bla bla ";
>>> }
>>> }
>>> }
>>>
>>>
>>> On Tue, Jul 28, 2009 at 10:44 AM, ZedroS Schwart
>>> <ze...@gmail.com>wrote:
>>>
>>>
>>>> Thanks for this answer Juri.
>>>>
>>>> I tried it (once again) and it didn't work : the setHeaders method
>>>> isn't called...
>>>>
>>>> I use Live HTTP headers to check what goes through :
>>>> http://localhost:8080/charts/data/dataId/KBU
>>>>
>>>>
>>>>
>>>> GET /charts/data/dataId/KBU HTTP/1.1
>>>>
>>>> Host: localhost:8080
>>>>
>>>> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
>>>> Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
>>>>
>>>> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
>>>>
>>>> Accept-Language: en,de;q=0.5
>>>>
>>>> Accept-Encoding: gzip,deflate
>>>>
>>>> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>>>>
>>>> Keep-Alive: 300
>>>>
>>>> Connection: keep-alive
>>>>
>>>> Cookie: JSESSIONID=1gxaom5muzh66
>>>>
>>>>
>>>>
>>>> HTTP/1.x 200 OK
>>>>
>>>> Content-Type: text/csv; charset=UTF-8
>>>>
>>>> Content-Length: 5726
>>>>
>>>> Server: Jetty(6.1.16)
>>>>
>>>>
>>>> thanks again
>>>> zedros
>>>>
>>>> On Tue, Jul 28, 2009 at 8:59 AM, Juri Prokofiev<pr...@gmail.com> wrote:
>>>>
>>>>> To set headers to a resource you need to extend setHeaders method from
>>>>> WebResource. Example:
>>>>> @Override
>>>>> protected void setHeaders(WebResponse response)
>>>>> {
>>>>> super.setHeaders(response);
>>>>> response.setAttachmentHeader("announcements.csv");
>>>>> response.setHeader("Cache-Control", "no-cache");
>>>>> }
>>>>>
>>>>> Check your headers. If Cache-Control is passed then resource should be
>>>>> cached on user side.
>>>>>
>>>>> On Tue, Jul 28, 2009 at 1:02 AM, ZedroS Schwart
>>>>> <ze...@gmail.com>wrote:
>>>>>
>>>>>
>>>>>> hi
>>>>>>
>>>>>> We need to provide a flash application (www.amcharts.com if anyone is
>>>>>> interested) with some content through some files.
>>>>>>
>>>>>> As the files are users specific (and determined with data from the
>>>>>> session), we went for some page delivering the content like this :
>>>>>> public AMChartDataProviderPage(final PageParameters parameters)
>>>>>> {
>>>>>> Object object = parameters.get(DATA_KEY);
>>>>>> if ((object == null) || !(object instanceof String) ||
>>>>>> "".equals(object))
>>>>>> {
>>>>>> throw new IllegalStateException("Expected parameter " +
>>>>>> DATA_KEY + " not provided or empty");
>>>>>> }
>>>>>> String dataId = (String) object;
>>>>>> ByteArrayResource resourceStream;
>>>>>> try
>>>>>> {
>>>>>> resourceStream = new ByteArrayResource("text/csv",
>>>>>> IOHelper.getResourceAsByteArray(dataId + ".csv"));
>>>>>> }
>>>>>> catch (IOException e)
>>>>>> {
>>>>>> throw ExceptionHelper.wrap(e);
>>>>>> }
>>>>>> getRequestCycle().setRequestTarget(new
>>>>>> ResourceStreamRequestTarget(resourceStream.getResourceStream()));
>>>>>> }
>>>>>>
>>>>>> However, I don't manage to get this resource to be cached on the user
>>>>>> browser side, despite the resource being cacheable. From what I've
>>>>>> seen, setHeaders() in WebResource is never called... Neither did I
>>>>>> manage to set them myself (on the page they're never called neither...
>>>>>> and the request cycle has no webresponse on which to define the
>>>>>> header).
>>>>>>
>>>>>> Any clue ?
>>>>>>
>>>>>> thanks in advance
>>>>>> zedros
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> http://www.autoladu.ee - kõik varuosad ühes kohas
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>> --
>>> http://www.autoladu.ee - kõik varuosad ühes kohas
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Erik van Oosten
http://day-to-day-stuff.blogspot.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Caching a resource on the browser side
Posted by ZedroS Schwart <ze...@gmail.com>.
I finally managed to set the headers this way :
WebResponse response = (WebResponse) getRequestCycle().getResponse();
response.setDateHeader("Date", System.currentTimeMillis());
response.setDateHeader("Expires", System.currentTimeMillis() +
CACHE_DURATION);
response.setHeader("Cache-Control", "max-age=" +
CACHE_DURATION + ", must-revalidate");
response.setLastModifiedTime(Time.valueOf(new Date(90, 1,
1).getTime()));
response.setContentType("text/csv");
I see them all in live http headers but... the browser keeps
requesting the file I send back :
http://localhost:8080/charts/data/dataId/AOX
GET /charts/data/dataId/AOX HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en,de;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: JSESSIONID=vk0x2bf8xnpb
HTTP/1.x 200 OK
Last-Modified: Wed, 31 Jan 1990 23:00:00 GMT
Expires: Tue, 04 Aug 2009 09:53:23 GMT
Cache-Control: max-age=3600000, must-revalidate
Content-Type: text/csv; charset=UTF-8
Content-Length: 5659
Date: Tue, 04 Aug 2009 08:53:23 GMT
Server: Jetty(6.1.16)
if anyone knows how to resolve that
++
On Wed, Jul 29, 2009 at 12:10 AM, ZedroS
Schwart<ze...@gmail.com> wrote:
> hi Juri
>
> I did it the same way as you did and it worked fine. Even more : I
> didn't even see lines in http header (???).
>
> However, it doesn't fit my use case : I need to get the link to the
> file to embed it in a javascript. Previously I did it this way :
> PageParameters parameters = new PageParameters();
> parameters.add(AMChartDataProviderPage.DATA_KEY, set.getDataId());
> return RequestCycle.get().urlFor(AMChartDataProviderPage.class,
> parameters).toString();
>
> however I don't know how to do it with what you provided...
>
> ++
>
> On Tue, Jul 28, 2009 at 10:32 AM, Juri Prokofiev<pr...@gmail.com> wrote:
>> It works for me.
>>
>> ResourceLink csvLink = new ResourceLink("csvLink", new
>> ResourceReference(AnnouncementCsvResource.ID), params);
>> add(csvLink);
>>
>> public class AnnouncementCsvResource extends WebResource
>> {
>> public static final String ID = "csv";
>> @Override
>> public IResourceStream getResourceStream()
>> {
>> return new CsvResourceStream();
>> }
>>
>> @Override
>> protected void setHeaders(WebResponse response)
>> {
>> super.setHeaders(response);
>> response.setAttachmentHeader("announcements.csv");
>> response.setHeader("Cache-Control", "no-cache");
>> }
>>
>> private class CsvResourceStream extends AbstractStringResourceStream
>> {
>> @Override
>> public String getContentType()
>> {
>> return "text/plain";
>> }
>>
>> @Override
>> protected Charset getCharset()
>> {
>> return Charset.forName("ISO-8859-1");
>> }
>>
>> @Override
>> protected String getString()
>> {
>> return "bla bla ";
>> }
>> }
>> }
>>
>>
>> On Tue, Jul 28, 2009 at 10:44 AM, ZedroS Schwart
>> <ze...@gmail.com>wrote:
>>
>>> Thanks for this answer Juri.
>>>
>>> I tried it (once again) and it didn't work : the setHeaders method
>>> isn't called...
>>>
>>> I use Live HTTP headers to check what goes through :
>>> http://localhost:8080/charts/data/dataId/KBU
>>>
>>>
>>>
>>> GET /charts/data/dataId/KBU HTTP/1.1
>>>
>>> Host: localhost:8080
>>>
>>> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
>>> Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
>>>
>>> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
>>>
>>> Accept-Language: en,de;q=0.5
>>>
>>> Accept-Encoding: gzip,deflate
>>>
>>> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>>>
>>> Keep-Alive: 300
>>>
>>> Connection: keep-alive
>>>
>>> Cookie: JSESSIONID=1gxaom5muzh66
>>>
>>>
>>>
>>> HTTP/1.x 200 OK
>>>
>>> Content-Type: text/csv; charset=UTF-8
>>>
>>> Content-Length: 5726
>>>
>>> Server: Jetty(6.1.16)
>>>
>>>
>>> thanks again
>>> zedros
>>>
>>> On Tue, Jul 28, 2009 at 8:59 AM, Juri Prokofiev<pr...@gmail.com> wrote:
>>> > To set headers to a resource you need to extend setHeaders method from
>>> > WebResource. Example:
>>> > @Override
>>> > protected void setHeaders(WebResponse response)
>>> > {
>>> > super.setHeaders(response);
>>> > response.setAttachmentHeader("announcements.csv");
>>> > response.setHeader("Cache-Control", "no-cache");
>>> > }
>>> >
>>> > Check your headers. If Cache-Control is passed then resource should be
>>> > cached on user side.
>>> >
>>> > On Tue, Jul 28, 2009 at 1:02 AM, ZedroS Schwart
>>> > <ze...@gmail.com>wrote:
>>> >
>>> >> hi
>>> >>
>>> >> We need to provide a flash application (www.amcharts.com if anyone is
>>> >> interested) with some content through some files.
>>> >>
>>> >> As the files are users specific (and determined with data from the
>>> >> session), we went for some page delivering the content like this :
>>> >> public AMChartDataProviderPage(final PageParameters parameters)
>>> >> {
>>> >> Object object = parameters.get(DATA_KEY);
>>> >> if ((object == null) || !(object instanceof String) ||
>>> >> "".equals(object))
>>> >> {
>>> >> throw new IllegalStateException("Expected parameter " +
>>> >> DATA_KEY + " not provided or empty");
>>> >> }
>>> >> String dataId = (String) object;
>>> >> ByteArrayResource resourceStream;
>>> >> try
>>> >> {
>>> >> resourceStream = new ByteArrayResource("text/csv",
>>> >> IOHelper.getResourceAsByteArray(dataId + ".csv"));
>>> >> }
>>> >> catch (IOException e)
>>> >> {
>>> >> throw ExceptionHelper.wrap(e);
>>> >> }
>>> >> getRequestCycle().setRequestTarget(new
>>> >> ResourceStreamRequestTarget(resourceStream.getResourceStream()));
>>> >> }
>>> >>
>>> >> However, I don't manage to get this resource to be cached on the user
>>> >> browser side, despite the resource being cacheable. From what I've
>>> >> seen, setHeaders() in WebResource is never called... Neither did I
>>> >> manage to set them myself (on the page they're never called neither...
>>> >> and the request cycle has no webresponse on which to define the
>>> >> header).
>>> >>
>>> >> Any clue ?
>>> >>
>>> >> thanks in advance
>>> >> zedros
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> >> For additional commands, e-mail: users-help@wicket.apache.org
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> > http://www.autoladu.ee - kõik varuosad ühes kohas
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>> --
>> http://www.autoladu.ee - kõik varuosad ühes kohas
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Caching a resource on the browser side
Posted by ZedroS Schwart <ze...@gmail.com>.
hi Juri
I did it the same way as you did and it worked fine. Even more : I
didn't even see lines in http header (???).
However, it doesn't fit my use case : I need to get the link to the
file to embed it in a javascript. Previously I did it this way :
PageParameters parameters = new PageParameters();
parameters.add(AMChartDataProviderPage.DATA_KEY, set.getDataId());
return RequestCycle.get().urlFor(AMChartDataProviderPage.class,
parameters).toString();
however I don't know how to do it with what you provided...
++
On Tue, Jul 28, 2009 at 10:32 AM, Juri Prokofiev<pr...@gmail.com> wrote:
> It works for me.
>
> ResourceLink csvLink = new ResourceLink("csvLink", new
> ResourceReference(AnnouncementCsvResource.ID), params);
> add(csvLink);
>
> public class AnnouncementCsvResource extends WebResource
> {
> public static final String ID = "csv";
> @Override
> public IResourceStream getResourceStream()
> {
> return new CsvResourceStream();
> }
>
> @Override
> protected void setHeaders(WebResponse response)
> {
> super.setHeaders(response);
> response.setAttachmentHeader("announcements.csv");
> response.setHeader("Cache-Control", "no-cache");
> }
>
> private class CsvResourceStream extends AbstractStringResourceStream
> {
> @Override
> public String getContentType()
> {
> return "text/plain";
> }
>
> @Override
> protected Charset getCharset()
> {
> return Charset.forName("ISO-8859-1");
> }
>
> @Override
> protected String getString()
> {
> return "bla bla ";
> }
> }
> }
>
>
> On Tue, Jul 28, 2009 at 10:44 AM, ZedroS Schwart
> <ze...@gmail.com>wrote:
>
>> Thanks for this answer Juri.
>>
>> I tried it (once again) and it didn't work : the setHeaders method
>> isn't called...
>>
>> I use Live HTTP headers to check what goes through :
>> http://localhost:8080/charts/data/dataId/KBU
>>
>>
>>
>> GET /charts/data/dataId/KBU HTTP/1.1
>>
>> Host: localhost:8080
>>
>> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
>> Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
>>
>> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
>>
>> Accept-Language: en,de;q=0.5
>>
>> Accept-Encoding: gzip,deflate
>>
>> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>>
>> Keep-Alive: 300
>>
>> Connection: keep-alive
>>
>> Cookie: JSESSIONID=1gxaom5muzh66
>>
>>
>>
>> HTTP/1.x 200 OK
>>
>> Content-Type: text/csv; charset=UTF-8
>>
>> Content-Length: 5726
>>
>> Server: Jetty(6.1.16)
>>
>>
>> thanks again
>> zedros
>>
>> On Tue, Jul 28, 2009 at 8:59 AM, Juri Prokofiev<pr...@gmail.com> wrote:
>> > To set headers to a resource you need to extend setHeaders method from
>> > WebResource. Example:
>> > @Override
>> > protected void setHeaders(WebResponse response)
>> > {
>> > super.setHeaders(response);
>> > response.setAttachmentHeader("announcements.csv");
>> > response.setHeader("Cache-Control", "no-cache");
>> > }
>> >
>> > Check your headers. If Cache-Control is passed then resource should be
>> > cached on user side.
>> >
>> > On Tue, Jul 28, 2009 at 1:02 AM, ZedroS Schwart
>> > <ze...@gmail.com>wrote:
>> >
>> >> hi
>> >>
>> >> We need to provide a flash application (www.amcharts.com if anyone is
>> >> interested) with some content through some files.
>> >>
>> >> As the files are users specific (and determined with data from the
>> >> session), we went for some page delivering the content like this :
>> >> public AMChartDataProviderPage(final PageParameters parameters)
>> >> {
>> >> Object object = parameters.get(DATA_KEY);
>> >> if ((object == null) || !(object instanceof String) ||
>> >> "".equals(object))
>> >> {
>> >> throw new IllegalStateException("Expected parameter " +
>> >> DATA_KEY + " not provided or empty");
>> >> }
>> >> String dataId = (String) object;
>> >> ByteArrayResource resourceStream;
>> >> try
>> >> {
>> >> resourceStream = new ByteArrayResource("text/csv",
>> >> IOHelper.getResourceAsByteArray(dataId + ".csv"));
>> >> }
>> >> catch (IOException e)
>> >> {
>> >> throw ExceptionHelper.wrap(e);
>> >> }
>> >> getRequestCycle().setRequestTarget(new
>> >> ResourceStreamRequestTarget(resourceStream.getResourceStream()));
>> >> }
>> >>
>> >> However, I don't manage to get this resource to be cached on the user
>> >> browser side, despite the resource being cacheable. From what I've
>> >> seen, setHeaders() in WebResource is never called... Neither did I
>> >> manage to set them myself (on the page they're never called neither...
>> >> and the request cycle has no webresponse on which to define the
>> >> header).
>> >>
>> >> Any clue ?
>> >>
>> >> thanks in advance
>> >> zedros
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > http://www.autoladu.ee - kõik varuosad ühes kohas
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> http://www.autoladu.ee - kõik varuosad ühes kohas
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Caching a resource on the browser side
Posted by Juri Prokofiev <pr...@gmail.com>.
It works for me.
ResourceLink csvLink = new ResourceLink("csvLink", new
ResourceReference(AnnouncementCsvResource.ID), params);
add(csvLink);
public class AnnouncementCsvResource extends WebResource
{
public static final String ID = "csv";
@Override
public IResourceStream getResourceStream()
{
return new CsvResourceStream();
}
@Override
protected void setHeaders(WebResponse response)
{
super.setHeaders(response);
response.setAttachmentHeader("announcements.csv");
response.setHeader("Cache-Control", "no-cache");
}
private class CsvResourceStream extends AbstractStringResourceStream
{
@Override
public String getContentType()
{
return "text/plain";
}
@Override
protected Charset getCharset()
{
return Charset.forName("ISO-8859-1");
}
@Override
protected String getString()
{
return "bla bla ";
}
}
}
On Tue, Jul 28, 2009 at 10:44 AM, ZedroS Schwart
<ze...@gmail.com>wrote:
> Thanks for this answer Juri.
>
> I tried it (once again) and it didn't work : the setHeaders method
> isn't called...
>
> I use Live HTTP headers to check what goes through :
> http://localhost:8080/charts/data/dataId/KBU
>
>
>
> GET /charts/data/dataId/KBU HTTP/1.1
>
> Host: localhost:8080
>
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
> Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
>
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
>
> Accept-Language: en,de;q=0.5
>
> Accept-Encoding: gzip,deflate
>
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>
> Keep-Alive: 300
>
> Connection: keep-alive
>
> Cookie: JSESSIONID=1gxaom5muzh66
>
>
>
> HTTP/1.x 200 OK
>
> Content-Type: text/csv; charset=UTF-8
>
> Content-Length: 5726
>
> Server: Jetty(6.1.16)
>
>
> thanks again
> zedros
>
> On Tue, Jul 28, 2009 at 8:59 AM, Juri Prokofiev<pr...@gmail.com> wrote:
> > To set headers to a resource you need to extend setHeaders method from
> > WebResource. Example:
> > @Override
> > protected void setHeaders(WebResponse response)
> > {
> > super.setHeaders(response);
> > response.setAttachmentHeader("announcements.csv");
> > response.setHeader("Cache-Control", "no-cache");
> > }
> >
> > Check your headers. If Cache-Control is passed then resource should be
> > cached on user side.
> >
> > On Tue, Jul 28, 2009 at 1:02 AM, ZedroS Schwart
> > <ze...@gmail.com>wrote:
> >
> >> hi
> >>
> >> We need to provide a flash application (www.amcharts.com if anyone is
> >> interested) with some content through some files.
> >>
> >> As the files are users specific (and determined with data from the
> >> session), we went for some page delivering the content like this :
> >> public AMChartDataProviderPage(final PageParameters parameters)
> >> {
> >> Object object = parameters.get(DATA_KEY);
> >> if ((object == null) || !(object instanceof String) ||
> >> "".equals(object))
> >> {
> >> throw new IllegalStateException("Expected parameter " +
> >> DATA_KEY + " not provided or empty");
> >> }
> >> String dataId = (String) object;
> >> ByteArrayResource resourceStream;
> >> try
> >> {
> >> resourceStream = new ByteArrayResource("text/csv",
> >> IOHelper.getResourceAsByteArray(dataId + ".csv"));
> >> }
> >> catch (IOException e)
> >> {
> >> throw ExceptionHelper.wrap(e);
> >> }
> >> getRequestCycle().setRequestTarget(new
> >> ResourceStreamRequestTarget(resourceStream.getResourceStream()));
> >> }
> >>
> >> However, I don't manage to get this resource to be cached on the user
> >> browser side, despite the resource being cacheable. From what I've
> >> seen, setHeaders() in WebResource is never called... Neither did I
> >> manage to set them myself (on the page they're never called neither...
> >> and the request cycle has no webresponse on which to define the
> >> header).
> >>
> >> Any clue ?
> >>
> >> thanks in advance
> >> zedros
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
> > --
> > http://www.autoladu.ee - kõik varuosad ühes kohas
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
http://www.autoladu.ee - kõik varuosad ühes kohas
Re: Caching a resource on the browser side
Posted by ZedroS Schwart <ze...@gmail.com>.
Thanks for this answer Juri.
I tried it (once again) and it didn't work : the setHeaders method
isn't called...
I use Live HTTP headers to check what goes through :
http://localhost:8080/charts/data/dataId/KBU
GET /charts/data/dataId/KBU HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en,de;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: JSESSIONID=1gxaom5muzh66
HTTP/1.x 200 OK
Content-Type: text/csv; charset=UTF-8
Content-Length: 5726
Server: Jetty(6.1.16)
thanks again
zedros
On Tue, Jul 28, 2009 at 8:59 AM, Juri Prokofiev<pr...@gmail.com> wrote:
> To set headers to a resource you need to extend setHeaders method from
> WebResource. Example:
> @Override
> protected void setHeaders(WebResponse response)
> {
> super.setHeaders(response);
> response.setAttachmentHeader("announcements.csv");
> response.setHeader("Cache-Control", "no-cache");
> }
>
> Check your headers. If Cache-Control is passed then resource should be
> cached on user side.
>
> On Tue, Jul 28, 2009 at 1:02 AM, ZedroS Schwart
> <ze...@gmail.com>wrote:
>
>> hi
>>
>> We need to provide a flash application (www.amcharts.com if anyone is
>> interested) with some content through some files.
>>
>> As the files are users specific (and determined with data from the
>> session), we went for some page delivering the content like this :
>> public AMChartDataProviderPage(final PageParameters parameters)
>> {
>> Object object = parameters.get(DATA_KEY);
>> if ((object == null) || !(object instanceof String) ||
>> "".equals(object))
>> {
>> throw new IllegalStateException("Expected parameter " +
>> DATA_KEY + " not provided or empty");
>> }
>> String dataId = (String) object;
>> ByteArrayResource resourceStream;
>> try
>> {
>> resourceStream = new ByteArrayResource("text/csv",
>> IOHelper.getResourceAsByteArray(dataId + ".csv"));
>> }
>> catch (IOException e)
>> {
>> throw ExceptionHelper.wrap(e);
>> }
>> getRequestCycle().setRequestTarget(new
>> ResourceStreamRequestTarget(resourceStream.getResourceStream()));
>> }
>>
>> However, I don't manage to get this resource to be cached on the user
>> browser side, despite the resource being cacheable. From what I've
>> seen, setHeaders() in WebResource is never called... Neither did I
>> manage to set them myself (on the page they're never called neither...
>> and the request cycle has no webresponse on which to define the
>> header).
>>
>> Any clue ?
>>
>> thanks in advance
>> zedros
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> http://www.autoladu.ee - kõik varuosad ühes kohas
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Caching a resource on the browser side
Posted by Juri Prokofiev <pr...@gmail.com>.
To set headers to a resource you need to extend setHeaders method from
WebResource. Example:
@Override
protected void setHeaders(WebResponse response)
{
super.setHeaders(response);
response.setAttachmentHeader("announcements.csv");
response.setHeader("Cache-Control", "no-cache");
}
Check your headers. If Cache-Control is passed then resource should be
cached on user side.
On Tue, Jul 28, 2009 at 1:02 AM, ZedroS Schwart
<ze...@gmail.com>wrote:
> hi
>
> We need to provide a flash application (www.amcharts.com if anyone is
> interested) with some content through some files.
>
> As the files are users specific (and determined with data from the
> session), we went for some page delivering the content like this :
> public AMChartDataProviderPage(final PageParameters parameters)
> {
> Object object = parameters.get(DATA_KEY);
> if ((object == null) || !(object instanceof String) ||
> "".equals(object))
> {
> throw new IllegalStateException("Expected parameter " +
> DATA_KEY + " not provided or empty");
> }
> String dataId = (String) object;
> ByteArrayResource resourceStream;
> try
> {
> resourceStream = new ByteArrayResource("text/csv",
> IOHelper.getResourceAsByteArray(dataId + ".csv"));
> }
> catch (IOException e)
> {
> throw ExceptionHelper.wrap(e);
> }
> getRequestCycle().setRequestTarget(new
> ResourceStreamRequestTarget(resourceStream.getResourceStream()));
> }
>
> However, I don't manage to get this resource to be cached on the user
> browser side, despite the resource being cacheable. From what I've
> seen, setHeaders() in WebResource is never called... Neither did I
> manage to set them myself (on the page they're never called neither...
> and the request cycle has no webresponse on which to define the
> header).
>
> Any clue ?
>
> thanks in advance
> zedros
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
http://www.autoladu.ee - kõik varuosad ühes kohas