1 / 26

Three - Tier No More: Integration - Ready Applications with AJAX and WS

Three - Tier No More: Integration - Ready Applications with AJAX and WS Samisa Abeysinghe ( samisa@wso2.com ) WSO2 Inc. Who am I?. A developer Apache Axis2/C and Axis C++ Member of Apache Software Foundation Software Architect WSO2 Inc. Agenda. Three-tier to Two-tier

tania
Download Presentation

Three - Tier No More: Integration - Ready Applications with AJAX and WS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Three - Tier No More: Integration - Ready Applications with AJAX and WS Samisa Abeysinghe (samisa@wso2.com) WSO2 Inc.

  2. Who am I? • A developer Apache Axis2/C and Axis C++ • Member of Apache Software Foundation • Software Architect WSO2 Inc.

  3. Agenda • Three-tier to Two-tier • XMLHttpRequest Characteristics • Introducing SOAPHttpRequest • Consuming Web Services • WS-* Support • REST vs. SOAP • Present and the Future

  4. Three-tier to Two-tier Web Client Web Server App Server HTTP SOAP Web Client App Server HTTP / SOAP

  5. Case for Dropping a Tier • Web services – SOAP over HTTP • Web browser can handle XML • Let browser talk SOAP

  6. First Generation - XMLHttpRequest • Construct XML representing SOAP envelope • SOAP is XML<envelope> <header>...headers...</header> <body>...payload...</body></envelope> • Send over HTTP • Concerns • You need to build the request SOAP envelope • Need to strip SOAP in response

  7. First Generation Example xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", "http://api.google.com/search/beta2",true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { alert(xmlhttp.responseText) } } xmlhttp.setRequestHeader("Man", "POST http://api.google.com/search/beta2 HTTP/1.1") xmlhttp.setRequestHeader("MessageType", "CALL") xmlhttp.setRequestHeader("Content-Type", "text/xml")

  8. First Generation Example (Contd.) xmlhttp.send("<?xml version='1.0' encoding='UTF-8'?>"+"\n\n"+ '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'+ '<soapenv:Body>'+ '<ns1:doSpellingSuggestion xmlns:ns1="urn:GoogleSearch"'+ ' soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'+ ' xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"'+ ' xmlns:xsd="http://www.w3.org/1999/XMLSchema">'+ '<key xsi:type="xsd:string">TcP7PPxQFHJtaZQO2OzWIPwdu2bUjYKD</key>'+ '<phrase xsi:type="xsd:string">salvasion</phrase>'+ '</ns1:doSpellingSuggestion>'+ '</soapenv:Body>'+ '</soapenv:Envelope>')

  9. Next Generation - SOAPHttpRequest • Let AJAX handle SOAP for you • You just worry about request payload and response payload • Inherited form XMLHttpRequest • Hence same familiar API • Benefit • SOAP envelope is handled for you

  10. Behind the Scenes • Used Apache Axis2/C as base • Implemented a Firefox extension • Extended Firefox AJAX API • Works both on Windows and Linux • Planning on an ActiveX object to support Microsoft IE

  11. Objectives for SOAPHttpRequest • Use an API similar to XMLHttpRequest • Shorten learning curve • Leverage the power of an existing SOAP engine • Axis2/C is written with integration in mind as a portable C library • Written to support full web services stack

  12. Consuming Web Services • Invoking Google spell checker:// create request object var req = new SOAPHttpRequest(); // set SOAP version to be SOAP 1.1 req.soapVer = 1.1; // set callback to be called on response req.onreadystatechange = listenStatus; // set up endpoint information; syntax:open(method, uri, isAsynchronous) req.open("POST", "http://api.google.com/search/beta2", false); // send request with payload req.send (reqContent);

  13. Consuming Web Services - Payload • XML payload build using DOM API//create the root nodevar req_node = document.createElementNS ("urn:GoogleSearch", "ns1:doSpellingSuggestion" );req_node. setAttribute ("xmlns:xsd", "http://www.w3.org/2001/XMLSchema" );//create the node for keyvar key_node = document.createElement ("key");key_node. setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:string" );var key_text = document.createTextNode (key );key_node.appendChild(key_text);//create the node for phrase|var phrase_node = document.createElement ("phrase");phrase_node. setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:string" );var phrase_text = document.createTextNode (phrase);phrase_node. appendChild(phrase_text );//attach nodesreq_node. appendChild (key_node );req_node. appendChild (phrase_node );reqContent = req_node; //attach nodesreq_node. appendChild (key_node );req_node. appendChild (phrase_node );reqContent = req_node;

  14. Consuming Web Services - Callback • Captures result// responseXML contains response domvar resultContent = req. responseXML;// Process result content as you wishHandleResponse (resultContent);

  15. <?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:doSpellingSuggestionResponse xmlns:ns1="urn:GoogleSearch" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <return xsi:type="xsd:string">tungsten</return> </ns1:doSpellingSuggestionResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> XML in/out Model Request <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header></soapenv:Header><soapenv:Body> <ns1:doSpellingSuggestion xmlns:ns1="urn:GoogleSearch" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <key xsi:type="xsd:string">wCumFQpQFHL7+coIxlNKUGtyVsgrVAnb</key> <phrase xsi:type="xsd:string">tungsston</phrase> </ns1:doSpellingSuggestion> </soapenv:Body></soapenv:Envelope> Response

  16. Non-Blocking • Set the third parameter of open to true req.open("POST", "http://api.google.com/search/beta2", true);

  17. WS-* Support • Axis2/C designed to support WS-* • Concept of modules • WS-Addressing built in • WS-Security and WS-Reliable Messaging available as separate modules • Advantage of using Axis2/C as base • Any module available at C level freely available at AJAX level

  18. Axis2 Architecture

  19. WS-Addressing • SOAP Header sample<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> <wsa:To>http://localhost:9090/axis2/services/echo</wsa:To> <wsa:Action>http://ws.apache.org/axis2/c/samples/echoString</wsa:Action> <wsa:MessageID>cb00ebf2-39ad-1db1-36e2-001125ce1ac4</wsa:MessageID></soapenv:Header> • Need for addressing in enterprise • reply to : where to send the reply • fault to : where to send the fault • e.g. Booking flight: send bill to finance, if error let me know

  20. WS-Addressing with AJAX // engage addressing req.engage ( "addressing", "version" ); // set WSA action req.options({ wsa_action:"http://ws.apache.org/axis2/c/samples/echoString" } ); • API allows you to select the version • Addressing specific parameters could be set as options

  21. REST vs. SOAP • REST and SOAP are different religions • Both have devotees • At 30,000 feet • REST is light weight; SOAP is heavy weight • REST QoS based on transport; SOAP has array of message level QoS options • Both has use cases • You will need SOAP for some use cases

  22. Present • You can try WSO2 Tungsten Firefox (v 1.5.0.1) extension • Open source with Apache 2.0 license • http://dist.wso2.net/products/tungsten/ajax/xpi/installation.html • Can consume Web services with XML in/out model • WS-Addressing and WS-Security UsernameToken integrated • Can use both on Linux and Windows with Firefox

  23. Future • Full WS-Security, MTOM and WS-RM support • ActiveX object for Windows IE • WS-Policy, WS-Eventing coming up with Axis2/C • Would be available to AJAX extension

  24. Conclusion • Full power of Web services stack available to AJAX programmer • Familiar API • Based on well designed, proved Apache Axis2 Web services architecture • Designed by industry leaders • C implementation: fast and portable design

  25. Links • WSO2 Tungsten XPI • http://dist.wso2.net/products/tungsten/ajax/xpi/ • Apache Axis2/C • http://ws.apache.org/axis2/c/ • This Presentation • http://people.apache.org/~samisa/

  26. Thank you Time for Q&A

More Related