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<proj...@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
> <zedros.schwa...@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<proj...@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
>> > <zedros.schwa...@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-unsubscr...@wicket.apache.org
>> >> For additional commands, e-mail: users-h...@wicket.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > http://www.autoladu.ee  - kõik varuosad ühes kohas
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>
>
> --
> http://www.autoladu.ee  - kõik varuosad ühes kohas
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to