Build Rich Internet Applications that Run Outside the Browser

Adobe AIR on Ulitzer

Subscribe to Adobe AIR on Ulitzer: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Adobe AIR on Ulitzer: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Adobe AIR Authors: Yeshim Deniz, Yakov Fain, David Weinberger, Maureen O'Gara, Tad Anderson

Related Topics: Java EE Journal, Adobe AIR on Ulitzer, XML Magazine, SOA & WOA Magazine

J2EE Journal: Article

Data Services Made Easy for Adobe Flex Applications

An approach based on XML and e4x

The framework layer consists of two parts: the generated AS server object counterparts and the conversion to AS from XML and AS back to the XML layer. The server counterpart AS layer is generated from the server-side interface schema to populate the AS classes. The conversion to the AS layer contains the logic to convert the incoming XML response to AS class objects transparently. The conversion layer also knows to convert the AS objects passed in as parameters to call a remote service using HTTP/Web Service calls. So the framework layer becomes an inherent part of the Flex application itself providing the infrastructure to call back-end services.

The generation of AS classes from schema/WSDL is done using the wsdl2as tool, a standalone Java application. This application generates the AS sources from the schema definition compatible with the framework's conversion layer. To put the new framework to use, the generated sources may be included in the Flex UI project as an add-on source path and the conversion layer as a library.

Now let's take a simple use case and see how the new framework works. For simplicity's sake let's consider a server hosting a Web Service or a Web application providing the HTTP access and XML response (REST API). In any of the cases above to fetch data to the Flex application running our framework, an XML Schema representation of the server-side objects is required. For the Web Service it may be found in the WSDL file describing the Web Service but for REST-type Web application it might be present in the application or generated from the underlying database schema. Once the XML Schema is found, the AS counterparts of the server-side object can be generated using a tool called the WSDL2AS converter. It generates the AS files that the framework can use to convert XML input to AS and back.

For brevity the samples discussed here will be kept simple and show the power of the underlying framework to build Flex applications for deployed server implementations.

A Simple HTTP and REST API-based Example
First let's see how to build a Flex UI application for a server implementing the REST API, i.e., a simple HTTP request and XML response, which has gotten popular recently. The method of building a REST-style application is based on the schema defining the back-end server objects. AS classes are generated from the schema representation with the wsdl2as tool provided with the framework. To explain REST-style invocation let's consider a fairly complicated production server, an Amazon ECS Web Service, to show how the framework handles the same with great ease.

To start building a REST-type solution for the Amazon ECS know that:

• The WSDL describing the Amazon ECS services and all complex types may be found at .The AS classes can be generated on this WSDL by running the wsdl2as tool.
• The generated source from the wsdl2as tool can be found in the attached amazon.ecs.jar file.
• The conversion layer for the framework can be found in the Flex-xmlrpc.swc file.

Now to build a simple application using the framework and Amazon ECS, let's submit a simple request to the Amazon Server and try to generate the object map from the classes in the amazon-ecs.jar on a successful server response. The HTTP request to send to the Amazon server is:
AWSAccessKeyId=[Your Access Key ID]&

This request will search Amazon for "Apparel" on the keyword "Shirt." On successful invocation the response will return an XML document with <ItemSearchResponse> as the root.

From the generated classes, the class that corresponds to the <ItemSearchResponse> complex type is "" class. So the XML response can be parsed by the conversion layer to instantiate and populate an object of the ItemSearchResponse class.

The code to convert the response to ItemSearchResponse is:

public function onSuccess(event:ResultEvent):void{
var xml:XML = event.result as XML;
    xml = XMLUtil.removeNamespace(xml);
    itemSearchResponse = new ItemSearchResponse().fromXML(xml) as

For brevity's sake the UI for this Flex application is kept simple. The mxml file for the application can be found in Listing 1.

A Web Service and SOAP-based Example
Now let's put the same example to work with SOAP and Web Services. The steps to generate the AS classes from the wsdl file found at are the same. So the same amazon.ecs.jar files for the AS generated source and Flex-xmlrpc.swc for the framework will be used in this case too.

To call the operation "ItemSearch," the generated ItemSearch class can be used. The ItemSearch class can be found in Listing 2.

To execute the "ItemSearch" operation, function call(…) shown below can be used with AS objects passed in as parameters:

public function call( MarketplaceDomain:String,

More Stories By Indroniel Deb Roy

Indroniel Deb Roy works as an UI Architect for BlueCoat Systems.He has more than 10 years of development experience in the fields of J2EE and Web Application development. In his past he worked in developing web applications for Oracle, Novell, Packeteer, Knova etc. He has a passion for innovation and works with various Web2.0 & J2EE technologies and recently started on Smart Phone & IPhone Development.

More Stories By Alex Nhu

Alex Nhu works as a manager, UI Development at Packeteer Inc. He has more than 11 years of work experience designing and architecting complex server-side J2EE and XML applications. He loves developing Web applications with Flex now after getting a taste of developing UI using other RIA platforms.

Comments (13)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.