users@jersey.java.net

Re: [Jersey] Firefox making multiple GET requests against a resource - any idea why?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 12 Nov 2009 18:06:35 +0100

Hi Alex,

I dunno if the following helps:

   http://stackoverflow.com/questions/95715/what-causes-firefox-to-make-a-get-request-after-submitting-a-form-via-the-post-me
   http://brian.pontarelli.com/2006/05/02/is-your-browser-requesting-a-page-twice/

> From looking at the response in Firebug, the content-encoding has
> been set
> to gzip and I was wondering whether this would be incorrect for a gif
> (output from a byte[])?

Do you know what is setting the Content-Encoding response header? do
you have a filter specified supporting gzip'ing of response entities?

In any case that should be harmless although rather inefficient given
that a 1x1 GIF image is returned.

I suspect that the HTML image take is playing some role in this.

You might want ti play around with the cache control headers you are
using. Perhaps try:

   return Response.ok(ONE_BY_ONE).type("image/gif").build();

and see if that works.

Paul.

On Nov 12, 2009, at 5:41 PM, Alex Bleasdale wrote:

>
> Hi,
>
> I'm wondering if anyone else is experiencing a similar issue -
>
> I've created a resource that returns a 1x1 transparent gif image
> called
> ONE_BY_ONE (the response is written out from a static byte array
> containing
> the necessary information).
>
> At the top of the method, I'm using the @Produces annotation to set
> the mime
> type to "image/gif" and - for each get request - the resource uses
> hibernate
> to write out one row to a table.
>
> On completion, the final response is rendered like so in my resource
> method:
>
> return Response.ok(ONE_BY_ONE).cacheControl(cc).type("image/
> gif").build();
>
> I've tested the resource in Firefox, Opera, Chrome and IE8 (all
> patched and
> up-to-date) in Windows XP.
>
> On making a request to "get" the resource, Opera, Chrome and IE8 all
> register one request, which in turn writes out one row. This is the
> desired
> behaviour and is consistent even over several attempts.
>
> However, getting the resource using Firefox (3.5) will cause 2 (and
> sometimes 3) rows to be written every time. In other words, from
> looking at
> the logs, it would appear that the "GET" happens multiple times.
>
> The only info I've managed to find online regarding how I may be
> able to go
> about solving this this is:
> http://forums.mozillazine.org/viewtopic.php?f=25&t=1412535
>
> Their suggestion of adding character encoding was something I tried
> (@Produces("image/gif;charset=ISO-8859-1")) but this has not
> appeared to
> make any difference whatsoever.
>
> From looking at the response in Firebug, the content-encoding has
> been set
> to gzip and I was wondering whether this would be incorrect for a gif
> (output from a byte[])?
>
> I've seen in some places, a recommendation for Content-Transfer-
> Encoding:
> base64 when "producing" gifs and was wondering whether I should set
> this
> (and indeed, whether it would make any difference if I did).
>
> Firstly, does anyone know how to alter the transfer encoding and is it
> something that should be done if you're using jersey to output
> images (and
> the like).
>
> Secondly, has anyone else found themselves to be in a similar
> situation with
> Firefox? If so, can they offer me any advice as to what my options
> are?
>
> Thanks in advance,
> A
> --
> View this message in context: http://n2.nabble.com/Firefox-making-multiple-GET-requests-against-a-resource-any-idea-why-tp3994046p3994046.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>