Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 119 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
119
Dung lượng
0,97 MB
Nội dung
ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 703 • Specifying credentials in the Flex destination Specifying credentials in ActionScript To specify credentials in ActionScript, you use the setRemoteCredentials() method, as the following example shows: ds = new DataService(“mydest”); ds.setRemoteCredentials(“wilsont”, “password”); Specifying credentials in the Flex destination To specify credentials in the Flex destination, you edit the data-management-config.xml file that is in the WEB- INF/flex folder of the server on which you run the Flex application. In the properties element, you include the remote-username and remote-password elements, as follows: <destination id="cfcontact"> <adapter ref="coldfusion-dao" /> <channels> <channel ref="cf-dataservice-rtmp" /> </channels> <properties> <source>samples.contact.ContactAssembler</source> <scope>application</scope> <remote-username>wilsont</remote-username> <remote-password>password</remote-password> /properties> </destination> Enabling SSL You encrypt communication between ColdFusion and Flex by enabling Secure Sockets Layer (SSL). Enabling SSL only makes sense if you are running LiveCycle Data Services ES remotely. To use SSL, you must create a keystore file. The keystore is a self-signed certificate. (You do not require a certificate signed by a Certificate Authority, although if you do use one, you do not have to configure Flex as indicated in the following steps.) The information in the keystore is encrypted and can be accessed only with the password that you specify. To create the keystore, you use the Java keytool utility, which is included in your Java Runtime Environment (JRE). To enable SSL, you do the following: • Create the keystore • Configure Flex • Enable SSL in the ColdFusion Administrator Create the keystore 1 Generate the SSL server (ColdFusion) keystore file by using the keytool utility, with a command similar to the following: keytool -genkey -v -alias FlexAssembler -dname "cn=FlexAssembler" -keystore cf.keystore -keypass mypassword -storepass mypassword The following table describes the parameters of the keytool utility that you use: ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 704 Next, you place the certificate that you created in the file that the JVM uses to decide what certificates to trust. The file in which you put the certificate, (usually named cacerts), is located in the JRE, under the lib/security folder. Configure Flex 1 Export the keystore to a certificate by using the keytool utility, with a command similar to the following: keytool -export -v -alias FlexAssembler -keystore cf.keystore -rfc -file cf.cer 2 Import the certificate into the JRE cacerts file for your server by using the keytool utility, with a command similar to the following: keytool -import -v -alias FlexAssembler -file cf.cer -keystore C:\fds2\UninstallerData\jre\lib\security\cacerts The previous example specifies the location of the keystore for LiveCycle Data Services ES with integrated JRun, installed using the default settings. If you are using a different server, specify the location of the cacerts file for the JRE that you are using. For example, if you are using JBoss, you specify the keystore location as $JAVA_HOME/jre/lib/security/cacerts. Enable SSL in the ColdFusion Administrator 1 In the ColdFusion Administrator, select Data & Services > Flex Integration, and specify the keystore file in the Full Path to Keystore text box. 2 Specify the keystore password in the Keystore password text box. 3 Select the Enable RMI over SSL for Data Management option, and then click Submit Changes. If you specify an invalid keystore file or password, ColdFusion does not enable SSL, and disables Flex Data Management Support. Data translation The following table lists the ColdFusion data types and the corresponding Adobe Flash or ActionScript data type: Parameter Description -alias The name of the keystore entry. You can use any name for this, as long as you are consistent when referring to it. -dname The Distinguished Name, which contains the Common Name (cn) of the server. -keystore The location of the keystore file. -keypass The password for your private key. -storepass The password for the keystore. The encrypted storepass is stored in ColdFuison configuration files. -rfc Generates the certificate in the printable encoding format. -file The name of the keystore file. -v Generates detailed certificate information. ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 705 ColdFusion data type Flash data type String String Array [] = Array Struct {} = untyped Object Query ArrayCollection CFC Class = typed Object (if a matching ActionScript class exists, otherwise the CFC becomes a generic untyped Object (map) in ActionScript) CFC Date ActionScript Date CFC String ActionScript String CFC Numeric ActionScript Numeric ColdFusion XML Object ActionScript XML Object 706 Chapter 39: Using Server-Side ActionScript ColdFusion server configuration includes the Flash Remoting service, a module that lets Adobe Flash developers create server-side ActionScript. These ActionScript files can directly access ColdFusion query and HTTP features through two new ActionScript functions: CF.query and CF.http. Contents About server-side ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706 Connecting to the Flash Remoting service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709 Using server-side ActionScript functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709 Global and request scope objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710 About the CF.query function and data sources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711 Using the CF.query function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712 Building a simple application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 About the CF.http function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717 Using the CF.http function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718 About server-side ActionScript ColdFusion includes a module called the Flash Remoting service that acts as a broker for interactions between Flash and ColdFusion. Flash Remoting supports a range of object types, and lets you reference an ActionScript file that lives on a ColdFusion server. You can partition data-intensive operations on the server, while limiting the amount of network transactions necessary to get data from the server to the client. Flash developers can create server-side ActionScript files to access ColdFusion resources; they do not have to learn CFML (ColdFusion Markup Language). This ability lets you logically separate the Flash presentation elements of your applications from the business logic. You have the option of creating ActionScript files that reside on the server to partition this processing away from your client applications. You have a very simple interface for building queries using server-side ActionScript, and an equally simple interface for invoking these queries from your client-side ActionScript. Client-side ActionScript requirements On the client side, you only need a small piece of code that establishes a connection to the Flash Remoting service and references the server-side ActionScript you want to use. For example (notice the embedded comments): // This #include is needed to connect to the Flash Remoting service #include "NetServices.as" // This line determines where Flash should look for the Flash Remoting service. // Ordinarily, you enter the URL to your ColdFusion server. // Port 8500 is the Flash Remoting service default. ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 707 NetServices.setDefaultGatewayUrl("http://mycfserver:8500"); // With the Flash Remoting service URL defined, you can create a connection. gatewayConnnection = NetServices.createGatewayConnection(); // Reference the server-side ActionScript. // In this case, the stockquotes script file lives in the web root of the // ColdFusion server identified previously. If it lived in a subdirectory // of the web root called "mydir," you would reference it // as "mydir.stockquotes". stockService = gatewayConnnection.getService("stockquotes", this); // This line invokes the getQuotes() method defined in the stockquotes // server-side ActionScript. stockService.getQuotes("macr"); // Once the record set is returned, you handle the results. // This part is up to you. function getQuotes_Result ( result ) { // Do something with results } Note: Client-side ActionScript does not support the two new server-side ActionScript functions, CF.query and CF.http. Server-side requirements Creating ActionScript that executes on the server helps leverage your knowledge of ActionScript. It also provides direct access to ColdFusion query and HTTP features. The CF.query and CF.http ActionScript functions let you perform ColdFusion HTTP and query operations. Note: On the server side, ActionScript files use the extension .asr. For example, the following server-side ActionScript code builds on the client-side code shown previously: // Filename: stockquotes.asr // Here is the getQuotes method invoked in the client-side ActionScript. // It accepts a single stock quote symbol argument. function getQuotes(symbol) { // Query some provider for the specified stock quote and return the // results. In this case, the getQuotesFromProvider method is // defined elsewhere in this ActionScript code. data = getQuotesFromProvider(symbol); // Return the data to the client. // Note: this example does not include any of the error checking // logic you would normally use prior to returning the data. return data; } The getQuotes function conducts the stock quote request and returns the results of the request to the client as a RecordSet object. Software requirements To use server-side ActionScript files, you must have the following software installed: • Adobe Flash ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 708 • ColdFusion • Flash Remoting Components For more information about these products, go to www.adobe.com. Location of server-side ActionScript files You can place Ac t i onS c r ip t f i l e s ( *.asr) on the server anywhere below the web server’s root directory. To specify subdirectories of the web root or a virtual directory, use package dot notation (use dots instead of slashes in a fully qualified directory name). For example, in the following assignment code, the stockquotes.asr file is located in the mydir/stock/ directory: stockService = gatewayConnnection.getService("mydir.stock.stockquotes", this); You can also point to virtual mappings, such as cfsuite.asr.stock.stockquotes where cfsuite is a virtual mapping and asr.stock is subdirectories of that mapping. Benefits Server-side ActionScript lets your ActionScript engineers use their knowledge of ActionScript to write code for the back end of their Flash applications, which can mean more meaningful levels of interactivity for your users. Your Flash applications can share a library of server-side ActionScript functions, which means you can define functions that are specifically tailored to your own business. You could, for example, create a server-side ActionScript file that defines a whole library of SQL query methods. With these query methods defined on the server side, your Flash designers only have to invoke the specific query function they want to return data to their Flash movies. They do not have to write any SQL, and they do not have to create a new query every time they need to retrieve data from a ColdFusion data source. It is a way of creating reusable queries that your entire Flash design team can use. Coding the ColdFusion query and HTTP operations in ActionScript is very straightforward. The CF.query and CF.http functions provide a well-defined interface for building SQL queries and HTTP operations. For example, the following is a typical server-side ActionScript function definition that returns query data: // This function shows a basic CF.query operation using only // arguments for data source name and for SQL. function basicQuery() { mydata = CF.query({datasource:"customers", sql:"SELECT * FROM myTable"}); return mydata; } What to do next If you are already familiar with ActionScript, you only need to know a few things to get started: • How to establish a connection with the Flash Remoting service using client-side ActionScript. See “Connecting to the Flash Remoting service” on page 709 • How to reference server-side ActionScript functions and methods. See “Using server-side ActionScript functions” on page 709. • How to code the server-side CF.query and CF.http functions. See “Using the CF.query function” on page 712 and “Using the CF.http function” on page 718. Also see the reference pages for these functions in the CFML Reference. ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 709 For additional information on using Flash Remoting, see “Using the Flash Remoting Service” on page 674 and Using Flash Remoting. Connecting to the Flash Remoting service Before you can use functions defined in your server-side ActionScript files, you must connect the Adobe Flash movie to the server-side Flash Remoting service. Create a Flash Remoting service connection 1 Include the necessary ActionScript classes in the first frame of the Flash movie that will be using server-side ActionScript functions. a Use the following command to include the NetServices class: #include "NetServices.as" b (Optional) Use the following command to include the NetDebug class: #include "NetDebug.as" For more information about the NetDebug and RecordSet classes, see Using Flash Remoting. 2 Since the Flash Remoting service serves as a broker for calls to server-side ActionScript functions, you must identify the Flash Remoting service URL as an argument in the NetServices.setDefaultGatewayUrl function. For example: NetServices.setDefaultGatewayURL("http://localhost:8500/flashservices") You must specify a server hostname. The default port number for the Flash Remoting service is 8500. 3 Create the gateway connection using the NetServices.createGatewayConnection function; for example: gatewayConnection = NetServices.createGatewayConnection(); Using server-side ActionScript functions After you connect to the Flash Remoting service, you call functions that are defined in your server-side ActionScript files, and return results. Call a function 1 Create an instance of the server-side ActionScript file using the getService function. This function instantiates the server-side ActionScript file as an object to be used on the client side. For example: albumService = gatewayConnection.getService("recordsettest", this) Where recordsettest represents the name of the server-side ActionScript file, without the file extension .asr. 2 Call a function defined in your server-side ActionScript object. Use dot notation to specify the object name followed by the function name; for example: albumService.getAlbum("The Color And The Shape", "1999"); Where albumService is the instance of the server-side ActionScript file and getAlbum is a function that passes two arguments, "The Color and The Shape" and "1999". ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 710 Note: Arguments must occur in the order defined in the function declaration. 3 Handle the function results in ActionScript. See “Using the function results in ActionScript” on page 710. Using the function results in ActionScript To use the results returned by server-side ActionScript, you must create a corresponding results function. The results function uses a special naming convention that ties it to the function that calls the server-side ActionScript. For example, if you defined a client-side ActionScript function called basicCustomerQuery, you also must create a results function called basicCustomerQuery_Result. The results returned by server-side ActionScript functions differ somewhat depending on whether you are using CF.http or CF.query: • The CF.query function returns a record set, which you manipulate using methods available in the RecordSet ActionScript class object. See “Using results returned by the CF.query function” on page 710. • The CF.http function returns simple text strings through properties that you reference in your server-side ActionScript. See “Using results returned by the CF.http function” on page 710. Using results returned by the CF.query function You use functions in the RecordSet ActionScript object to access the data returned in a CF.query record set; for example, how many records are in the record set and the names of the columns. You can also use the RecordSet functions to pull the query data out of the record set. To do so, you reference a specific row number in the record set and use the getItemAt RecordSet function, as in the following example: // This function populates a Flash text box with data in the first row // of the record set under the "email" column name. function selectData_Result ( result ) { stringOutput.text = result.getItemAt(0)["email"]; _root.employeesView.setDataProvider(result); } In the example, the column name is referenced in the getItemAt function between square brackets [ ]. (In Action- Script, indexes start at 0, so getItemAt(0) returns the first row.) For more information, see “Using the CF.query function” on page 712. Using results returned by the CF.http function The CF.http server-side ActionScript function returns data as simple text. You write server-side functions that reference the properties available in the object returned by the CF.http function. These properties store the file content of the retrieved file, HTTP status codes, the MIME type of the returned file, and so on. On the client side, you create return functions to handle data returned by the CF.http function. You write these functions to handle simple text data. For more information, see “Using the CF.http function” on page 718. Global and request scope objects Global and request scope objects are implicitly available in all server-side ActionScript. The following table describes these scope objects: ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 711 For more information about these scope objects, see the documentation on the javax.servlet class at http://java.sun.com. About the CF.query function and data sources You use the CF.query function to populate Flash movie elements with data retrieved from a ColdFusion data source. To use the CF.query function you do the following: Pull data into your Flash movie from a ColdFusion data source 1 Create a server-side ActionScript file that performs queries against a ColdFusion data source. 2 Write ActionScript code in your Flash movie that references your ActionScript file (.asr) on the ColdFusion server. You create server-side ActionScript to execute the query and return the data in a record set to the client—your Flash movie. You can use methods in the RecordSet ActionScript object on the client to manipulate data in the record set and present data in your Flash movie. Note: Client-side ActionScript files use the .as extension. Server-side ActionScript files use the .asr (ActionScript remote) extension. Publishing dynamic data You use the server-side ActionScript feature in ColdFusion to publish dynamic data. To do this, you write server-side ActionScript files that perform queries against ColdFusion data sources. Before using ActionScript, you must under- stand how to do the following: • Create database queries in the server-side ActionScript file using the CF.query ActionScript function. See “Using the CF.query function” on page 712. • Reference the server-side ActionScript file in your Flash movie. See “Connecting to the Flash Remoting service” on page 709. Using the CF.query function, you can do the following tasks: Scope name Type Description config Global Initialization information for the server-side ActionScript adapter. Class: javax.servlet.ServletConfig application Global The context for the current web application. The context defines methods that provide, for example, the MIME type of a file that can be used to write to a log file. There is one context per web application. Class: javax.servlet.ServletContext request Request An object containing client request information. The object provides data, including param- eter name and values, attributes, and an input stream. Class: HttpServletRequest (subtype of javax.servlet.ServletRequest) response Request An object to assist in sending a response to the client. It provides HTTP-specific functionality in sending a response. Do not use the OutputStream or PrintWriter to send data back to the client. Class: HttpServletResponse (subtype of javax.servlet.ServletResponse) ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 712 • Create user login interfaces that validate users against a ColdFusion data source. • Populate form elements and data grids with data from a ColdFusion data source. • Create banners that pull data (such as URLs or image file paths) out of a database. The CF.query function can retrieve data from any supported ColdFusion data source (see “About ColdFusion data sources” on page 712). About ColdFusion data sources For ColdFusion developers, the term data source can refer to a number of different types of structured data accessible locally or across a network. You can query websites, Lightweight Directory Access Protocol (LDAP) servers, POP mail servers, and documents in a variety of formats. For server-side ActionScript, a data source ordinarily means the entry point to a ColdFusion database. Your ColdFusion administrator can help you identify and configure data sources. To create ActionScript files that successfully perform queries on ColdFusion data sources, you must know how the data source is identified by ColdFusion, as well as any other parameters that affect your ability to connect to that database, such as whether a user name and password are required to connect. You use server-side ActionScript in ColdFusion to return record set data to a Flash client from a ColdFusion data source. You specify the ColdFusion data source name and the SQL statement you execute on the data source as arguments in the CF.query function in server-side ActionScript. Typically, your server-side ActionScript handles the interaction with the ColdFusion data source, and returns a record set to the Flash client through the Flash Remoting service. For more detailed information about ColdFusion data sources, see Configuring and Administering ColdFusion. Using the CF.query function You use the CF.query function in your server-side ActionScript to retrieve data from a ColdFusion data source. This function lets you perform queries against any ColdFusion data source. Note: The CF.query function maps closely to the cfquery CFML tag, although it currently supports a subset of the cfquery attributes. Use the CF.query function to do the following: • Identify the data source you want to query. • Pass SQL statements to the data source. • Pass other optional parameters to the database. For reference information about the CF.query function, see CF.query in the CFML Reference. About CF.query function syntax You can w r ite t h e CF.query ActionScript function using either named arguments or positional arguments. The named argument style is more readable, but it requires more code. Although the positional argument style supports a subset of CF.query arguments, it allows a more compact coding style that is more appropriate for simple expres- sions of the CF.query function. [...]... “Creating the Flash movie interface” on page 71 5 3 Define a search function that sends user data to the Flash Remoting service See “Submitting user data to the Flash Remoting service” on page 71 6 4 Define a result function that captures the results returned from the Flash Remoting service See “” on page 71 6 ADOBE COLDFUSION 8 71 5 ColdFusion Developer’s Guide 5 Ensure that the Flash movie has established... [empty string] txtPhoneNum [empty string] ADOBE COLDFUSION 8 73 1 ColdFusion Developer’s Guide After submission by using HTTP post, the resulting structure might look like the following example: struct FORM1 struct SUBFORM struct HEADER struct HTTPSUBMITBUTTON1 [empty string] TXTDEPTNAME Sales TXTFIRSTNAME Carolynn TXTLASTNAME Peterson TXTPHONENUM (6 17) 872 -9 178 TXTEMPID 1 TXTEMAIL carolynp@company Note:... contain complex field names For example an Acrobat form might contain the following fields: form1.x.f1, form1.x.f2, form1.x.f3, and so on ADOBE COLDFUSION 8 72 7 ColdFusion Developer’s Guide Because the cfpdfparam tag does not handle field names with periods in them, ColdFusion treats forms with complex field names created in Acrobat the same way as subforms created in LiveCycle Therefore, the result structure... text/html; charset=EUC-JP Header Raw response header The following is an example header : HTTP/1.1 200 OK Date: Mon, 04 Mar 2002 17: 27: 44 GMT Server: Apache/1.3.22 (Unix) mod_perl/1.26 Set-Cookie: MM_cookie=2 07. 22.48.162. 473 1015262864 476 ; path=/; expires=Wed, 03-Mar-04 17: 27: 44 GMT; domain=.adobe.com Connection: close Content-Type: text/html Filecontent File contents, for text and MIME files Mimetype... files However, XML files are not user-friendly: to view the file in its original format, the user has to open the PDF form template in Acrobat and import the XML data file ADOBE COLDFUSION 8 72 5 ColdFusion Developer’s Guide ColdFusion automates the process of reuniting XML data with the PDF form that generated it To do this, you use the populate action of the cfpdfform tag, specify the source, which... { dataView.setDataProvider(resultset); status.text = (0+resultset.getLength())+" names found."; } Reviewing the code The following table describes the code and its function: ADOBE COLDFUSION 8 71 7 ColdFusion Developer’s Guide Code Description function search_Result (resultset) The _Result suffix tells the Flash Remoting service to return the results of the search function to this function dataView.setDataProvider... files Also, JavaScript differs between forms created in Acrobat and those created in LiveCycle: scripts written in one format do not work with other ColdFusion 8 introduced several tags for manipulating PDF forms: ADOBE COLDFUSION 8 72 4 ColdFusion Developer’s Guide Tag Description cfpdfform Reads data from a form and writes it to a file or populates a form with data from a data source cfpdfformparam A... file to be written It is a combination of the user name and the current date -> ADOBE COLDFUSION 8 73 3 ColdFusion Developer’s Guide ColdFusion Likewise, the field names in the cfpdfformparam tags must match the field... ADOBE COLDFUSION 8 73 7 ColdFusion Developer’s Guide Office Supply Request Form Please... in ColdFusion 72 3 Assembling PDF Documents 73 9 Creating and Manipulating ColdFusion Images 76 3 Creating Charts and Graphs 78 5 Creating Reports and Documents for Printing . Ordinarily, you enter the URL to your ColdFusion server. // Port 8500 is the Flash Remoting service default. ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 70 7 NetServices.setDefaultGatewayUrl("http://mycfserver:8500");. function” on page 71 2 and “Using the CF.http function” on page 71 8. Also see the reference pages for these functions in the CFML Reference. ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 70 9 For additional. javax.servlet.ServletResponse) ADOBE COLDFUSION 8 ColdFusion Developer’s Guide 71 2 • Create user login interfaces that validate users against a ColdFusion data source. • Populate form elements and data grids with data from a ColdFusion