Over a million developers have joined DZone.

Calling Flex Data Services from Pivot

DZone's Guide to

Calling Flex Data Services from Pivot

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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 {
result = amfConnection.call("product.getProducts");
java.util.ArrayList<object> products = (java.util.ArrayList<object>)result;
productTableView.setTableData(new ListAdapter<object>(products));
} catch(Exception exception) {
} finally {

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

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}