users@grizzly.java.net

Problem with Grizzly/Comet on Glassfish 3.1.2

From: Enrique Ubinas <enrique.ubinas_at_gmail.com>
Date: Tue, 19 Jun 2012 12:25:20 -0400

So I'm attempting to set up http long polling with Grizzly Comet on
Glassfish 3.1.2. I've enabled Comet on my Glassfish server and for whatever
reason its still not working. When I make a calls to
cometContext.notify(obj), the CometEventHandler doesn't receive any events.
On top of that, I also noticed that the addCometHandler method doesn't
suspend the connection and returns immediately. Wireshark tells me that I
get a response from the server with a content length of zero. Any help with
this is greatly appreciated. Below is the relevant sections of my code.
Thank you.

This code is found in the doGet method of my HttpServlet sub class.

[code]
final CometContext<?> cometContext =
CometEngine.getEngine().register(Constant.COMPANY_LOCATIONS_TOPIC);
final CompanyLocationHandler handler = new CompanyLocationHandler();

handler.attach(response);
cometContext.addCometHandler(handler);
[/code]

This code is found in the service method of another HttpServlet sub class.

[code]
final CometContext<?> cometContext =
CometEngine.getEngine().register(Constant.COMPANY_LOCATIONS_TOPIC);
final Location companyLocation = new Location(locationId, address, city,
state, zipCode, country);

cometContext.notify(companyLocation);
[/code]

And this my implementation of the onEvent method in CompanyLocationHandler.

[code]
public void onEvent(final CometEvent event) throws IOException
{
    if (event.getType() == CometEvent.NOTIFY)
    {
        final Location companyLocation = (Location)event.attachment();
        final PrintWriter printWriter = this.response.getWriter();

        try
        {
            this.response.setContentType("application/json");

            printWriter.write(companyLocation.toJson());
            printWriter.flush();
        }
        finally
        {
            printWriter.close();
        }

        event.getCometContext().resumeCometHandler(this);
    }
}
[/code]