Miles to go ...

Arun Gupta is a Technology Evangelist for Web Services and Web 2.0 Apps at Sun. He was the spec lead for APIs in the Java platform, committer in multiple Open Source projects, participated in standard bodies and contributed to Java EE and SE releases.
« jMaki "SpeedGeeking" | Main | Jaane Bhi Do Yaaron! »

http://blogs.sun.com/arungupta/date/20070727 Friday July 27, 2007

jMaki - Accessing External Services

A jMaki widget in a page can communicate with:

  • Other widgets on the same page using publish/subscribe mechanism
  • Services in the application domain using service="data.jsp".
  • Services outside the application domain using proxy (xhp).

This blog entry explains how external services are accessed by jMaki widgets.

This image shows a Web application with multiple pages (Page1, Page2, Page3) where one of the page (Page2) contain at least one jMaki widget. For a BlockList widget, the generated code fragment looks like:

<a:widget name="jmaki.blockList" value="[
    {title : 'jMaki Project Home', link : 'https://ajax.dev.java.net', description : 'Where to go for the latest jMaki.' },
    {title : 'jMaki Widgets Home', link : 'https://widgets.dev.java.net', description : 'The source for the latest jMaki widgets.' },
    {title : 'jMaki-Charting Home', link : 'https://jmaki-charting.dev.java.net', description : 'Enables complex charts rendered on the client in any modern browser.' }
]" />

This code fragment populates the widget with static data specified in the value attribute. In order to populate the widget with data from an external service, such as an RSS feed, the value attribute needs to be replaced with service="/xhp?id=rss". Let me explain how that works.

If any page consists of a jMaki widget then the jMaki runtime is bundled with the application. The runtime consists of jmaki.xhp.XmlHttpProxyServlet class that maps to "/xhp" URL pattern within the application context. The id specified in the URL, "rss", is configured in a configuration file named "xhp.json". This file consists of a list of default external services that can be accessed by the widgets in a page. Each entry in this file can can be specified using up to 5 different parameters:

  • ID (required parameter, unique identifier for the entry)
  • URL (required parameter, location of external service)
  • Parameters (optional parameters specifying the default values passed to URL)
  • API Key (optional parameter to invoke the service with a specific key)
  • Stylesheet (optional parameter to process the response)

So if BlockList widget needs to access the RSS feed, then the code fragment needs to look like:

<a:widget name="jmaki.blockList" service="/xhp?id=rss" />

The corresponding entry in xhp.json is:

{"id": "rss",
    "url":"http://weblogs.java.net/blog/ludo/index.rdf",
    "xslStyleSheet": "rss.xsl"
}

The tag and the default entry tells the jMaki runtime to fetch the RSS feed from http://weblogs.java.net/blog/ludo/index.rdf, apply the 'rss.xsl' stylesheet (that understand the multiple RSS/Atom formats) to the received response and convert the data into into a common JSON data format of the type "dataType" : "jMakiRSS". The BlockList widget knows how to convert jmakiRSS data to its specific data model.

This approach allows all widgets, that take a "value" attribute, to consume data from external services.

Technorati: jmaki rss services web2.0

del.icio.us | furl | simpy | slashdot | technorati | digg
Comments:

[Trackback] jMaki returns from vacation...with pictures:)

Posted by Ludovic Champenois's Blog on July 31, 2007 at 06:09 PM PDT #

[Trackback] In my role of Technology Evangelist, I get the opportunity to meet a lot of community (folks like you :) all around the world. In the year 2007, I represented GlassFish (and related technologies - Metro, jMaki and Jersey) at...

Posted by Arun Gupta's Blog on January 01, 2008 at 03:53 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
« jMaki "SpeedGeeking" | Main | Jaane Bhi Do Yaaron! »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.

--> ajax ajaxworld conf eclipse fitness gem glassfish glassfishday hyderabad india indigo interoperability javaone javaone2008 jax-ws jmaki jpa jruby mac marathon metro microsoft mysql netbeans phobos photography presos railsconf ruby rubyonrails running runninglog runsfm screencast siliconvalleymarathon sun suntechdays swdp tango theserverside totd training traveltips v3 vista wcf web2.0 webservices webtier windows wsaddressing wsit youtube
Locations of visitors to this page

calendar

« September 2008
SunMonTueWedThuFriSat
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today
www.flickr.com
This is a Flickr badge showing public photos from ArunGupta. Make your own badge here.
Add to Technorati Favorites

Last 50