Oracle GlassFish Server 3.0.1 Application Development Guide

ProcedureTo Write, Deploy, and Run the Client

The examples in this task are taken from the example chat application that is posted and discussed at http://weblogs.java.net/blog/jfarcand/archive/2007/02/gcometd_introdu_1.html.

  1. Add script tags to the HTML page. For example:

    <script type="text/javascript" src="chat.js"></script>
  2. In the script, call the needed libraries. For example:

    dojo.require("dojo.io.cometd");
  3. In the script, use publish and subscribe methods to send and receive messages. For example:

    cometd.subscribe("/chat/demo", false, room, "_chat");
    cometd.publish("/chat/demo", { user: room._username, chat: text});
  4. Deploy the web application as you would any other web application. For example:


    asadmin deploy cometd-example.war
  5. Run the application as you would any other web application.

    The context root for the example chat application is /cometd and the HTML page is index.html. So the URL might look like this:


    http://localhost:8080/cometd/index.html
See Also

For more information about deployment in the GlassFish Server, see the Oracle GlassFish Server 3.0.1 Application Deployment Guide.

For more information about the Bayeux protocol, see Bayeux Protocol.

For more information about the Dojo toolkit, see http://dojotoolkit.org/.

For information about pushing data from an external component such as an EJB module, see the example at http://blogs.sun.com/swchan/entry/java_api_for_cometd. Using this Grizzly Java API for Cometd makes your web application non-portable. Running your application on a server that doesn't support Grizzly Comet will not work.

For information about REpresentational State Transfer (RESTful) web services and Comet, see RESTful Web Services and Comet.