views:

129

answers:

1

We are building an application on Google App Engine in Java using Spring 2.5.

I would like to put something in the footer that displays page render time.

Where are the best code hooks in either Spring or GAE/J to calculate render time and put it into the Spring model for JSP rendering?

+2  A: 

this is somewhat tricky. the most sensical way to do this may be a servlet filter. but the problem is, when the response returns to the filter, it is already written. so you could write it it, but only at the end of the markup, which does not make sense from a html point of view..

so you have basically three choices that come to my mind:

1) create a Filter, wrap the whole outputStream write it to a buffer and replace a "special string" with the render time. then write the modified buffer to the true outputstream.

2)at the start of the request assign a random/increasing token. save the request duration in a global map/session map. write a javscript that fires after page load that writes out the response time somewhere in the page.

3) fake the whole thing and calculate the response time using javscript/cookies without the server measuring anything.

i have impemented it like 2) and i think its ok.

note this answer is not GAE specific, rather servlet2.x specific. which does not matter.

Andreas Petersson
Ah, one question about 2: where in the Spring code is as close as possible to the beginning of the request? At the @RequestHandler method seems a little late (after dispatch), but maybe not.And what about 3? How are the cookies involved?By the way, thanks for your answer!
dfrankow