Real-time Updates on WebPages - Part 2 - Hello World Comet Application

Guest Author


*10/21/2008 Update* I mention in this post that I had an issue with Dojo 1.2.0, well I figured it out, read Part 3 for details.

Last week I wrote about the introduction of a HTTP Publish-Subscribe Server in WebLogic Server 10gR3.  The new feature is based on the concept of Comet and implements the Bayeux protocol and is very useful for publishing events immediately to subscribed clients over HTTP.  There are many uses for a feature like this, essentially any time where stale information should be updated on a web page as soon as possible.  This entry will showcase a basic Hello World example application that will demonstrate the basic mechanics for using this feature.  Click the image to enlarge and get a better look at the application.



Dev Tools - I built this example with Oracle Enterprise Pack for Eclipse 1.0.0, the Eclipse 3.4 version, which you can download here.  If you just want to deploy the WAR file, then you can skip this.

Application Server - You will need WebLogic Server 10gR3.

Browser Debugging  - You must have Firebug for Firefox if you spend any time doing web development.  I insist.

Javascript Framework - It's also probably not a good idea for me to include Dojo Toolkit source with my example without getting approval, so grab a copy of that too.  I used version 1.1.1 because 1.2.0 was not out last week and more importantly when I tried 1.2.0 tonight, I got the error message below which leads me to believe there is a compatibility issue with 1.2.0 and the Bayeux implementation on WLS.  More to come when I figure this out.  I see that Dojo 1.2.0 version supports an additional connection type that WLS's pubsub server doesn't accept currently.  The bottom line is use Dojo 1.1.1 for now.

*10/21/2008 Update* I mention in this post that I had an issue with Dojo 1.2.0, well I figured it out, read Part 3 for details.

[{"channel": "/meta/handshake", "successful": false, "error": "402:long-polling-json-encoded:Invalid

supportedConnectionTypes attribute.", "supportedConnectionTypes": ["long-polling","callback-polling"

], "version": "1.0", "minimumVersion": "0.1", "advice": {"reconnect": "none", "interval": 500, "multiple-clients"

: false}}]


The example consists of server-side components that simply requires editing two deployment descriptor files in your web application's WEB-INF folder.  The typical steps section of the documentation are pretty clear.  In your weblogic.xml file, add a reference to the pubsub library, which will cause WLS to merge the files in the pubsub library with your application at runtime.  Here is the simplest that file could look:

<?xml version="1.0" encoding="UTF-8"?>

<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"



Secondly, you will need a weblogic-pubsub.xml file.  Below is the simple one for my sample application.  Notice the channel pattern definition, which is concept very similar to a Topic in JMS, except that there is also pattern matching.  There are also some configuration constraints for the channel pattern.

<?xml version="1.0" encoding="UTF-8"?>



<!--since no handler defined, the default handler will be used -->

<wlps:description>subscribe channel constraint</wlps:description>
<!-- Open this up for all users, if this section is enabled, web users will need to authenticate
<!- allow only user with "subscriber" role to subscribe to above channels ->



The simple.jsp that is included with my project showcases the most basic example of Dojo client API.  For additional functionality, look at the source of index.jsp.  Both of these files just as easily could be html files instead of jsp.

<!-- Import Dojo -->
<script type="text/javascript" src=""dojo-release-1.1.1/dojo/dojo.js"

djConfig="parseOnLoad:true, isDebug:true"></script>

<script type="text/javascript">



dojox.cometd.subscribe('/hello/world', function(msg) { alert(msg.data.test); } );

<input type="button"

onclick="dojox.cometd.publish('/hello/world', { test: 'hello world' } )"

value="Click Me!">


Run it

Below are the steps for OEPE/Eclipse, if you just would rather work with the war file, download CometWEB.war, add Dojo 1.1.1 as described in step 3, and deploy to the server.

  1. Download my CometWEB project archive
  2. Import the archive into OEPE as an existing project.
  3. Put Dojo 1.1.1 in the web application so that the path to dojo looks like CometWEB\WebContent\dojo-release-1.1.1\dojo\dojo.js
  4. Deploy to WLS 10.3, I used the samples domain <WEBLOGIC_INSTALLATION>\wlserver_10.3\samples\domains\wl_server
  5. Go to your URL, on my configuraiton it is: http://localhost:7001/CometWEB/index.jsp

Try it in multiple browsers at the same time and publish messages to one another.  Use Firebug to see what is going on in the network traffic between the server and the client.  In future posts I plan on showing some of the protocol and discussing more advanced enterprise features like JMS integration and security.

Join the discussion

Comments ( 4 )
  • sunny Friday, June 18, 2010
    Thank you, excellent articles. I want to change the connection-type from long-polling to callback-polling. How can I do it?
    I appreciate
  • james.bayer Friday, June 18, 2010
    I haven't tried callback-polling, but presumably you could try the technique in Part 3 http://blogs.oracle.com/jamesbayer/2008/10/realtime_updates_on_webpages_p_1.html
    So in that one I removed supported type with code like this in web page:
    So you might also try adding a line that removes long-polling like this:
    Simply a guess. Good luck,
  • Shyam Monday, April 18, 2011
    Your blog is really informative and i really appreciate your effort.I have a query here , can i have a simple html/javascript client without using a dojo toolkit feature.A reply will be iof great help to me.
  • james.bayer Monday, April 18, 2011
    You'll need a client that understand the Bayeux protocol to work with the WebLogic Server HTTP PubSub engine. The Cometd project at http://cometd.org/ has some javascript examples that include JQuery I understand, but I do not have a working sample of it yet. it's on my to-do list. You could look into that if you want to investigate.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.