Use flash Builder 4 Beta to establish a flex application to connect to the remote end of blazeds

Source: Internet
Author: User
Configure the server environment:


Step 1: Create a Java class called by the flex application. The application in this article uses the simplecustomerservice class, and the method of this class is namedgetAllCustomers()
, Will be called in the flex application:

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

Compile<Samplezipfile>/java_src
FolderSimplecustomerservice. Java
AndSimplecustomer. Java
Start (or you can<Samplezipfile>/java_classes
Folder ).

To create a web application using a class file, follow these steps:

  1. If Tomcat is not installed, install Tomcat now to http://tomcat.apache.org /*
    Find download information and more details.
  2. FindWebapps
    In Windows, the default path is:C:/program files/Apache Software Foundation/tomcat 6.0/webapps
    .
  3. InWebapps
    Folder, namedSamplewebapp
    To create a new Web application.
  4. Copy a Java FileSimplecustomerservice. Class
    AndSimplecustomer. Class
    ToWebapps/samplewebapp/WEB-INF/classes
    Below.
Install blazeds

Before calling the Java class from a flex application, you must use the blazeds display class as the remote service terminal. To configure the blazeds file for your web application, you must deploy the blazeds JAR file in the Web application source path. Perform the following steps to install blazeds:

  1. Download the latest nightly build of blazeds *
    Binary release version, which contains the JAR file and other configuration files you need. If you use earlier versions of blazeds or livecycle Data Services es, you need to perform the steps in addition to the above in my blog *
    This topic is described in detail.
  2. Decompress the downloaded ZIP file.Blazeds. War
    It contains the jar files required for configuring blazeds and other configuration files,Blazeds-bin-readme.htm
    Contains details such as contracts, conditions, and certificates.
  3. ExtractBlazeds. War
    The content is named separatelyBlazeds
    (You can use WinZip or similar tools to decompress the content in the war file ).
  4. SlaveBlazeds/WEB-INF/lib
    Copy all jar filesSamplewebapp/WEB-INF/lib
    .
  5. CopyBraazeds/WEB-INF/flex
    FolderSamplewebapp/WEB-INF

    This folder contains the configuration file blazeds. This configuration file is used to configure remote, message, and proxy services.

  6. If you do not want to useWeb. xml
    File, copyBlazeds/WEB-INF/Web. xml
    ToSamplewebapp/WEB-INF
    .

Next, you need to add the Servlet Mapping name to the blazeds servlet: messagebrokerservlet, so that you can call blazeds when you send requests to remote, message, or proxy services through any channel.

If you are using your ownWeb. xml
File, you need to add the following code, or you canBlazeds/WEB-INF/Web. xml
Copy this code.

<!-- 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 4RDSDispatchServlet
(BIND blazeds and livecycle Data Services ES2) to obtain the server details in the Web application. If you are using your ownWeb. xml
File, you needRDSDisptachServlet
Add Servlet Mapping and copy the following XML snippet<web-app>
Under the nodeSamplewebapps/WEB-INF/Web. xml
File.

<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 remote target

To display the Java class as a remote target, you need<service>
Under the nodeSamplewebapps/WEB-INF/flex/remoting-config.xml
File<destination>
Nodes, as shown below. (In<Samplezipfile>/config
You will findRemoting-config.xml
AndServices-config.xml
Files are used in applications .)

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

When you start your web service, blazeds will expose your Java class as a remote terminalSimpleCustomerServiceDestination
As the ID.

Develop Client Applications


Because the server has been created, you should use flash Builder 4 to generate code for consuming remote service targets. The flex application will callgetAllCustomers()
Method.

Generates the ActionScript code that can consume remote service terminals, flash builder will send a request to blazeds or Adobe livecycle Data Services ES2 to activate the web application you configured in the Project Server settings and retrieve the details of the external server terminal.

Follow these steps to create a new Flex project:

  1. Select File> New> flex project.


    Figure 1.
    Set Project Properties

  2. Name the projectBlazedssample
    .
  3. Select runs in Adobe Flash Player as the application type.
  4. Select J2EE as the application service type.
  5. Select use remote object service, and then select blazeds (1 ).
  6. Click Next to continue.


    Figure 2.
    Configure Server Settings

    Because you set the server type to J2EE in the Project Properties window, flash builder will prompt you to set the server.

  7. Configure the J2EE server and set the root folder: the path of the root folder in the Web application that you have configured in blazeds.
  8. Set the root URL as the root directory of the Web application URL. For example:Http: // localhost: 9191/samplewebapp
    .
  9. Set context root (context root directory): the context root directory of the Web application. For example:/Samplewebapp
    .
  10. Retain the default value of output folder on the server.
  11. Click Validate configuration to check whether the server configuration has taken effect. If not, adjust your settings and try again.
  12. After your configuration takes effect, click Finish to create a new project.
Create a new service

To create a new service in Flash Builder 4, follow these steps:

  1. Find the data/services view in Flash Builder 4. If the view is not opened, select Window> data/services.
  2. Click Connect to data/service (link to data/Service) (or choose data> connect to data/service ), flash Builder 4 displays the types of services that can be consumed from the current flex project.


    Figure 3.
    Select Service Type

  3. In this example, the blazeds service is used, so select blazeds as shown in figure 3.
  4. Click Next.
  5. If Flash Builder 4 prompts the RDS password, select no password and click OK. (This job isWeb. xml
    MediumRDSDispatchServlet
    OfuseAppSecurity
    The parameter is setfalse
    .)

    Flash builder communicates with the server. A list of external service targets is displayed, as shown in figure 4.


    Figure 4.
    Valid terminal list

  6. Select simplecustomerservicedestination from the list and click Finish. If your application has more than one target, you can select any target in the list to generate the desired code.

Flash Builder 4 generates the ActionScript class, which represents the Java class related to the selected remote service target. In this example, the class name generated by flash Builder 4 isSimplecustomerservicedestination
InSimplecustomerservice. Java
Parameters of each common method displayed in. To call simplecustomerservice. Java on the server, you only need to callSimplecustomerservicedestination.
. You can see that the Service (Simplecustomerservicedestination.
) And its operations (functions representing the server class) are listed in the data/services view. You can also view the code in the package browser.

If any custom data type is used as the return type or as a Java class method parameter, flash Builder 4 will generate an ActionScript class to represent the Custom Data Type together with the service class file. In this example,getAllCustomers()
ReturnsArrayList
.ArrayList
Is to create a data type and be convertedArrayCollection
. Simplecustomer is not a data type, so flash Builder 4Simplecustomer. Java
Generate for each public attributeSimplecustomer.
Attribute to represent the simplecustomer object returned from the server. Note that the Operation Return service type should also be properly configured in the data/services view of the method based on the return type in the Java class.

Since the Code required to consume the remote service target has been generated, the following steps are displayed in the response from the service request in the UI control.

Bind service request results to the UI component

Flash Builder 4 can also generate code to call a service request and bind the service request result to the UI component. In this example, you will bindgetAllCustomers()
Returns the operation result to the DataGrid.

  1. Add the DataGrid component in the application design view.
  2. Right-click the DataGrid and select bind data.


    Figure 5.
    Select services and operations

  3. The BIND data dialog box is displayed. Select "new service call )".
  4. From the "service" list, select simplecustomerservicedestination; from the "operation" list, select getallcustomers (): simplecustomer [], as shown in Figure 5.
  5. Click "OK )".

Because you choose "New service call", flash Builder
4. A new simplecustomerservicedestination class instance will be created, and
Callresponder class. If the simplecustomerservicedestination instance already exists, the only callresponder
The instance is created. The callresponder class helps you manage the asynchronous request results to the RPC-based service. Parameters in the flex Language
More details about callresponder are found.

Note:
If you already have a service request in the current mxml file and want to bind the result to the UI component, bind to data) "select an existing request result in the dialog box and select an existing service request.

Save your application and run it. After the flex application is released in the web browser, it will callgetAllCustomers()
And display the simplecustomer object returned from the server in the DataGrid.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.