1 / 33

Native Web Services Support in XJ

Native Web Services Support in XJ. Or “Must Web Service Programming be Hard?”. Igor Peshansky, IBM Research. XJ/WS Demo: Preamble. Send email to xj.access@gmail.com Subject: a book title search string e.g., “ The Bonfire of the Vanities ” Body: contains “ book ” in the first line

aquene
Download Presentation

Native Web Services Support in XJ

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. Native Web Services Support in XJ Or “Must Web Service Programming be Hard?” Igor Peshansky, IBM Research

  2. XJ/WS Demo: Preamble • Send email to xj.access@gmail.com • Subject: a book title search string • e.g., “The Bonfire of the Vanities” • Body: contains “book” in the first line • e.g., “You’ve got to read this book!” • Why? You’ll see…  XML 2006: Native Web Services Support in XJ

  3. Intro to XJ – Features • XML integration into Java • Java extended with • Inline XML construction (typed and untyped) • Native XPath expressions • Schema type import (if any) • Static type checking and validation • XML-specific optimizations + updates • Retargetable backend XML 2006: Native Web Services Support in XJ

  4. Use schema types in code Use schema types in code Intro to XJ – Example Code Refer to schema declarations …including nested elements import com.amazon.devheavy.*; import com.amazon.devheavy.ProductInfo.Details; import myOutput.*; publicBookcheckReviews (ProductInfopi,String title, String author, float goodRating) { Sequence<Details>bookSeq =pi[| .//Details[ProductName = $title] |]; for (Details book : bookSeq) { if (book[| [$author = .//Author] |].isEmpty()) continue; double discountMult = 0.5; if (! book[| [.//AvgCustomerRating > $goodRating] |].isEmpty()) discountMult = 0.75; Bookresult =newBook(<Book name='{title}'> <isbn>{book[| Isbn |]}</isbn> <price>{book[| .//Price |] * discountMult}</price> </Book>); return result; } } Inline XPath expressions Validated inline XML construction …with embedded expressions XML 2006: Native Web Services Support in XJ

  5. Web Services Concepts • A web service is a collection of operations that consume some XML parts and produce exactly one XML part (or nothing) • An operation is like a method with XML types in the signature • A WSDL PortType (abstract web service specification) is like an interface with many such methods • A WSDL Port is a binding + endpoint XML 2006: Native Web Services Support in XJ

  6. WSDL Example • definitions • types • schematargetNamespace="http://example.com/HelloService/2006-11-29" • elementname="sayHello" • sequence elementname="firstName" type="string"elementname="lastName" type="string" • elementname="hello" • extensionbase="string"attributename="from" type="string" use="required" • message… • message… • portType… • binding… • service… • definitions • types… • messagename="HelloRequestMsg“partelement="sayHello" • messagename="HelloResponseMsg“partelement="hello" • portTypename="HelloPortType" • operationname="sayHello“inputmessage="HelloRequestMsg“outputmessage="HelloResponseMsg" • bindingname="HelloBinding" type="HelloPortType" • soap:bindingstyle="document" transport="http://schemas.xmlsoap.org/soap/http" • operationname="sayHello“soap:operationsoapAction="http://localhost:8080"input — soap:bodyuse="literal“output — soap:bodyuse="literal" • servicename="HelloService" • portname="HelloPort" binding="HelloBinding“soap:addresslocation="http://localhost:8080/axis2/services/HelloService" XML 2006: Native Web Services Support in XJ

  7. Web Services Support in XJ • Import WSDL (1.1) • Including the embedded schema • Manifest PortTypes as interfaces • Get deployable web services by implementing a PortType interface • Invoke web service operations by calling methods on a PortType object • Connect by instantiating concrete Ports XML 2006: Native Web Services Support in XJ

  8. xjc DOM XJ Source + XML Schemas + WSDL Java Bytecode SDO • Static checking • Optimization • Code generation Eclipse JDT XML data xj XJ Runtime Axis2 JRE XJ/WS Architecture • Document/literal only for now • More styles coming XML 2006: Native Web Services Support in XJ

  9. XJ/WS Demo Amazon Client Amazon Service GMail + Amazon mashup

  10. XJ/WS Demo: Amazon Client • Connect to the Amazon web service • Invoke the Help operation • Request help on the ItemSearch operation • Invoke the ItemSearch operation • Search for a book with a given title • Invoke the ItemLookup operation • Retrieve the item returned by ItemSearch XML 2006: Native Web Services Support in XJ

  11. XML 2006: Native Web Services Support in XJ

  12. XML 2006: Native Web Services Support in XJ

  13. XML 2006: Native Web Services Support in XJ

  14. XJ/WS Demo: Amazon Service • Implement Help, ItemSearch, ItemLookup • Help: • Return an empty response element • ItemSearch: • Return a constant response • ItemLookup: • Extract the item id from request; verify that it is an “ASIN”; construct response XML 2006: Native Web Services Support in XJ

  15. XML 2006: Native Web Services Support in XJ

  16. XML 2006: Native Web Services Support in XJ

  17. XML 2006: Native Web Services Support in XJ

  18. XJ/WS Demo:GMail + Amazon Mashup • Retrieve mail for xj.access@gmail.com • As an RSS feed • Find messages with “book” in body summary • Invoke ItemSearch on Amazon • For each matched message • With message subject as book title XML 2006: Native Web Services Support in XJ

  19. XML 2006: Native Web Services Support in XJ

  20. XML 2006: Native Web Services Support in XJ

  21. Alternate Approaches

  22. Static JAX-WS (JAXB) • JAX-WS for service dispatch, JAXB for data • Lots of generated code • Unintuitive bindings • Impedance mismatch • No optimizations • Schemaless support via DOM only XML 2006: Native Web Services Support in XJ

  23. Other Possibilities • Axis2 for service dispatch, AXIOM for data • requires more initialization • same issues as DOM • JAX-RPC 2.0 + JSR 181 annotations • object to XML mapping • may need extra annotations to get right • generated code • no apparent association to WSDL XML 2006: Native Web Services Support in XJ

  24. XJ/WS Demo: Reprise • Modify GMail + Amazon Mashup • To also display the sender of each message • Minor changes required to the code XML 2006: Native Web Services Support in XJ

  25. XML 2006: Native Web Services Support in XJ

  26. Conclusion • XJ/WS provides intuitive native support for Web Services • Faithful XML representation; static checks • Ease of implementation and deployment • Ease of code evolution • Opportunities for optimization • Retargetable backend • Coming soon to http://alphaworks.ibm.com/tech/xj • More demos at the IBM booth XML 2006: Native Web Services Support in XJ

  27. Backup Slides

  28. Alternate Approaches Service dispatch: JAX-WS Data: DOM or JAXB Construction: Strings or bottom-up Traversals: JAXP or explicit

  29. JAX-WS + DOM (Implicit) • JAX-WS for service dispatch, DOM for data • Implicit construction from Strings • JAXP for XPath • Visually similar to the XJ version • A bit awkward • No static checking • Performance implications XML 2006: Native Web Services Support in XJ

  30. JAX-WS + DOM (Explicit) • JAX-WS for service dispatch, DOM for data • Explicit construction (via DOM operations) • Explicit traversals • Hard to write • No static checking • Hard to debug • Harder to change XML 2006: Native Web Services Support in XJ

  31. JAX-WS + JAXB • JAX-WS for service dispatch, JAXB for data • Unintuitive bindings • Lots of generated code • Impedance mismatch XML 2006: Native Web Services Support in XJ

  32. More opportunity for automatic optimization Less boilerplate code; Automatic coercions; Visually nicer Subjective Comparison XML 2006: Native Web Services Support in XJ

  33. Compiled XPath  Projection   Performance XML 2006: Native Web Services Support in XJ

More Related