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

Comments:

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

Posted by Ludovic Champenois's Blog on July 31, 2007 at 11:09 AM 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 07:53 AM PST #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
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