Title: SOA using Java Web Services and Ajax
1 SOA using Java Web Services and Ajax
- Mark D. Hansen
- Author of SOA Using Java Web Services
- http//soabook.com
2Mark Hansens Background
- Consultant, Entrepreneur, MIT PhD
- Book and code examples at http//soabook.com
- SOA-J open source project at http//soa-j.org
3Outline
- What is SOA?
- What are Web Services?
- What are Java Web Services (JWS)?
- What is AJAX?
- How can you implement SOA with JWS and AJAX?
- Demo (eBay, Amazon, Yahoo!)
4What is SOA?
- Loose coupling
- Service contract
- Autonomy
- Abstraction
- Reusability
- Composability
- Statelessness
- Discoverability
Service-Oriented Architecture, Thomas Erl,
Chapter 3 pg 34 - 37
5What is a Web Service?
- A provider that enables access to the service via
either - SOAP
- XML / HTTP
- A description or contract that specifies the
request/response message structure. - WSDL
- XML Schema (insufficient)
- WADL (new)
6What are Java Web Services (JWS)?
- The provider is written in Java and deployed
using a Java container. - The consumer is written in Java.
- Java Web Service APIs are used
- JAX-WS
- JAXB
- WS-Metadata (JSR-181)
- WSEE (JSR-109)
- JAX-RPC is deprecated starting in Java EE 5
7Client Side JWS
8Server Side JWS
9JAX-WS Maps WSDL to a Java API
- package samples
- import javax.jws.WebService
- _at_WebService
- public class Hello
-
- public String sayHello(String s)
- return "Hello " s
-
-
- ltdefinitions ... targetNamespace"http//samples/"
name"HelloService"gt - lttypesgt ... lt/typesgt
- ltmessage name"sayHello"gt ... lt/messagegt
- ltportType name"Hello"gt
- ltoperation name"sayHello"gt
- ltinput message"tnssayHello"/gt
- ltoutput message"tnssayHelloResponse"/gt
- lt/operationgt
- lt/portTypegt
- ltbinding name"HelloPortBinding"
type"tnsHello"gt - ltsoapbinding ... /gt
- ltoperation name"sayHello"gt ... lt/operationgt
- lt/bindinggt
- ltservice name"HelloService"gt
- ltport name"HelloPort ...
- lt/portgt
- lt/servicegt
- lt/definitionsgt
10JAXB Maps XML Schema to Java Classes
11What is AJAX?
- Asynchronous JavaScript and XML
- An Interaction Model
- A Set of Technologies for Rich Client Development
- ...
- A Composite Application Framework for Flexible
Business Process Management ???
Ajax In Action, Dave Crane et al., Chapter 2 pg
33
12SOA Using JWS and Ajax
13SOAShopper Architecture
14Demo
- SOAShopper Integrating Yahoo!, Amazon, and eBay
15eBay WSDL
16Ant Task to Compile eBay WSDL
17Using the Generated eBay API
18A Client Binding Example
- public ListltOffergt offerSearch(
- String keywords, Category category,
- Price lowprice, Price highprice)
- ShopperImp binding
- BindingService.getBinding(
- ShopperImp.class, EBayAPIInterface.clas
s) - return
- binding.offerSearch(keywords,
- category, lowprice, highprice)
-
19Implementing a Binding Service
- public abstract class BindingService
- public static ltCgt C getBinding(
- ClassltCgt client, Classlt?gt service)
- ...
-
20Flash Demo
21Using the Dojo Table Widget
- lttable dojoType"filteringTable"
id"fromSOAShopperData" multiple"true" - alternateRows"true" cellpadding"0"
cellspacing"0" border"0" - style"margin-bottom24px"gt
- lttheadgt
- lttrgt
- ltth field"source" dataType"String"gtSourcelt
/thgt - ltth field"thumbnail" dataType"html"
align"center"gtImagelt/thgt - ltth field"price" dataType"String"gtPricelt/t
hgt - ltth field"summary" dataType"String"gtSummar
ylt/thgt - ltth field"url" dataType"html"gtLinklt/thgt
- lt/trgt
- lt/theadgt
- lt/tablegt
22Invoking the REST Endpoint
- function retrieveURL(url)
- restURL url
- showSearchingMsg(restURL)
- if (window.XMLHttpRequest) // Non-IE
browsers - req new XMLHttpRequest()
- req.onreadystatechange processStateChange
- try
- req.open("GET", url, true)
- req.setRequestHeader('Content-type','text/
xml') - catch (e)
- alert(e)
-
- req.send(null)
- else if (window.ActiveXObject) // IE
- req new ActiveXObject("Microsoft.XMLHTTP")
- ...
-
-
23Loading the Dojo Table
- function populateTableFromLiveSOAShopperData()
- try
- var w dojo.widget.byId("fromSOAShopperData")
- w.store.setData(theSOAShopperLiveData)
- catch(e)
- alert(e)
-
-
24Resources
- SOA Using Java Web Services http//soabook.com
- Thomas Erls SOA Book http//www.thomaserl.com/boo
ks.asp - Ajax In Action http//www.manning.com/crane/
- SOA-J open source project http//soa-j.org