Greg has posted 18 posts at DZone. You can read more from them at their website. View Full User Profile

Calling Flex Data Services from Pivot

10.30.2008
| 6267 views |
  • submit to reddit

Pivot comes with built-in support for calling JSON-based REST services. However, if you prefer a more RPC-oriented approach to interacting with server-side data, Adobe's BlazeDS is now a great alternative. BlazeDS is an open-source implementation of the Flex RPC protocol, called AMF (short for Action Message Format). Adobe has begun including Java client libraries in recent builds of BlazeDS, making this protocol available to Pivot applications, which are written in Java.

Documentation on the Java AMF client API is scarce, but I was able to get a prototype up and running relatively quickly. The relevant source code is shown below; the full source is available here:

AMFConnection amfConnection = new AMFConnection();
String url = "http://localhost:8080/samples/messagebroker/amf";

Object result = null;
try {
amfConnection.connect(url);
result = amfConnection.call("product.getProducts");
java.util.ArrayList<object> products = (java.util.ArrayList<object>)result;
productTableView.setTableData(new ListAdapter<object>(products));
} catch(Exception exception) {
System.out.println(exception);
} finally {
amfConnection.close();
}

The application creates an instance of AMFConnection and calls the getProducts() method of the "product" service. This method returns an array list of Product instances that will be displayed in the table. See the samples included with the BlazeDS distribution for more information on how the service is defined.

The returned array list is wrapped in a Pivot ListAdapter and set as the table data. The result looks like this:

For comparison, here is a screen shot of the original Flex example:

So, in addition to REST, Pivot now also has a simple and lightweight means of invoking RPC-oriented web services via BlazeDS, which opens up a number of additional possibilities for Pivot developers.

From http://pivot-toolkit.org/demos/pivot_amf.html

Published at DZone with permission of its author, Greg Brown.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: