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

About This Presentation
Title:

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

Description:

Behind the Scenes. Used Apache Axis2/C as base. Implemented a Firefox extension ... Leverage the power of an existing SOAP engine ... create the root node ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 27
Provided by: people4
Learn more at: http://people.apache.org
Category:

less

Transcript and Presenter's Notes

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


1
  • Three - Tier No More Integration - Ready
    Applications with AJAX and WS
  • Samisa Abeysinghe (samisa_at_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 XMLltenvelopegt ltheadergt...headers...lt/he
    adergt ltbodygt...payload...lt/bodygtlt/envelopegt
  • 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/searc
    h/beta2",true)
  • xmlhttp.onreadystatechangefunction() if
    (xmlhttp.readyState4) alert(xmlhttp.respons
    eText)
  • 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("lt?xml version'1.0'
    encoding'UTF-8'?gt""\n\n"
  • 'ltsoapenvEnvelope xmlnssoapenv"http//schemas.x
    mlsoap.org/soap/envelope/"gt'
  • 'ltsoapenvBodygt'
  • 'ltns1doSpellingSuggestion xmlnsns1"urnGoogleSe
    arch"'
  • ' soapenvencodingStyle"http//schemas.xmlsoap.or
    g/soap/encoding/"'
  • ' xmlnsxsi"http//www.w3.org/1999/XMLSchema-inst
    ance"'
  • ' xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt'
  • 'ltkey xsitype"xsdstring"gtTcP7PPxQFHJtaZQO2OzWIP
    wdu2bUjYKDlt/keygt'
  • 'ltphrase xsitype"xsdstring"gtsalvasionlt/phrasegt'
  • 'lt/ns1doSpellingSuggestiongt'
  • 'lt/soapenvBodygt'
  • 'lt/soapenvEnvelopegt')

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
    syntaxopen(method, uri, isAsynchronous)
  • req.open("POST", "http//api.google.com/search/bet
    a2", 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
    ("urnGoogleSearch", "ns1doSpellingSuggestion"
    )req_node. setAttribute ("xmlnsxsd",
    "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-i
    nstance", "type", "xsdstring" )var key_text
    document.createTextNode (key )key_node.appendChi
    ld(key_text)//create the node for phrasevar
    phrase_node document.createElement
    ("phrase")phrase_node. setAttributeNS("http//ww
    w.w3.org/2001/XMLSchema-instance", "type",
    "xsdstring" )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 in/out Model
Request
  • lt?xml version"1.0" encoding"UTF-8"?gt
    ltsoapenvEnvelope xmlnssoapenv"http//schemas.x
    mlsoap.org/soap/envelope/"gt
    ltsoapenvHeadergtlt/soapenvHeadergtltsoapenvBodygt
    ltns1doSpellingSuggestion
    xmlnsns1"urnGoogleSearch" soapenvencodingStyle
    "http//schemas.xmlsoap.org/soap/encoding/"
    xmlnsxsi"http//www.w3.org/1999/XMLSchema-instan
    ce" xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt
    ltkey xsitype"xsdstring"gtwCumFQpQFHL
    7coIxlNKUGtyVsgrVAnblt/keygt ltphrase
    xsitype"xsdstring"gttungsstonlt/phrasegt
    lt/ns1doSpellingSuggestiongt lt/soapenvBodygtlt/soa
    penvEnvelopegt

Response
  • lt?xml version'1.0' encoding'UTF-8'?gtltSOAP-ENVE
    nvelope xmlnsSOAP-ENV"http//schemas.xmlsoap.org
    /soap/envelope/" xmlnsxsi"http//www.w3.org/1999
    /XMLSchema-instance" xmlnsxsd"http//www.w3.org/
    1999/XMLSchema"gt ltSOAP-ENVBodygt
    ltns1doSpellingSuggestionResponse
    xmlnsns1"urnGoogleSearch" SOAP-ENVencodingStyl
    e"http//schemas.xmlsoap.org/soap/encoding/"gt
    ltreturn xsitype"xsdstring"gttungstenlt/r
    eturngt lt/ns1doSpellingSuggestionResponse
    gt lt/SOAP-ENVBodygt lt/SOAP-ENVEnvelopegt

16
Non-Blocking
  • Set the third parameter of open to true
  • req.open("POST", "http//api.google.com/search/bet
    a2", 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 sampleltsoapenvHeader
    xmlnswsa"http//www.w3.org/2005/08/addressing"gt
    ltwsaTogthttp//localhost9090/axis2/services/e
    cholt/wsaTogt ltwsaActiongthttp//ws.apache.org/
    axis2/c/samples/echoStringlt/wsaActiongt
    ltwsaMessageIDgtcb00ebf2-39ad-1db1-36e2-001125ce1ac
    4lt/wsaMessageIDgtlt/soapenvHeadergt
  • 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/ax
    is2/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/in
    stallation.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 QA
Write a Comment
User Comments (0)
About PowerShow.com