330 likes | 421 Views
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
E N D
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 • e.g., “You’ve got to read this book!” • Why? You’ll see… XML 2006: Native Web Services Support in XJ
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
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
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
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
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
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
XJ/WS Demo Amazon Client Amazon Service GMail + Amazon mashup
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
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
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
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
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
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
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
Alternate Approaches Service dispatch: JAX-WS Data: DOM or JAXB Construction: Strings or bottom-up Traversals: JAXP or explicit
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
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
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
More opportunity for automatic optimization Less boilerplate code; Automatic coercions; Visually nicer Subjective Comparison XML 2006: Native Web Services Support in XJ
Compiled XPath Projection Performance XML 2006: Native Web Services Support in XJ