JFreechart / Gwt image generation

315 views
Skip to first unread message

Luciano Broussal

unread,
Mar 4, 2007, 5:27:06 AM3/4/07
to Google Web Toolkit
Hi all,

With a timer in my gwt application i'm timely refreshing an image that
is server side generated by a JFreechart Servlet

response.setContentType("image/png");
response.addHeader("Pragma" , "no-cache");
response.addIntHeader("Expires" , 0);
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart,
300,
250);


On the client side i do somethign like this in a Timer loop:
setSumVote(sum);
Image chart = new Image("charts?
type=overview");
chart.setSize("300px", "250px");
votesGrid.setWidget(1 ,2 , chart);

votesGrid.getFlexCellFormatter().setRowSpan(0,2, 5);

HorizontalPanel layout = new
HorizontalPanel();
layout.add(votesGrid);
layout.add(chart);
RootPanel.get("votes").clear();
RootPanel.get("votes").add(layout);


What i don't understand is why the Image is not displayed with the new
data than move on server side.

FYI: when i clear the cache file of the browser the image is refreshed
with the new data!
So i decide to add headers :
response.addHeader("Pragma" , "no-cache");
response.addIntHeader("Expires" , 0);

But this has no effect :( the image is stored again in the browser
cache directory. It that the problem i suppose

Do the header work for image MIME type ?


I really do pass on server side generation timely and with good data
values , in debugging mode !!!!


Any idea ?


Thank you by advance.


Luciano

georgeuoa

unread,
Mar 4, 2007, 3:08:05 PM3/4/07
to Google Web Toolkit
Hello Luciano

I wrote a small sample trying to reproduce your issue and I could
verify exactly what you witnessed. The strange thing is with Firefox
that when you right-click on the image (View image) and then view the
new page's properties, the browser suddenly changes it's mind about
the 'cacheability' of that image. Searching the web I found endless
discussions about what may be the possible causes and remedies
(apparently not only FF nor GWT users alone have that problem!) and no
matter what headers I tried I could get FF to reload that image.

What did though work for me is append a dummy parameter like this:

Timer t = new Timer(){
public void run() {
image.setUrl("images/pic1.jpg?param="+(counter++));
}
};
t.scheduleRepeating(500);

which apparently is considered as a 'new' url and as such not in the
cache.
Regards
g.

Luciano Broussal

unread,
Mar 4, 2007, 3:41:00 PM3/4/07
to Google Web Toolkit
Hi georgeuoa,

first of all may thanks to gave me a response.

After investigations, i've found many post on the net about the
behavior i have encountered :)

but none give a clear solution except maybe the post on the
TheServerSide.com.

The set of headers they propose works perfectly with IE but not for
FF :) for once IE is better thant FF, The browser world is upside
down :)

At the end I've done for continuing my way the workaround you have
proposed :) but this solution will fill the cache area of the users :
(

They are others solutions that consist to generate temp chart on the
server side and after user view they are mark for deletion as a
garbage collector would do it.

Anyway. this problem should be fix simply with the HTTP headers but i
don't know what is the combinations for doing it working on FF and IE
at least.

for those who need help in same area :

response.setHeader("cache-control", "no-cache, no-store,must-
revalidate"); // HTTP 1.1

this header set work nicely for IE but not for FF :(

Indeed thank you very much for your response and the hard work you
have done to reproduce the enviromement !!!

Hoping a contributor could give us THE solution :)


Luciano,
--
http://www.gwtwindowmanager.org

dgirard

unread,
Mar 4, 2007, 3:42:57 PM3/4/07
to Google Web Toolkit
Here is an article about integrating JFreeChart and GWT :
http://www.jfree.org/phpBB2/viewtopic.php?t=19080&sid=f627bee2b70f0f512009d737957b8eee


On Mar 4, 9:08 pm, "georgeuoa" <g.georgovassi...@gmail.com> wrote:

Luciano Broussal

unread,
Mar 5, 2007, 5:39:35 AM3/5/07
to Google Web Toolkit
Hi dgirard,

Very interessing article !!!!! i will revoiew my design considering
this articles sweet advises :)

BTW i think this recipe no fix the cache problem ! ?


Regards.

Luciano,
--
http://www.gwtwindowmanager.org


On Mar 4, 9:42 pm, "dgirard" <didier.gir...@gmail.com> wrote:
> Here is an article about integrating JFreeChart and GWT :http://www.jfree.org/phpBB2/viewtopic.php?t=19080&sid=f627bee2b70...

Message has been deleted

George Georgovassilis

unread,
Mar 5, 2007, 5:46:50 AM3/5/07
to Google-We...@googlegroups.com
Do you have some constraint that does not allow you to use the unique url approach? You mentioned that you were concerned about the browser cache filling up with images... I wouldn't worry (although is somehow presumptuous and may stem more from ignorance than wisdom) too much about this. Even if the browser has to reload that image frequently, you should be more concerned about the network traffic than the cache filling up (which is tended by the browser anyway).

Am I missing something here?

On 3/5/07, Luciano Broussal <luciano....@gmail.com> wrote:

Hi dgirad,

I've found a tiny project that use GWT/JFreeChart but when i look my
browser temporary folder i see the chart in cache but the chart seems
moving in realtime so i suppose unique url are generated to by pass
the cache process ? http://www.pokercontrolcenter.com




On Mar 4, 9:42 pm, "dgirard" <didier.gir...@gmail.com> wrote:

> Here is an article about integrating JFreeChart and GWT : http://www.jfree.org/phpBB2/viewtopic.php?t=19080&sid=f627bee2b70...

Luciano Broussal

unread,
Mar 5, 2007, 5:59:11 AM3/5/07
to Google Web Toolkit
No pb George,

Just hope that a user that has set a browser cache size with 200mo by
mistake will not see his box going slowdown by seeing is directory
cache to fill with many has been charts.

One of my project use a lot of JFreeChart so it is really important
for me to have the best approach concerning this integration

Indeed the method you have post works perfectly.

Thank you George.

Luciano.
--
http://www.gwtwindowmanager.org


On Mar 5, 11:46 am, "George Georgovassilis"


<g.georgovassi...@gmail.com> wrote:
> Do you have some constraint that does not allow you to use the unique url
> approach? You mentioned that you were concerned about the browser cache
> filling up with images... I wouldn't worry (although is somehow presumptuous
> and may stem more from ignorance than wisdom) too much about this. Even if
> the browser has to reload that image frequently, you should be more
> concerned about the network traffic than the cache filling up (which is
> tended by the browser anyway).
>
> Am I missing something here?
>

> On 3/5/07, Luciano Broussal <luciano.brous...@gmail.com> wrote:
>
>
>
> > Hi dgirad,
>
> > I've found a tiny project that use GWT/JFreeChart but when i look my
> > browser temporary folder i see the chart in cache but the chart seems
> > moving in realtime so i suppose unique url are generated to by pass

> > the cache process ?http://www.pokercontrolcenter.com

Chiraz

unread,
Mar 5, 2007, 7:25:28 PM3/5/07
to Google Web Toolkit
You could try:

response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=0");

see:

http://forum.java.sun.com/thread.jspa?forumID=45&threadID=233446

G>

On Mar 5, 7:59 am, "Luciano Broussal" <luciano.brous...@gmail.com>
wrote:


> No pb George,
>
> Just hope that a user that has set a browser cache size with 200mo by
> mistake will not see his box going slowdown by seeing is directory
> cache to fill with many has been charts.
>
> One of my project use a lot of JFreeChart so it is really important
> for me to have the best approach concerning this integration
>
> Indeed the method you have post works perfectly.
>
> Thank you George.
>
> Luciano.

> --http://www.gwtwindowmanager.org

Reinier Zwitserloot

unread,
Mar 6, 2007, 11:08:27 AM3/6/07
to Google Web Toolkit
Luciano: The ENTIRE INTERNET dodges caches with unique URLs.

If someone's somehow decided to appropriate their entire harddrive as
a web cache, then their system will be crashing forthwith whether or
not you persist in solving this problem the hard way.

Seriously. Use the unique URL approach. It works. Everything else
doesn't.

On Mar 5, 11:59 am, "Luciano Broussal" <luciano.brous...@gmail.com>
wrote:


> No pb George,
>
> Just hope that a user that has set a browser cache size with 200mo by
> mistake will not see his box going slowdown by seeing is directory
> cache to fill with many has been charts.
>
> One of my project use a lot of JFreeChart so it is really important
> for me to have the best approach concerning this integration
>
> Indeed the method you have post works perfectly.
>
> Thank you George.
>
> Luciano.

> --http://www.gwtwindowmanager.org

Luciano Broussal

unread,
Mar 6, 2007, 12:13:43 PM3/6/07
to Google Web Toolkit
Hi Reiner,

Thank you for your post but please keep cool.
If i remember well Dan from The Google Team has already congratulate
you for good technicals posts but ask you also to be bit more cool :)
No worries.

Thank you again and continue contributing for the GWT community like
you do!!

Regards.

Luciano
--
http://www.gwtwindowmanager.org

Luciano Broussal

unread,
Mar 6, 2007, 12:36:45 PM3/6/07
to Google Web Toolkit

And the WINNER is
Chiraz.

Work like a charm!!!

Indeed, thank you to all of you!!!


Luciano
--
http://www.gwtwindoamanager.org

georgeuoa

unread,
Mar 6, 2007, 3:10:38 PM3/6/07
to Google Web Toolkit
I'm glad it works for you Luciano... but it doesn't for me :(

I wrote a test that looks about like this:

Timer t = new Timer(){
public void run() {

panel.remove(image);
image = new Image("images/pic1.jpg");
panel.add(image);
}
};
t.scheduleRepeating(5000);

And it loads the image only once. Variations like keeping the same
image and just setting the url (image.setUrl(...) ) don't work either
(we're always talking about FF 2.0, right?). Are you using only the
headers Chiraz mentioned or do you have another ace up in your sleeve?

Luciano Broussal

unread,
Mar 6, 2007, 4:03:19 PM3/6/07
to Google Web Toolkit
right for FF2.
Your test case can't work
you make a call to static image which is completly different from
asking a stream that give response with specialized headers!

Image('static url') != Image ('server-service-url') that give response
with a specialized stream and http headers.

Regards.

Luciano
--
http://gwtwindowmanager.org

georgeuoa

unread,
Mar 6, 2007, 4:43:35 PM3/6/07
to Google Web Toolkit
No no no! images/pic1.jpg is not a file, just a url. I stream it
through a servlet of my own so that I can control the http headers for
the experiment.

So, what are you doing then which I'm doing wrong?

On Mar 6, 11:03 pm, "Luciano Broussal" <luciano.brous...@gmail.com>
wrote:


> right for FF2.
> Your test case can't work
> you make a call to static image which is completly different from
> asking a stream that give response with specialized headers!
>
> Image('static url') != Image ('server-service-url') that give response
> with a specialized stream and http headers.
>
> Regards.
>
> Luciano

> --http://gwtwindowmanager.org

jhulford

unread,
Mar 7, 2007, 9:36:47 AM3/7/07
to Google Web Toolkit
I believe the Pragma header is actually supposed to be sent by the
client and is an HTTP/1.0 feature that's superceded by the Cache-
Control header in 1.1. What you really want in combination with
Reiner's insistence of unique URLs is a header like "Cache-Control: no-
cache, no-store". See the HTTP Header RFC here:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.

By combining both approaches you force non-compliant clients to use
fresh copies of your charts with the unique URL and the header keeps
the conformant clients from filling their cache with your charts.

For more reading, here's a pretty good caching tutorial:
http://www.mnot.net/cache_docs/

Luciano Broussal

unread,
Mar 7, 2007, 9:47:57 AM3/7/07
to Google Web Toolkit
Thank you jhulford
What do you mean by combining the two approaches ?

George Georgovassilis

unread,
Mar 7, 2007, 10:30:34 AM3/7/07
to Google-We...@googlegroups.com
As far as my understanding goes if you use the unique URL approach you avoid the caching mechanism completely because there is nothing to cache, thus headers do not play any role, no?

jhulford

unread,
Mar 8, 2007, 10:32:03 AM3/8/07
to Google Web Toolkit
By combining the two approaches, I mean using the Cache-Control header
and unique URLS. As far as I know, just because you use unique
headers doesn't mean the content requested won't get cached. The
browser has no real way to know that the URL it requested was unique.
But because the URL you're requesting isn't already found in your
browsers cache (due to the uniqueness added), the browser executes a
new request to the server.

One of Luciano's issues was that he didn't want to fill a user's
browser cache, using the Cache-Control header should prevent that for
clients that respect the header along with causing the browser to
execute a new request for the resource every time. Adding a uniqueness
factor to the URL should make every client (even non-compliant ones)
execute a new request when fetching the chart.

On Mar 7, 10:30 am, "George Georgovassilis"

George Georgovassilis

unread,
Mar 8, 2007, 11:48:54 AM3/8/07
to Google-We...@googlegroups.com
According to w3c [1] , sect 3.2 and 3.2.2 a URL (they prefer calling it
URI) is perceived as http_URL = "http:" "//" host [ ":" port ] [
abs_path [ "?" query ]]
And then in 3.2.3 (URI Comparison) it basically states that two URI's
are equal if the case-insensitive string comparison succeeds (there are
some exceptions, the interested reader can look it up in [1]).
As far as I understand, this means that two URLs with the same path but
different parameters are considered not the same. You are referring to
'non compliant clients', but that is in general a different story since
this can mean anything and you can't speculate which part of the http
protocol they'd like to follow and which to omit. You could consider the
Windows notepad.exe a non compliant web browser :)

I don't think that filling up the browser cache is an issue, browsers
take good care of their cache (as far as I know at least) and, unless
we're talking about an intranet application, one should be worried more
about the network traffic (after all, you have somehow to get that data
first to the user over the wire) than filling up the cache.

BR
G.

[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html

Luciano Broussal

unread,
Mar 9, 2007, 4:32:20 AM3/9/07
to Google Web Toolkit
Thank you all for the posts.

I've combined your solutions to solve my problem.

Regards.

Luciano
--
http://groups.google.com/group/gwt-window-manager
http://www.gwtwindowmanager.org

On Mar 8, 5:48 pm, "George Georgovassilis"

Reply all
Reply to author
Forward
0 new messages