Eclipse Web Tools Platform Project © 2005 IBM Corporation Developing Web Services with Eclipse – Programming Examples Arthur Ryman IBM Rational EclipseWorld New York,
Eclipse Web Tools Platform Project © 2005 IBM Corporation 2Developing Web Services with Eclipse, EclipseWorld, New York Development Scenarios Accessing Web Services Creating Web Services –Bottom-Up –Top-Down
Eclipse Web Tools Platform Project © 2005 IBM Corporation 3Developing Web Services with Eclipse, EclipseWorld, New York Accessing Web Services The preceding demo generated a JSP test client for the Stock Quote service Well now code a JSP client application that accesses it The Web Service wizard generated JAX-RPC compliant client code and a convenience wrapper Well use this code in our client
Eclipse Web Tools Platform Project © 2005 IBM Corporation 4Developing Web Services with Eclipse, EclipseWorld, New York JAX-RPC Client Code
Eclipse Web Tools Platform Project © 2005 IBM Corporation 5Developing Web Services with Eclipse, EclipseWorld, New York JAX-RPC Client Code package NET.webserviceX.www –targetNamespace=" StockQuoteLocator.java – Service locator StockQuoteLocator.java StockQuote.java – Service interface StockQuote.java – StockQuoteSoap.java – Remote interface StockQuoteSoap.java – StockQuoteSoapStub.java – Client stub wrapper for Call object StockQuoteSoapStub.java StockQuoteSoapProxy.java – Client proxy convenience wrapper StockQuoteSoapProxy.java
Eclipse Web Tools Platform Project © 2005 IBM Corporation 6Developing Web Services with Eclipse, EclipseWorld, New York Web Client Version 1: getQuote.jspgetQuote.jsp 1)Create a JSP 1)get a query parameter, symbol, 2)create a service proxy, and 3)invoke the getQuote operation 2)Select getQuote.jsp and invoke Run As->Run on ServergetQuote.jsp 1)The Web app is added to the server, 2)the server is started, and 3)a Web browser is opened on the appropriate URL for getQuote.jsp getQuote.jsp
Eclipse Web Tools Platform Project © 2005 IBM Corporation 7Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 8Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 9Developing Web Services with Eclipse, EclipseWorld, New York Processing XML This service has a poorly designed interface –XML is returned as an escaped string –No schema for result The client needs to parse the result to extract the price, etc. Client application can parse XML using: –DOM, –SAX, –Java data binding code (JAXB, etc), or –server-side XSLT For fun, well use browser-side XSLT
Eclipse Web Tools Platform Project © 2005 IBM Corporation 10Developing Web Services with Eclipse, EclipseWorld, New York Web Client Version 2: getQuote-xsl.jspgetQuote-xsl.jsp 1)View example of XML response ibm-quote.xmlibm-quote.xml 2)Create XSLT StockQuotes.xslStockQuotes.xsl 1)Generate to get symbol 2)Generate to present stock quote 3)Create JSP getQuote-xsl.jspgetQuote-xsl.jsp 1)Insert processing instruction 2)Return unparsed XML 4)Run on Server to view result
Eclipse Web Tools Platform Project © 2005 IBM Corporation 11Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 12Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 13Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 14Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 15Developing Web Services with Eclipse, EclipseWorld, New York Bottom-Up Web Service Creation Any reasonable Java class can be easily deployed as a Web service This approach is very appealing to Java programmers since it lets them be immediately productive The WSDL is generated from the Java The result is acceptable if the methods use tame argument types, however object graphs are problematic Top-Down design is recommended to achieve the cleanest and most interoperable Web service interfaces
Eclipse Web Tools Platform Project © 2005 IBM Corporation 16Developing Web Services with Eclipse, EclipseWorld, New York Bottom-Up Service: BUService 1)Create a new Web project: BUService 2)Create a data object to represent the result: BUStock.javaBUStock.java 3)Create a business object to take a symbol and return a stock quote for it: BUQuoter.javaBUQuoter.java 4)Use the Web service wizard to deploy it. Use rpc-encoded style for fun so we can see WS-I errors. Generate and monitor a JSP test client. 5)Test the service, view the messages in the monitor, and validate the SOAP messages for WS-I conformance. Note the errors caused by rpc-encoded style.
Eclipse Web Tools Platform Project © 2005 IBM Corporation 17Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 18Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 19Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 20Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 21Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 22Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 23Developing Web Services with Eclipse, EclipseWorld, New York Top-Down Web Service Creation Business is transacted by exchanging documents – purchase orders, receipts, application forms, insurance claims, building permits, etc. For best interoperability, treat Web services as document interchange, not distributed objects Model documents using XSD, and operations using WSDL Generate Java from WSDL
Eclipse Web Tools Platform Project © 2005 IBM Corporation 24Developing Web Services with Eclipse, EclipseWorld, New York Top-Down Service: TDService 1)Create a new Web project: TDService 2)Create an XML schema for the Stock quote result: TDStock.xsdTDStock.xsd 3)Create a WSDL for the quote service with an operation that takes a symbol and returns a quote: TDQuoter.wsdl. Use the WSDL Binding wizard to generate document-literal SOAP binding style this time.TDQuoter.wsdl 4)Use the Web service wizard to generate the service. 5)Fill in the implementation of the service: TDQuoterSOAPImpl.javaTDQuoterSOAPImpl.java 6)Create a new Web project: TDServiceClient 7)Select /wsdl/TDQuoterSOAP.wsdl, create a JSP test client, and monitor the service. 8)Test the service and validate the SOAP messages for WS-I conformance. There should be no errors this time.
Eclipse Web Tools Platform Project © 2005 IBM Corporation 25Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 26Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 27Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 28Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 29Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 30Developing Web Services with Eclipse, EclipseWorld, New York
Eclipse Web Tools Platform Project © 2005 IBM Corporation 31Developing Web Services with Eclipse, EclipseWorld, New York