Accessibility

LiveCycle Developer Center

 

BlazeDS 30-minute test drive


Table of Contents

Sample 1: Accessing data using HTTPService

Run the sample:

  1. After installing the turnkey server, you can run the first sample application at http://localhost:8400/samples/testdrive-httpservice/index.html
  2. Click "Get Data". The DataGrid is populated with XML data returned by catalog.jsp
  3. Also notice some of the built-in DataGrid features:
    • Sortable columns (click on a column header)
    • Moveable columns (click on a column header and drag the column to a new position)

Code walkthrough:

Open main.mxml in the testdrive-httpservice/src directory to view the source code of the application.

Using the Flex HTTPService object, you can send HTTP requests to a server, and consume the response. Although HTTPService can be used to consume different types of responses, it is typically used to consume XML. You can use HTTPService with any kind of server-side technology: JSP, Servlet, ASP, Ruby on Rails, PHP, among others. You specify the target service in the url property of the HTTPService object.

Flex provides sophisticated data binding capabilities. You can bind the value of a property to the value of another property, or to an expression in general. In this example, the dataProvider property of the DataGrid is bound (using the curly braces notation) to the lastResult property of the HTTPService object.

HTTPService calls are asynchronous. The result event is triggered on the HTTPService when the data becomes available to the client application. The fault event is triggered if an error occurs on the server side, or if the network becomes unavailable. (For more information on coding result and fault event handlers, see "Sample 5: Updating Data").

By default, the XML document retrieved from the server is deserialized into an object graph. This allows you to navigate through the result using the dot (.) notation. You can also get the result as an XML document by specifying resultFormat="e4x" on the HTTPService. In that case, you can parse the document using E4X (ECMAScript for XML).

The BlazeDS server is not required to use the HTTPService. By default, the application tries to connect directly to the domain specified in the HTTPService url attribute. This will work if one of the two conditions below is satisfied:

  1. The domain specified in the HTTPService url attribute is the domain from which your application was downloaded.
  2. A crossdomain.xml file granting access to your application's originating domain is available on the domain specified in the HTTPService url attribute. More information on crossdomain.xml is available here.

If you want your application to access services available on another domain without deploying a crossdomain.xml file on that domain (for example, because you may not own the target domain), you can set the useProxy attribute of the HTTPService to true, as in this example. In this case, the request is sent to the BlazeDS proxy, which makes the request to the target domain on the client application's behalf. This configuration also provides more control over the access to the service. For example, you may configure the proxy to require authentication before accessing a service, log access to the service, and so on.

When using the proxy, you can specify a logical name in the HTTPService destination attribute instead of specifying a hardcoded value in the url attribute. You then map this logical name to an actual URL in the WEB-INF\flex\proxy-config.xml file. Open this file to see how the catalog destination is configured.

Note that both HTTP and HTTPS are supported. To use HTTPS, specify "https:://…" in the url.