Adobe
製品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
その他の製品一覧
ソリューション
デジタルマーケティング
デジタルメディア
教育
金融機関
Web Experience Management
その他のソリューション
ラーニング サポート ダウンロード 会社情報
ご購入
アドビストア 安心のサポート& サービス
アカデミックストア 学生、教職員、個人向け
アドビライセンスストア 中小企業向け
ボリュームライセンスについて 企業、教育機関、官公庁向け
販売パートナー
キャンペーン情報
検索
 
情報 サインイン
ようこそ、 さん カート 注文状況 マイアカウント
マイアカウント
注文状況
アカウント情報の変更
コミュニケーションの設定を変更
サインアウト
サインインの目的 お客様のアカウントや体験版ダウンロード、製品の拡張機能、コミュニティエリアへのアクセスなどを管理するため
Adobe
製品 セクション ご購入   検索  
ソリューション 会社情報
サポート ラーニング
サインイン サインアウト 注文状況 マイアカウント
先行予約の提供開始予定日Date. 商品が発送されるまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。 先行予約の提供開始予定日Date. ダウンロードの準備が整うまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。
個数:
ご購入には学生・教職員個人版の購入資格の確認が必要です。
小計
カートの中身を見る
Adobe Developer Connection / Flexデベロッパーセンター /

Building a Flex application that connects to a BlazeDS Remoting destination using Flash Builder 4

著者 Sujit Reddy G

Sujit Reddy G
  • sujitreddyg.wordpress.com

Content

  • Setting up the server environment
  • Developing the client application

Modified

17 May 2010

ページ ツール

Facebookでシェア
Twitterでツイート
LinkedInでシェア
ブックマーク
印刷

タグ

必要条件

この記事に必要な予備知識

Knowledge of J2EE containers, Adobe Flex, and Java will be helpful.

ユーザーレベル

すべて

必要な製品

  • Flash Builder 4 (Download trial)
  • BlazeDS (Download trial)

サンプルファイル

  • flashbuilder4_blazeds_source.zip (7 KB)

Additional Requirements

Apache Tomcat

  • Learn more

This article explains how to create a Flex application in Flash Builder 4 that invokes a method in a Java class on the server using BlazeDS Remoting service. After you set up the server environment required for the sample application, you’ll use Flash Builder 4 to generate ActionScript service classes and build a Flex application that displays the service call results.

Setting up the server environment

The first step is to create a Java class to be invoked from the Flex application. The sample application for this article uses the SimpleCustomerService class. This class has a method named getAllCustomers(), which will be invoked from the Flex application:

public class SimpleCustomerService { public ArrayList<SimpleCustomer> getAllCustomers() { ArrayList<SimpleCustomer> customers = null; //code to create ArrayList containing SimpleCustomer objects return customers; } }

Start by compiling SimpleCustomerService.java and SimpleCustomer.java in the <SampleZipFile>/java_src folder (or you can use the precompiled class files from the <SampleZipFile>/java_classes folder).

To create a web application that uses the class files, follow these steps:

  1. If you don’t already have Tomcat installed, install it now. See http://tomcat.apache.org/ for download information and more details.
  2. Find the folder webapps in your Tomcat installation directory. On Windows the default location is C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps.
  3. Create a folder named samplewebapp under the webapps folder to create the new web application.
  4. Copy the Java class files SimpleCustomerService.class and SimpleCustomer.class to webapps/samplewebapp/WEB-INF/classes under appropriate sub folders reflecting the package hierarchy.

Set up BlazeDS

Before you can invoke the Java class from the Flex application you must expose the class as a Remoting service destination using BlazeDS. To set up BlazeDS for your web application you have to deploy BlazeDS JAR files in your web application source path. Follow these steps to set up BlazeDS:

  1. Download the latest release build of BlazeDS, which has the JAR files and other configuration files you’ll need. If you want to use the earlier builds of BlazeDS or LiveCycle Data Services ES, you will need to perform the steps outlined in my blog post on this topic.
  2. Extract the zip file you downloaded into a folder. In the folder you will now have blazeds.war, which contains the required JAR files and configuration files for setting up BlazeDS, and blazeds-bin-readme.htm, which contain terms, conditions, and license details.
  3. Extract the contents of blazeds.war into a separate folder named blazeds. (You can use WinZip or a similar tool to extract the contents of the WAR file.)
  4. Copy all JAR files from blazeds/WEB-INF/lib to samplewebapp/WEB-INF/lib.
  5. Copy the blazeds/WEB-INF/flex folder to samplewebapp/WEB-INF

    This folder contains BlazeDS configuration files, which are used to configure Remoting, Messaging, and Proxy services.

  6. If you don’t already have a web.xml file that you want to use, copy blazeds/WEB-INF/web.xml to samplewebapp/WEB-INF.

Next, you need to add Servlet mapping for the BlazeDS Servlet named MessageBrokerServlet, so that BlazeDS is invoked when you send a request to a Remoting, Messaging, or Proxy destination using any of the channels supported.

If you are using your own web.xml file, then you’ll need to add the code below. Alternatively, you can copy it from blazeds/WEB-INF/web.xml.

<!-- Http Flex Session attribute and binding listener support --> <listener> <listener-class>flex.messaging.HttpFlexSession</listener-class> </listener> <!-- MessageBroker Servlet --> <servlet> <servlet-name>MessageBrokerServlet</servlet-name> <display-name>MessageBrokerServlet</display-name> <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class> <init-param> <param-name>services.configuration.file</param-name> <param-value>/WEB-INF/flex/services-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>MessageBrokerServlet</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping>

Flash Builder 4 uses RDSDispatchServlet (bundled with BlazeDS and LiveCycle Data Services ES2) to get service destination details in a web application. If you’re using your own web.xml file, add Servlet mapping for RDSDisptachServlet in your web application by copying the following XML snippet into the samplewebapp/WEB-INF/web.xml file under the <web-app> node.

<servlet> <servlet-name>RDSDispatchServlet</servlet-name> <display-name>RDSDispatchServlet</display-name> <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class> <init-param> <param-name>useAppserverSecurity</param-name> <param-value>false</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> <servlet-mapping id="RDS_DISPATCH_MAPPING"> <servlet-name>RDSDispatchServlet</servlet-name> <url-pattern>/CFIDE/main/ide.cfm</url-pattern> </servlet-mapping>

Create a Remoting destination

To expose a Java class as a Remoting destination you need to add a <destination> node in the samplewebapp/WEB-INF/flex/remoting-config.xml file under the <service> node as shown below. (You can find the remoting-config.xml and services-config.xml files used for the sample application in the <SampleZipFile>/config folder.)

<destination id="SimpleCustomerServiceDestination"> <properties> <source>com.adobe.services.SimpleCustomerService</source> </properties> </destination>

When you start your web server, BlazeDS will expose your Java class as a Remoting destination with SimpleCustomerServiceDestination as the id.

Developing the client application

Now that the server is set up, you are ready to use Flash Builder 4 to generate code for consuming the Remoting service destination. The Flex application will invoke the getAllCustomers() method in the destination you created.

To generate ActionScript code that can consume a Remoting service destination, Flash Builder will send a request to the BlazeDS or Adobe LiveCycle Data Services ES2 enabled web application you configured in the project server settings and retrieve details of the exposed service destinations.

Follow these steps to create the new Flex project:

  1. Choose File > New > Flex Project.
file
Figure 1. Setting project properties
  1. For the Project Name, type BlazeDSSample.
  2. Select Web (Runs In Adobe Flash Player) as the application type.
  3. Select J2EE as the Application Server Type.
  4. Select Use Remote Object Service and then select BlazeDS (see Figure 1).
  5. Click Next to continue.
file
Figure 2. Configuring server settings

Because you set the server type to J2EE in the project properties window, Flash Builder will prompt you for server settings.

  1. To configure the J2EE server, set the Root Folder to the path of the root folder of your web application that has been configured for BlazeDS.
  2. Set the Root URL to the URL of the root of the web application; for example, http://localhost:9191/samplewebapp.
  3. Set the Context Root to context root of the web application; for example, /samplewebapp.
  4. Leave the default value for the Output Folder, which will be on the server
  5. Click Validate Configuration to check if the server configuration is valid. If it is not valid, verify your settings and try again.
  6. When your server configuration is valid, click Finish to create the project.

Creating a new service

Follow these steps to create a new service in Flash Builder 4:

  1. Locate the Data/Services view in Flash Builder 4; if the view is not open, select Window > Data/Services.
  2. Click Connect to Data/Service (or choose Data > Connect to Data/Service). Flash Builder 4 displays list of service types that can be consumed from the current Flex project.
file
Figure 3. Select service type
  1. In this sample, you are using a BlazeDS service, so select BlazeDS as shown in Figure 3.
  2. Click Next.
  3. If Flash Builder 4 prompts for an RDS password just select No Password Required and then click OK. (This works because the useAppSecurity parameter of RDSDispatchServlet is set to false in web.xml.)

    Flash Builder communicates with the server and displays list of exposed service destinations as shown in Figure 4.

file
Figure 4. List of available destinations
  1. Select SimpleCustomerServiceDestination from the list and click Finish. If your application has more than one destination, you can select any destination from the list for which you want code to be generated.

Flash Builder 4 generates an ActionScript class that represents the Java class associated with the selected Remoting service destination. In this case, Flash Builder 4 generated a class named SimpleCustomerServiceDestination, which has functions for each public method exposed in SimpleCustomerService.java. To invoke a method of SimpleCustomerService.java on the server, you simply invoke the corresponding function in SimpleCustomerServiceDestination.as. You can see the service (SimpleCustomerServiceDestination.as) and its operations (representing functions in the service class) listed in the Data/Services view; you can also view the code using the Package Explorer.

If there are any custom data types used as a return type or as arguments in the Java class methods, Flash Builder 4 will generate an ActionScript class to represent the custom data type along with the service class files. In this sample getAllCustomers() returns an ArrayList containing SimpleCustomer object types. The ArrayList is a built-in data type and is converted to ArrayCollection on the client side by default. SimpleCustomer, however, is not a built-in data type so Flash Builder 4 generated SimpleCustomer.as with properties for each public property in SimpleCustomer.java to represent the SimpleCustomer objects returned from server. Note that the operation return types for the service are also properly configured in the Data/Services view based on the return type of the methods in the Java class.

Now that the code required to consume a Remoting service destination has been generated, follow the steps in the next section to display the response from the service call in a UI control.

Binding service call results to UI controls

Flash Builder 4 can also generate code to invoke a service call and bind the service call result to a UI control. In this sample you will bind the result of the getAllCustomers() operation to a DataGrid.

  1. Add a DataGrid control to the application in Design view.
  2. Right-click the DataGrid and select Bind To Data.
file
Figure 5. Selecting the service and operation
  1. In the Bind To Data dialog box that appears, Select New Service Call.
  2. Select SimpleCustomerServiceDestination from the services list and select getAllCustomers():SimpleCustomer[] from the list of operations as shown in Figure 5.
  3. Select SimpleCustomer[] as the Data Provider. Click OK.

Because you selected New Service Call, Flash Builder 4 will create a new instance of the SimpleCustomerServiceDestination class and a CallResponder class in the current MXML file. If an instance of SimpleCustomerServiceDestination already exists only the CallResponder instance will be created. The CallResponder class helps you manage the results for asynchronous calls made to RPC-based services. You can find more details on CallResponder in the Flex Language Reference.

Note: If you already have a service call in the current MXML file and you want to bind its result to the UI control, then select Existing Call Result in the Bind To Data dialog box and choose the existing service call.

Save your application and run it. After the Flex application launches in a web browser, it will invoke the getAllCustomers() method in the SimpleCustomerService Java class on the server and displays the SimpleCustomer objects returned from the server in the DataGrid.

Where to go from here

Now that you have used Flash Builder 4 to develop a Flex application that sends a request to a BlazeDS Remoting service destination and displays the response in a DataGrid, you may want to look for opportunities to use this approach in your own applications. You can expose any Java class as a BlazeDS or LiveCycle Data Services ES2 Remoting service destination and build a Flex application in Flash Builder 4 to consume that destination.

You can also use Flash Builder 4 to build Flex applications for HTTP services, web services, and the data management services in LiveCycle Data Services ES2. You can learn more in the article Data-centric development with Flash Builder 4.

If you are developing a data-centric application, you should also take some time to understand the data management and model-driven development capabilities of LiveCycle Data Services ES2. The LiveCycle Data Services ES2 Quick Starts is an excellent resource to help you hit the ground running.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Building a Flex application that connects to a BlazeDS Remoting destination using Flash Builder 4.5
  • Data paging with Flex and PHP using Flash Builder 4
  • Learn the advanced features of remoting with Flex
  • ColdFusionおよびFlash Builder 4ベータ版入門
  • Working with Doctrine 2, Zend AMF, Flex, and Flash Builder
  • Set up and build your first Flex and ColdFusion application – Part 1: Database setup
  • Set up and build your first Flex and ColdFusion application – Part 2: Generating ColdFusion components
  • Understanding Flex in the client/server model
  • DigiPri Widgets sales dashboard – Part 2: Setting up the server application
  • Flash Builder 4 and PHP – Part 2: Zend AMF and Flash Remoting

製品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • モバイルアプリ
  • Photoshop
  • Touch Apps

ソリューション

  • デジタルマーケティング
  • コンテンツオーサリング
  • Web Experience Management

業種別ソリューション

  • 教育
  • 金融機関

サポート

  • ヘルプ&サポート
  • 注文と返品
  • ダウンロードに関するヘルプ
  • ユーザー登録に関するヘルプ

ラーニング

  • ADC: Adobe Developer Center
  • Adobe TV
  • Design Magazine
  • Photoshop Magazine
  • Focus In

ご購入方法

  • アドビストア
  • アカデミックストア
  • アドビライセンスストア
  • ボリュームライセンスについて
  • 販売パートナー
  • キャンペーン情報

ダウンロード

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

会社情報

  • プレスルーム
  • パートナープログラム
  • 企業の社会的責任(英語)
  • 採用情報
  • 投資家の皆様へ(英語)
  • イベント&セミナー
  • Legal(英語)
  • セキュリティ
  • お問い合わせ
国・地域および言語の選択 日本(変更)
国・地域および言語の選択 閉じる

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

利用条件 | プライバシーポリシーとCookie (更新)

Reviewed by TRUSTe: site privacy statement