2. Plan for today
•
•
•
•
•
•
Recap: Web fundamentals
APIs, Web Services
Restful services
SOAP-based services
Comparison
Tutorial
• JAX-WS: Building SOAP-based services in Java
• JAX-RS: Building RESTful services in Java
PAGE 4
3. Recap: Web Fundamentals
Key Architectural Components
• Identification: URI
• Interaction: HTTP
• Standardized Document Formats: HTML, XML, JSON, etc.
PAGE 5
4. URIs / resources
• URIs identify interesting things
• documents on the Web
• relevant aspects of a data set
• HTTP URIs name and address resources in
Web based systems
• a URI names and identifies one resource
• a resource can have more than one name
− http://foo.com/software/latest
− http://foo.com/software/v1.4
PAGE 6
6. Plan for today
•
•
•
•
•
•
Recap: Web fundamentals
APIs, Web Services
RESTful services
SOAP-based services
Comparison
Tutorial
• JAX-WS: Building SOAP-based services in Java
• JAX-RS: Building RESTful services in Java
PAGE 8
8. (Web) APIs
• Application Programming Interface
• Specifies how software components communicate
with each other
• e.g., Java API, 3rd party library APIs
• usually come with documentation
• Web API: specify how applications communicate
with other over the Web (HTTP, URI, XML, etc.)
PAGE 10
9. Web Services, Web Applications and
APIs (Application Programming Interface)
• Web Applications == Web Services == Web APIs ?
PAGE 11
10. Web Services, Web Applications and
APIs (Application Programming Interface)
• Web Applications are designed to be accessed by
end users through Web client software
• Web Services are intended to be used by other
software applications
• Web APIs ≈ Web Services
PAGE 12
11. Web Services
• “Web Services”
“Web APIs”
• Build on the design principles and architectural
components of the Web
• Provide certain operations
• Exchange structured data in standard formats
(JSON, XML, etc.)
PAGE 13
12. Web Services
Example operations:
• Publish image on Flickr
• Order a book at Amazon
• Post a message on your friend’s Facebook wall
PAGE 14
17. What Are Web Services?
• W3C definition:
• A software system designed to support
interoperable machine-to-machine interaction over a
network...
PAGE 19
18. Web Services Use
• Connect existing software
• Reusable application components
PAGE 20
19. Major classes of Web Services
• Big Web Services (L. Richardson and S. Ruby)
• RESTful (REST-compliant) Web Services
PAGE 21
23. A RESTful Web service...
• ... exposes its data and functionality through
interlinked Web resources identified by URI.
• ... is more data-centric, and less functionality-centric
(as opposed to SOAP services).
• ... embeds functionality of the service in the uniform
HTTP interfaces for interaction: GET, PUT, DELETE,
POST.
• ... uses HTTP as the application protocol instead of
SOAP
PAGE 25
24. Four basic design principles
•
•
•
•
Use HTTP methods explicitly.
Be stateless.
Expose directory structure-like URIs.
Transfer XML, JavaScript Object Notation (JSON), or
both.
PAGE 26
25. Use HTTP methods explicitly
• One-to-one mapping between
• create, read, update, and delete (CRUD) operations
• and HTTP methods.
• According to this mapping:
•
•
•
•
To create a resource on the server, use POST.
To retrieve a resource, use GET.
To change the state of a resource or to update it, use PUT.
To remove or delete a resource, use DELETE.
PAGE 27
26. Example: HTTP GET request
GET /users/Robert HTTP/1.1
Host: myserver
Accept: application/xml
PAGE 28
27. Example: HTTP PUT request
PUT /users/Robert HTTP/1.1
Host: myserver
Content-Type: application/xml
<?xml version="1.0"?>
<user>
<name>Bob</name>
</user>
PAGE 29
30. Transfer XML, JSON, or both
<?xml version="1.0"?>
<discussion date="{date}" topic="{topic}">
<comment>{comment}</comment>
<replies>
<reply from="joe@mail.com" href="/discussion/topics/{topic}/joe"/>
<reply from="bob@mail.com" href="/discussion/topics/{topic}/bob"/>
</replies>
</discussion>
PAGE 32
31. Tools and frameworks
• Ruby on Rails -- a framework for building RESTful Web
applications – http://www.rubyonrails.org/
• Restlet -- framework for mapping REST concepts to Java
classes http://www.restlet.org
• Django - framework for building RESTful Web applications in
Python
• JAX-RC specification (http://jsr311.java.net/) -provides a Java
API for RESTful Web Services over the HTTP
• RESTEasy (http://www.jboss.org/resteasy/) - Jboss project that
provides various frameworks for building RESTful Web
Services and RESTful Java applications.
PAGE 33
35. What is SOAP
•
•
•
•
•
•
•
SOAP used to stand for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is designed to communicate via Internet
SOAP is based on XML
SOAP is simple and extensible
SOAP is platform and language independent
SOAP is a W3C standard
PAGE 37
41. What is WSDL
•
•
•
•
WSDL stands for Web Services Description Language
WSDL is used to describe and locate Web Services
WSDL is based on XML
WSDL is a W3C standard
PAGE 43
42. WSDL
• Describes three fundamental properties
• What a service does
•
•
How a service is accessed
•
•
Operations (methods) provided by the service
Data format and protocol details
Where a service is located
•
Address (URL) details
PAGE 44
43. WSDL Document Structure
WSDL Specification
abstract part
types
messages
operations
Main structure of WSDL document
<definitions targerNamespace= ... >
<types>definition of types...</types>
<message>definition of a message...</message>
port types
<portType>definition of a port</portType>
concrete part
bindings
service
port
<binding>definition of a binding...</binding>
<service>
<port>...</port>
</service>
</definitions>
PAGE 45
45. Operation Types
Type
Definition
One-way
The operation can receive a message but will not return
a response
Requestresponse
The operation can receive a request and will return a
response
Solicit-response The operation can send a request and will wait for a
response
Notification
The operation can send a message but will not wait for
a response
PAGE 47
49. What is UDDI
• UDDI stands for Universal Description, Discovery and Integration
• UDDI a standard for publishing and discovering Web services
• UDDI is a specification for a distributed registry of Web services
• UDDI is built upon standards such as HTTP, XML, XML Schema,
SOAP, WSDL
• UDDI can communicate via SOAP, CORBA, Java RMI Protocol
• UDDI uses WSDL to describe interfaces to Web Services
PAGE 51
50. Ways to Use UDDI Registry
• White pages
– name, address, contact person, Web site
• Yellow pages
– types of business, locations, products, services,
categorizations
• Green pages
– technical information about business services, pointers
to WSDL descriptions of the services
PAGE 52
51. UDDI Data Model:
UDDI Core Data Types
Example: http://www.tutorialspoint.com/uddi/uddi_data_model.htm
PAGE 53
54. Big Web Services Examples
• http://www.xmethods.com
• http://www.programmableweb.com/
PAGE 56
55. Web services enable
1.
2.
3.
4.
data exchange between various applications and different platforms
to resolve interoperability issues
applications to function between two different operating systems server
all of the above
PAGE 57
56. Which of the following is used to locate
and describe web services?
1.
2.
3.
4.
SOAP
Web page
WSDL
UDDI
PAGE 58
58. Big Web Service Operations vs
RESTful Web Service URIs
Big WS operations
RESTful WS URIs
getAllUsers()
http://example.com/users/
"
getUserById(String id)
http://example.com/users/id/{user-id}
getUserByName(…),
addUser(…)
removeUser(…),
updateUser(…)
http://example.com/users/name/{user-name}
PAGE 60
59. Big Web Services versus REST
• A SOAP service has a single endpoint
• that handles all the operations
• therefore it has to have an application-specific
interface.
• A RESTful service has a number of resources
• so the operations can be distributed onto the resources
• and mapped to a small uniform set of operations.
PAGE 61
60. Comparison:
Big Web Services vs RESTful Web Services
• Big Web Services pros:
– protocol transparency and independence
– existence of tools to hide the complexity
– security
• Big Web Services cons:
–
–
–
–
–
rudimentary processing protocol
complexity
heavyweight architecture
do not get the benefits of resource-oriented services
opaqueness
PAGE 62
61. Comparison:
Big Web Services vs RESTful Web Services
• RESTful Web Services pros:
–
–
–
–
–
–
simplicity
lightweight infrastructure
addressability
uniform interface
scalability of stateless RESTful Web Service
improved performance using JSON
• RESTful Web Services cons:
–
–
–
–
bound to one protocol: HTTP
only POST and GET can be used in XHTML form
dealing with large input data - malformed URI
security issues
PAGE 63
62. Sources
• Cesare Pautasso,Olaf Zimmermann,Frank Leymann (2008)
RESTful Web Services vs. Big Web Services: Making the Right
Architectural Decision. Proc. of the 17th International World
Wide Web Conference (WWW2008), Bejing, China, April 2008.
• Alex Rodriguez. (2008). RESTful Web services: The basics.
Available at:
http://www.ibm.com/developerworks/webservices/library/wsrestful/
• Cesare Pautasso and Erik Wilde. Design Principles, Patterns
and Emerging Technologies for RESTful Web Services.
http://dret.net/netdret/docs/rest-icwe2010/
• Bernhard Hasl. RESTful web service APIs
http://courses2.cit.cornell.edu/info4302_2012fa/lectures/week7/
INFO_CS4302_Lecture12.pdf
PAGE 64