BEA Workshop Studio is an Eclipse-based toolset that allows developers to easily build rich Internet applications (RIAs) using Adobe Flex and Java. For developers already using BEA Workshop Studio, the new Flex bundle makes it easy to build RIAs in the same IDE used to build the business logic of an application. For developers already using Flex Builder, the Flex bundle for BEA Workshop Studio adds sophisticated functionality for building and debugging the Java-based back-end code for an application. The combination of BEA Workshop Studio and Flex Builder fits perfectly with typical three-tier architectures and helps developers to easily create a clean separation between the client and mid-tier.
In this tutorial, I walk you through the steps to creating an RIA using Java for the back-end business logic and Flex for the front-end view of the application. I will use the BEA Workshop Studio (Flex Bundle) to create a simple Java mid-tier and a simple Flex front-end for that mid-tier. Using BlazeDS, the new Adobe open-source Java remoting technology for Flex that facilitates communication.
To get the most out of this article you will need to install the following software:
First, you'll create a web application from the base blazeds.war file, creating a Java class file, and adding it to the web application. Next, you'll configure the web application to allow a Flex application to talk to the Java class. You'll create a Flex application, which will call a method on the Java class in the web application. Then you'll add the Flex application to the web application and deploy it to an application server. Lastly, you can run the Flex application in a web browser.
Adobe Flex applications run on the client-side in the browser. When they need to communicate with a server to persist data or integrate with other services, they have a variety of options. Flex has built-in libraries for communicating to servers through HTTP using serialization methods such as RESTful and SOAP. However, these methods of communication add complexity to applications because you must serialize objects to text and then back to objects. The Adobe Labs beta software, BlazeDS, provides a simpler method of communicating with Java back-ends, whether the back-end is based on POJOs, Spring, or EJB. By taking advantage of the open AMF serialization protocol for Adobe Flash, Java objects can be translated easily to and from Flash objects. With the remoting library in Flex, client applications can make method calls easily on back-end Java objects or call services like Spring Beans or EJB Session Beans. There is also a messaging library in Flex that allows Flex applications to consume and produce messages on a topic either stand-alone or JMS. Future articles will explain how to build applications that use the messaging capability of BlazeDS using BEA Workshop Studio (Flex Bundle).

Figure 1. Importing the blazeds.war file



public String sayHello()
{
return "hello, World";
}
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service-include file-path="remoting-config.xml" />
</services>
<security>
</security>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>
</channels>
<logging>
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>false</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
<system>
<redeploy>
<enabled>false</enabled>
</redeploy>
</system>
</services-config>

<?xml version="1.0" encoding="UTF-8"?> <service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> <adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/> </adapters> <default-channels> <channel ref="my-amf"/> </default-channels> <destination id="HelloWorld"> <properties> <source>HelloWorld</source> </properties> </destination> </service>



<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="ro.sayHello()">
<mx:RemoteObject id="ro" destination="HelloWorld"/>
<mx:Label text="{ro.sayHello.lastResult}"/>
</mx:Application>
-services C:\bea\user_projects\workspaces\workshop\flex_server\WebContent\WEB-INF\flex\services-config.xml -context-root /flex_server




The Flex application runs in the web browser, and displays the string: "Hello, World," which it received from the server through the RemoteObject and BlazeDS.
Continue learning about using Flex and Java together at:
James Ward is a Technical Evangelist for Flex at Adobe and Adobe's JCP representative to JSR 286, 299, and 301. Much like his love for climbing mountains he enjoys programming because it provides endless new discoveries, elegant workarounds, summits and valleys. His adventures in climbing have taken him many places. Likewise, technology has brought him many adventures, including: Pascal and Assembly back in the early '90s; Perl, HTML, and JavaScript in the mid '90s; then Java and many of its frameworks beginning in the late '90s. Today he primarily uses Flex to build beautiful front ends for Java based back ends. Prior to working at Adobe, James built a rich marketing and customer service portal for Pillar Data Systems. James Ward's blog can be found at www.jamesward.org.