Search code examples
firefoxiframeglassfishcometgrizzly

HTTP Streaming using Grizzly Comet in Glassfish doesn't work in Firefox


I have a Java chat-like application using Comet using Grizzly Comet, which works in Chrome but not in Firefox (latest versions of both). It uses the HTTP streaming method, sending Javascript snippets down to a hidden iframe ("forever frame") to be executed. On Firefox, no chat messages are displayed initially, until a few messages have been sent by a Chrome user - then it springs to life and works.

No proxy is in use, so it's not a proxy issue.

What could be the problem?


Solution

  • Ensure that you have both of these lines when you addCometHandler:

            response.setContentType("text/html");
            // Needed to fill buffer on some browsers 
            response.getWriter().write(padding);
    

    padding in this case is an array of characters, and can be anything, as long as it won't do anything and is sufficiently long to trigger buffering in all browsers (1K should be enough). I just filled it with spaces.