Sunday, April 20, 2014

[Spring] 21 - Spring Web Services

  • Introduction to Web Services
    • Why use or build a web service?
    • Best practices for implementing a web service
  • Quick start using Spring Web Services
  • Endpoint mappings
  • Object-XML marshalling
  • Client access
  • WSDL?


Web Services enable Loose Coupling

"Loosely coupled systems are considered useful when either the source or the destination computer systems are subject to frequent changes" ~ Wikipedia (July 2007)

Loose coupling increases tolerance ...
changes should not cause incompatibility


Web Services enable Interoperability
  • XML is the lingua franca in the world of interoperability
  • XML is understood by all major platforms
    • SAX, StAX or DOM in Java
    • System.XML or .NET XML Parser in .NET
    • REXML or XmlSimple in Ruby
    • Peral-XML or XML::Simple in Perl
* Notes:
Web services - the functions provided by other third party provider.
i.e. the specific functions which vendor provides in order to give your programs used,m usually via a URL.

Web Services - no need to code and maintain by yourself, just call others function to use.


Best practices for implementing your web services
(i.e. You acts as a google map, a service provider)
  • Remember: 
    • web services != SOAP (Simple Object Access Protocol)
    • web services != RPC (Remote Procedure Call)
  • Design contract independently from service interface
  • Refrain (經常重複) from using stubs (存根) and skeletons
  • Don't use validation for incoming requests
  • Use XPath




Spring MVC vs Spring Web Services



Define a schema





Bootstrap the application tier




Architecture of our application exposed using a web service




Endpoint mappings (i.e. HandlerMapping)
  • Spring Web Services provides several strategies for mapping requests to endpoints
    • Message Payload
    • SOAPAction Header
    • XPath
    • Annotations



Object-XML Marshalling




Marshaller Implementations
  • All popular OXM technologies are supported:
    • JAXB (1 and 2)
    • Castor
    • JiBX
    • XmlBeans
    • XStream


Object-XML Marshalling



Configuring a Castor Marshaller



Spring Web Services on the Client
  • WebService Template
    • Simplifies web service access
    • Works directly with the XML payload
      • Extracts body of a SOAP message
      • Also works with POX (Plain Old XML)
    • Can use marshallers /unmarshallers
    • Provides convenience methods for sending and receiving web service messages
    • Provides callbacks for more sophisticated usage

No comments:

Post a Comment