1 / 24

SOA using Java Web Services and Ajax

SOA using Java Web Services and Ajax. Mark D. Hansen Author of “SOA Using Java Web Services” http://soabook.com. Mark Hansen’s Background. Consultant, Entrepreneur, MIT PhD Book and code examples at http://soabook.com SOA-J open source project at http://soa-j.org. Outline.

MikeCarlo
Download Presentation

SOA using Java Web Services and Ajax

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. SOA using Java Web Services and Ajax Mark D. Hansen Author of “SOA Using Java Web Services” http://soabook.com

  2. Mark Hansen’s Background • Consultant, Entrepreneur, MIT PhD • Book and code examples at http://soabook.com • SOA-J open source project at http://soa-j.org

  3. Outline • 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!)

  4. What is SOA? • Loose coupling • Service contract • Autonomy • Abstraction • Reusability • Composability • Statelessness • Discoverability “Service-Oriented Architecture”, Thomas Erl, Chapter 3 pg 34 - 37

  5. What is a Web Service? • A provider that enables access to the service via either: • SOAP • XML / HTTP • A description or contractthat specifies the request/response message structure. • WSDL • XML Schema (insufficient) • WADL (new)

  6. What 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

  7. Client Side JWS

  8. Server Side JWS

  9. package samples; import javax.jws.WebService; @WebService public class Hello { public String sayHello(String s) { return "Hello: " + s; } } <definitions ... targetNamespace="http://samples/" name="HelloService"> <types> ... </types> <message name="sayHello"> ... </message> <portType name="Hello"> <operation name="sayHello"> <input message="tns:sayHello"/> <output message="tns:sayHelloResponse"/> </operation> </portType> <binding name="HelloPortBinding" type="tns:Hello"> <soap:binding ... /> <operation name="sayHello"> ... </operation> </binding> <service name="HelloService"> <port name="HelloPort“ ... </port> </service> </definitions> JAX-WS Maps WSDL to a Java API

  10. JAXB Maps XML Schema to Java Classes

  11. What 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

  12. SOA Using JWS and Ajax

  13. SOAShopper Architecture

  14. Demo SOAShopper – Integrating Yahoo!, Amazon, and eBay

  15. eBay WSDL

  16. Ant Task to Compile eBay WSDL

  17. Using the Generated eBay API

  18. A Client Binding Example public List<Offer> offerSearch( String keywords, Category category, Price lowprice, Price highprice) { ShopperImp binding = BindingService.getBinding( ShopperImp.class, EBayAPIInterface.class); return binding.offerSearch(keywords, category, lowprice, highprice); }

  19. Implementing a Binding Service publicabstractclass BindingService { publicstatic <C> C getBinding( Class<C> client, Class<?> service) { ... } }

  20. Flash Demo

  21. Using the Dojo Table Widget <table dojoType="filteringTable" id="fromSOAShopperData" multiple="true" alternateRows="true" cellpadding="0" cellspacing="0" border="0" style="margin-bottom:24px;"> <thead> <tr> <th field="source" dataType="String">Source</th> <th field="thumbnail" dataType="html" align="center">Image</th> <th field="price" dataType="String">Price</th> <th field="summary" dataType="String">Summary</th> <th field="url" dataType="html">Link</th> </tr> </thead> </table>

  22. Invoking 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"); ... } }

  23. Loading the Dojo Table function populateTableFromLiveSOAShopperData() { try { var w = dojo.widget.byId("fromSOAShopperData"); w.store.setData(theSOAShopperLiveData); } catch(e) { alert(e); } }

  24. Resources • SOA Using Java Web Services http://soabook.com • Thomas Erl’s SOA Book http://www.thomaserl.com/books.asp • Ajax In Action http://www.manning.com/crane/ • SOA-J open source project http://soa-j.org

More Related