Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. The AJAX Architecture and Scripting Services with E4X Paul Fremantle VP of Technology WSO2 [email protected] www.wso2.com Thanks to Anthony Elder, IBM, who co-wrote the examples, and IBM who supported much of the effort in putting this together Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. About the Presenter (cid:1) Ex-IBM Senior Technical Staff Member (cid:3) Led the creation and development of • IBM Web Services Gateway • Web Services Invocation Framework • JWSDL / WSDL4J (cid:1) VP of Technology at WSO2 (cid:3) www.wso2.com (cid:3) A startup aiming to develop and support leading edge Open Source Web services software • Provides support, training and consultancy for Apache Axis 1.x (cid:1) Co-Chair of the OASIS WS-Reliable eXchange Technical Committee (cid:3) http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=ws-rx (cid:1) Co-author of “Building Web Services in Java 2nd Edition” (cid:1) Blog http://www.bloglines.com/blog/paulfremantle Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. Contents (cid:1) Introducing AJAX (cid:1) Advantages (cid:1) Building AJAX clients for REST services (cid:1) Rest and SOAP (cid:1) Introducing E4X (cid:1) Sample browser code (cid:1) Writing server logic in E4X (cid:1) Conclusions Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. Introducing AJAX (cid:1) Asynchronous JavaScript and XML (cid:3) The practice of using “under the covers” XML/HTTP conversations to enrich a web page (cid:3) The requests do not constitute page refresh (cid:3) Results in more intuitive applications (cid:3) Remember the “network is the computer”? • The network is the application? (cid:3) Examples: • Google – Maps, Mail, autocomplete • Google maps can scroll round indefinitely, pulling in information from the network as needed Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. Why Use AJAX? (cid:1) Er… it’s the latest thing? (cid:1) Subliminal validation (cid:3)Checking entries while the user is typing (cid:3)Prompting users with possible answers (cid:3)Minimising network delays by interleaving network activity with user activity Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. Normal Web Application User active User waiting GET HTML form (new page) User active User waiting browser POST server HTML form (validated) User active User waiting POST HTML response User active User gets form, submits, returned with marked errors, resubmits, reads response Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. AJAX Web Application User active User waiting GET HTML form (new page) browser server XMLHttpRequest User active XMLHttpRequest XMLHttpRequest XMLHttpRequest - No page refreshes – user is always in control - Validation of one field can happen while user is typing another. - Validation can be less intrusive (like changing the graphical attributes Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. How Does It Work? (cid:1) XMLHttpRequest (cid:3)Introduced in IE (cid:3)Supports programmatic sending of HTTP requests and parsing the results (cid:3)Not tied to XML – but much easier to correctly parse (cid:3)Usually uses DOM for parsing the XML Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. Getting an XMLHttpRequest (cid:2) Er… there is no standard, cross-browser, single syntax (cid:1) (cid:2) Microsoft syntax: (cid:4) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); • or (cid:4) xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”); (cid:2) Everyone else (cid:4) xmlhttp = new XMLHttpRequest(); Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:1) Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, WSO2 Inc. One Size Fits All Code var xmlhttp=false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } (cid:2) Thanks to: • http://jibbering.com/2002/4/httprequest.html Paul Fremantle — The AJAX Architecture and Scripting Services with E4X Page (cid:2)(cid:1)
Description: