Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP

Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP

CSI 3140 WWW Structures, Techniques and Standards Web Services: JAX-RPC, WSDL, XML Schema, and SOAP Web Services Concepts A web application uses Web technologies to provide functionality to an end user A web service uses Web technologies to provide functionality to another software application Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 2 Web Services Concepts Standard web services technologies: Communication via SOAP XML vocabulary documents over HTTP Operations of web service defined by Web Services Definition Language (WSDL) XML vocabulary Data within WSDL defined using XML Schema Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 3 Web Services Concepts Higher-level API’s are often used to automatically generate web services client and server communication software We will use the Java API for XML-based Remote Procedure Call (JAX-RPC) Microsoft .NET framework is one popular alternative to JAX-RPC Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 4 Web Services Concepts Web services conceptually are just specialized web applications: HTTP request (SOAP body) Server Client (Java servlet) HTTP response (SOAP body) Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 5 Web Services Concepts Body of web services request is analogous to calling a method Operation name (like method name) Input parameter Input parameter values names Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 6 Web Services Concepts Body of web services response is analogous to value returned by a method Return value data type Return value Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 7 Web Services Concepts WSDL defines web service Operations Parameters Return values Communication protocols Basically an API for the web service Facilitates automated client/server software generation Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 8 Web Services Concepts Portions Input params of NWS Data types defined using WSDL XML Schema Return type Operation name Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 9 Web Services Concepts Java Web Services Developer Pack (JWSDP) wscompile tool can implement a Java API from a WSDL Classes and methods generated by wscompile This method automatically handles SOAP request and response Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 10 Web Services Concepts Writing the server for a web service with JWSDP: Write a Java interface defining the API Implement the interface JWSDP generates SOAP and communication handling classes WSDL Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 11 Web Services Concepts Example Java interface Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 12 Web Services Concepts Example implementation Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 13 Web Services Examples Tons of WS available on the internet. http://www.webservicex.net as a good collection Geo IP: http://www.webservicex.net/geoipservice.asmx?op=GetGeoIP Whois: http://www.webservicex.net/whois.asmx?op=GetWhoIS SMS: http://www.webservicex.net/sendsmsworld.asmx Etc.. Google: Amazon S3 Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 14 JWSDP: Server Application: currency converter Three operations: fromDollars fromEuros fromYen Input: value in specified currency Output: object containing input value and equivalent values in other two currencies Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 15 JWSDP: Server 1.Write service endpoint interface • May need to write additional classes representing data structures 2.Write class implementing the interface 3.Compile classes 4.Create configuration files and run JWSDP tools to create web service 5.Deploy web service to Tomcat Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 16 JWSDP: Server Service endpoint interface Must extend java.rmi.Remote Every method must throw java.rmi.RemoteException Parameter/return value data types are restricted No public static final declarations (global constants) Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 17 JWSDP: Server Allowable parameter/return value data types Java primitives (int, boolean, etc.) Primitive wrapper classes (Integer, etc.) String , Date, Calendar, BigDecimal, BigInteger java.xml.namespace.QName, java.net.URI Struct: class consisting entirely of public instance variables Array of any of the above Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 18 JWSDP: Server Struct for currency converter app (data type for return values) Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 19 JWSDP: Server Service endpoint interface Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 20 JWSDP: Server 1.Write service endpoint interface • May need to write additional classes representing data structures 2.Write class implementing the interface 3.Compile classes 4.Create configuration files and run JWSDP tools to create web service 5.Deploy web service to Tomcat Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 21 JWSDP: Server Class CurConImpl contains methods, for example: Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 22 JWSDP: Server 1.Write service endpoint interface • May need to write additional classes representing data structures 2.Write class implementing the interface 3.Compile classes 4.Create configuration files and run JWSDP tools to create web service 5.Deploy web service to Tomcat Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 23 JWSDP: Server Configuration file input to wscompile to create server Namespaces used in WSDL (normally, unique URL’s at your Web site) Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 24 JWSDP: Server Configuration file for web service Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 25 JWSDP: Server Configuration file for web service Context path Like servlet in web.xml Like servlet-mapping in web.xml Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 26 JWSDP: Server Also need a minimal web.xml Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 27 JWSDP: Server Run jar and wsdeploy to create a Web Archive (WAR) file converter.war Name must match urlPatternBase value Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 28 JWSDP: Server 1.Write service endpoint interface • May need to write additional classes representing data structures 2.Write class implementing the interface 3.Compile classes 4.Create configuration files and run JWSDP tools to create web service 5.Deploy web service to Tomcat Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 29 JWSDP: Server Just copy converter.war to Tomcat webapps directory May need to use Manager app to deploy Enter converter.war in “WAR or Directory URL” text box Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 30 JWSDP: Server Testing success: Visit http://localhost:8080/converter/currency Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 31 JWSDP: Client Goal: write a JSP-based client Input: currency and value Output: table of equivalent values Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 32 JWSDP: Client Configuration file input to wscompile to create client Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 33 JWSDP: Client Directory structure (wscompile generates content of classes and src) Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 34 JWSDP: Client Starting point for writing a client (if the web service author does not explain how): In the WSDL, find the name attribute of the service element Look in Java file with this name to see how to obtain a proxy object for the service Data type of proxy object Method called to obtain object Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 35 JWSDP: Client Obtaining the proxy object: Java file consisting of service name followed by _Impl defines a class implementing the proxy- generating interface Client code begins with method call on this class: Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 36 JWSDP: Client Using the proxy object: Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 37 JWSDP: Client Structs will be represented as JavaBeans classes, regardless of how they are defined on the server Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 38 JWSDP: Client Bean obtaining and calling proxy object: Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 39 JWSDP: Client JSP document using the bean: Call to getExValues() Call to getEuros() Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 40 WSDL Example Namespaces specified in config files WSDL namespaces XML Schema NS Target namespace: namespace for names (e.g., of operations) defined by the WSDL Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 41 WSDL Example Namespace for data type definitions (ns2 in rest of document) Defines struct using XML Schema Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 42 WSDL Example Data type defined by XML Schema Output Input messages messages (response (parameter data types) lists) Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 43 WSDL Example Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 44 WSDL Example Implement the operations using SOAP encoding of data structures and RPC (JWSDP defaults) Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jackson’s slides 45 WSDL Example Replaced by server when WSDL is visited Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    76 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us