140 likes | 228 Views
WDDX Case Study: Building a Cross CFUG Search. April Fleming. Introduction. “ Real world WDDX (not just a short introduction)” Problem I encountered developing an application How I used WDDX to solve the problem Benefits of using WDDX. Scenario .
E N D
WDDX Case Study: Building a Cross CFUG Search April Fleming
Introduction “Real world WDDX (not just a short introduction)” • Problem I encountered developing an application • How I used WDDX to solve the problem • Benefits of using WDDX
Scenario • Data stored on 3 separate servers across the country • Using CFHTTP to access remote server • Remote server built query searching all fields on criteria entered by user. • Remote server performs query, outputs the query results with a set of predetermined display fields • Local server parses query results, stores each parsed record in a database, to be used and displayed.
Problem • Parsing routine had to be written • If remote server output changed the parsing routine would no longer work until it was modified. • Required strict communication/cooperation between nodes, not practical • Needed to allow user to search on any given field, using logical operators • EX: “FirstName contains ‘A’ and FirstName contains ‘B’ • Needed knowledge of data on remote server to avoid rewriting the parsing routine if the remote server changed its structure • Needed to allow user to specify any or all fields to display in search results in any given order. • Needed knowledge of data on remote server to give user all possible return fields • Local parsing routine needed to be able to parse any possible combination of fields returned by remote server.
Problem - cont’d • Storing Search Results • Needed to be able to store any given set of fields in any order • Current storage of search records to local table could not accommodate • If we stored return fields as text, could not access them as a recordset • Individually inserting records into the database was processor intensive and very slow. • All of the writing and reading from the ACCESS database were causing it to be corrupt.
Solution Enter WDDX….
What is WDDX? • WDDX is a tag Markup language written in XML. • The markup language describes the data which is being “marked up” • Serialization and Deserialization functions written for CFML, ASP, JavaScript,Java, PERL, and Python • Facilitates passing objects • Recordsets • Arrays • Structures
WDDX Tag • <CFWDDX ACTION="" • INPUT="" • OUTPUT="" TOPLEVELVARIABLE="”> • ACTION: • CFML2WDDX - Serialize to WDDX Format • WDDX2CFML - Deserialize WDDX to CFML • CFML2JS - Serialize CFML to Javascript • WDDX2JS - Deserialize WDDX to Javascript • INPUT - Data to be “Serialized/Deserialized” • OUTPUT - Output variable for Serialized/Deserialized Data • TOPLEVELVARIABLE - Output variable for Javascript Object
Terms • Serialize - converting data to WDDX format • Deserialize - extracting data in native language format • Packet - serialized data
WDDX In Action • Had the remote server output a WDDX packet describing their data • Does not matter what language they use • Used <CFWDDX> to deserialize their packet • Was able to output over the deserialized query to create form for users to choose the fields they want to search • Used <CFWDDX> to serialize a structure containing search criteria. • Remote server outputs search results in packets • Local server deserializes results packets and manipulates as if queries had been run locally
Benefits • Parsing routine was already written, performed by WDDX tag • Remote server could return any data, WDDX packets are self-describing • User could specify any fields since parser could now parse any fields returned. • Packets could be written to files, or entire packets could be stored in database requiring less load on the database. • Surprisingly fast!
Other Uses for WDDX • Syndication • Stocks quotes • News feeds • http://cfug.itcenter.org/ - Greg Witte’s Digital Daily • Using JavaScript to allow for multiple user input for a given field • Parent/child relationship • Multiple phone numbers • Transferring Data from Browser to Server • Wizard interface • Maintain state in an inherently stateless medium
Resources • http://www.wddx.org/ • http://www.allaire.com/developer/ • http://www.xml.Com/ • Advanced ColdFusion 4.0 application development (ISBN 0-7897-1810-3) • Advanced ColdFusion development • XML journal (http://www.coldfusionjournal.Com/)