You are currently browsing the tag archive for the ‘JSON’ tag.

la vía láctea

Originally uploaded by sanabria

Simon Willison’s blog post made me try Comet finally. The Jetty and Dojo demo has worked without any hassle. Simon said:

The entire application took less than an hour to put together, which I think is a testament to the quality of the Bayeux implementation present in both Jetty and Dojo. […] Comet is probably about 90% of the way to being usable for mainstream project.

So I have decided to give it a go in my new experimental monitoring project and got a core feature working – a RESTish webservice being able to publish and cache a message and retrieve the latest message from the cache on top of Comet in Jetty and Dojo. Bayeux’s channel names are used as URIs in REST and keys in the cache.

What I wanted to archive with this feature is to mashup monitoring data from various tools, Nagios, Ganglia, etc. by server push. Even a simple chat can be in the same page!

First, I have replicated the demo into a webapp war and deployed it in tomcat 6.0, in which process I have learnt how it works more in details. Basically what I need is to deploy a Jetty’s Continuation Servlet, which does all server side magic for you.

I have chosen MemCached to cache Bayeux’s messages which are JSON objects.

The most difficult part so far was hooking the caching function into the Jetty Cometd Servlet. First, I tried DataFilter, but I can’t get the real channel id as I use a wildcard channel “/**”. It always returns the root channel “/”. Next, I tried BayeuxService used in the echo demo, but it does not allow to subscribe a wildcard channel. So I ended up adding a simple server side client which updates the cache on deliver method in Listener interface.

The RESTish webservice servlet, mapped to /galaxy/*, serves the only 2 methods, the HTTP GET to return the last Bayeux’s JSON message on the channel named by getPathInfo() and the HTTP POST to publish posted data onto the channel named by getPathInfo(). For example,

% curl http://localhost:8080/galaxy/nagios
% curl -d “status=OK” http://localhost:8080/galaxy/nagios

At client side I use jQuery with Dojo and its color animations to notify a changed value by changing the background colors. It loads the initial data by getJSON on the galaxy servlet and updates the data by cometd subscriber.

So far so good.


Timeline: Alan Johnston Missing
Originally uploaded by Lilly.

You may have tried Google Spreadsheet to Map wizard that was mentioned in the Google Map API Blog by now. Nice and easy, isn’t it? It’s part of JSON support for Gdata. So I gave it a whirl.

I instantly thought I would use it to populate SIMILE Timeline.

First l looked for a practical source of data and I chose BBC’s Timeline of Alan Johnston to show support for him. I have created a spreadsheet manually, but I believe it’s worth doing. Here it is – Alan Johnston missing in a SIMILE Timeline widget.

There are JSON examples at Google Code. I used Google Doodle calendar in Timeline as template. Also check the Timeline Wiki for more examples.

I’ve found Michael Bolin’s JSON Inspector very useful when checking JSON output.

Note that I used the BBC’s favicon link as icon for Timeline’s event object, which is shown in FireFox, but not in IE.

Related Posts:


Blog Stats

  • 87,765 hits