Over a million developers have joined DZone.

Calling Flex Data Services from Pivot

· Java Zone

Easily build powerful user management, authentication, and authorization into your web and mobile applications. Download this Forrester report on the new landscape of Customer Identity and Access Management, brought to you in partnership with Stormpath.

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

The Java Zone is brought to you by Stormpath—a complete, pre-built User Management API. Want to learn how to use JWTs to protect microservices from CSRF and more? Check out this on-demand webinar with our Java Developer Evangelist, Micah Silverman.

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}