CS5220 Advanced Topics in Web Programming Web Services

Slides:



Advertisements
Similar presentations
18 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Introduction to Web Services.
Advertisements

31242/32549 Advanced Internet Programming Advanced Java Programming
Web Services Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
General introduction to Web services and an implementation example
SOAP : Simple Object Access Protocol
Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility.
RPC Robert Grimm New York University Remote Procedure Calls.
Web Services Darshan R. Kapadia Gregor von Laszewski 1http://grid.rit.edu.
Web Services Nasrullah. Motivation about web service There are number of programms over the internet that need to communicate with other programms over.
Presentation 7 part 2: SOAP & WSDL. Ingeniørhøjskolen i Århus Slide 2 Outline Building blocks in Web Services SOA SOAP WSDL (UDDI)
6/11/2015Page 1 Web Services-based Distributed System B. Ramamurthy.
Web Service What exactly are Web Services? To put it quite simply, they are yet another distributed computing technology (like CORBA, RMI, EJB, etc.).
Processing of structured documents Spring 2003, Part 6 Helena Ahonen-Myka.
Introduction SOAP History Technical Architecture SOAP in Industry Summary References.
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
WSDL Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
1 HKU CSIS DB Seminar: HKU CSIS DB Seminar: Web Services Oriented Data Processing and Integration Speaker: Eric Lo.
CSCI 6962: Server-side Design and Programming Web Services.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Web Services Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Web Services. ASP.NET Web Services  Goals of ASP.NET Web services:  To enable cross-platform, cross- business computing  Great for “service” based.
Distributed Programming CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Engineering Web Based Legacy Systems By Kanchana Eramudugoda Distributed Computing – CS843.
S imple O bject A ccess P rotocol Karthikeyan Chandrasekaran & Nandakumar Padmanabhan.
Kemal Baykal Rasim Ismayilov
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
Advanced Web Technologies Lecture #4 By: Faraz Ahmed.
An Introduction to Web Services Web Services using Java / Session 1 / 2 of 21 Objectives Discuss distributed computing Explain web services and their.
Web Services An Introduction Copyright © Curt Hill.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
.NET Mobile Application Development XML Web Services.
Net-centric Computing Web Services. Lecture Outline  What is Web Service  Web Service Architecture  Creating and using Java Web Services  Apache Axis.
CS520 Web Programming Introduction to Web Services Chengyu Sun California State University, Los Angeles.
Java Distributed Computing
Labs: Create, deploy and test a simple web service
Java Web Services Orca Knowledge Center – Web Service key concepts.
CS3220 Web and Internet Programming RESTful Web Service
CS520 Web Programming Introduction to Web Services
Introduction to Web Services
GF and RS, Dept of CS, Mangalore University
The Fedora Project March 10, 2003
CS5220 Advanced Topics in Web Programming Web Services
An Introduction to Web Services
Sabri Kızanlık Ural Emekçi
A Web Services Journey on the .NET Bus
WEB SERVICES.
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
Unit – 5 JAVA Web Services
GF and RS, Dept. of CS, Mangalore University
CORBA Alegria Baquero.
Web Services CO5027.
WEB API.
Web Server Administration
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
WEB SERVICES Mr. P. VASANTH SENA.
CORBA Alegria Baquero.
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Web services, WSDL, SOAP and UDDI
Implementation of Web Services in Perl by Litis Abraham & Gomathy Sankara CS522 Fall 2001 Semester Project 11/28/2018 Web Services in Perl.
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Creating a Distributed System with Remote Procedure Calls and Web Services Ch.5 B.Ramamurthy 2/17/2019 B.Ramamurthy.
Deepak Shenoy Agni Software
WebServices Using JAX-RPC
Introduction to Web Services
Distributed System using Web Services
Chapter 42 Web Services.
Distributed System using Web Services
Chengyu Sun California State University, Los Angeles
Presentation transcript:

CS5220 Advanced Topics in Web Programming Web Services Chengyu Sun California State University, Los Angeles

Client-Server Architecture in Network Programming data processing result

Client-Server Example username password processing first_name last_name age or user not found

Socket Programming – Client create socket write string to socket read string s from socket if( s == “user not found” ) return null; else return new User( s, read string from socket read integer from socket ) close socket Tedious networking code Application specific data exchange protocols

Client-Server Interaction as Function Calls User user = auth(username, password); Automatically translate function calls to network operations Encode and decode parameters and return values Send and receive data between the client and the server User auth(String u, String p) { … return user; } Server

RPC and RMI Remote Procedure Call (RPC) Remote Method Invocation (RMI) Java

RMI – Server Create a service interface Remote interface Declares the methods to be remotely invoked Create a service implementation Remote object Implements the methods to be remotely invoked Register the service with a RMI registry so a client can find and use this service

RMI – Client Include the remote interface Get an implementation of the remote interface by Connecting to the RMI registry Looking up the service by name Invoke the method

RMI Example: AuthService Shared by both server and client AuthService User Server AuthServiceImpl AuthServiceStartup Client AuthServiceClient Why does User have to implement the Serializable interface? What exactly does registry.lookup() return?

How RMI Works Client Server 1. Lookup Registry Client code 2. Stub (proxy) 0. Register 6. Return result 3. Method invocation Stub (Proxy) 4. Parameters Remote Object 5. Result Client Server

Cross Platform RPC Client Server C/C++ Java C# Python PHP … C/C++ Java C# Python PHP … ?? Windows Linux … Windows Linux … The client and the server use different languages and/or platforms How do we define service interface??

CORBA Common Object Request Broker Architecture Use Interface Definition Language (IDL) to describe service interface Provide mappings from IDL to other languages such as Java, C++, and so on. Java Service Interface in IDL Service Implementation C++ … Client Server

IDL Example module bank { interface BankAccount { exception ACCOUNT_ERROR { long errcode; string message;}; long querybalance(in long acnum) raises (ACCOUNT_ERROR); string queryname(in long acnum) raises (ACCOUNT_ERROR); string queryaddress(in long acnum) raises (ACCOUNT_ERROR); void setbalance(in long acnum, in long balance) raises (ACCOUNT_ERROR); void setaddress(in long acnum, in string address) raises (ACCOUNT_ERROR); };

(Traditional) Web Services RPC over HTTP Client and server communicate using HTTP requests and responses Many different web service protocols Language support: single language vs. language independent Message encoding: binary vs. text Most widely used: SOAP

Metro http://metro.java.net/ A Java web service library backed by SUN/Oracle Implementation of the latest Java web service specifications Guaranteed interoperability with .NET Windows Communication Foundation (WCF) web services Easy to use

Other Java Web Service Libraries Apache Axis2 http://axis.apache.org/axis2/java/core/ Apache CXF http://cxf.apache.org/

Web Service Example: HashService Dependency: org.glasshfish.metro:webservices-rt com.sun.activation:javax.activation (for JDK 10+) HashService @WebService and @WebMethod web.xml sun-jaxws.xml <endpoint>

WSDL A language for describing web services Where the service is What the service does How to invoke the operations of the service Plays a role similar to IDF in CORBA

Sample WSDL Documents HashService - http://localhost:8080/ws/hash?wsdl Amazon ECS - http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

How Do We Describe an API interface name Type interface Foo { … int bar( String, BigDecimal ) } Return value Method name Parameters

How Do We Describe an Web Service API WSDL Type <message> Parameters <input> Return value <output> Method name <operation> Interface name <portType>

Web Service Example: Consume HashService Generate client side interface and stub from WSDL using wsimport in JDK -s source code directory -p package for generated code URL of the WSDL document Write client code

SOAP http://www.w3.org/TR/soap/ Simple Object Access Protocol SOAP Web Service Client Web Service Implementation Client Server

A Sample SOAP Message <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsi=http://www.w3.org/1999/XMLSchema-instance xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:doSpellingSuggestion xmlns:ns1="urn:GoogleSearch" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <key xsi:type="xsd:string">00000000000000000000000000000000</key> <phrase xsi:type="xsd:string">britney speers</phrase> </ns1:doSpellingSuggestion> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

A Sample SOAP RPC Response <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsi=http://www.w3.org/1999/XMLSchema-instance xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:doSpellingSuggestionResponse xmlns:ns1="urn:GoogleSearch“ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <return xsi:type="xsd:string">britney spears</return> </ns1:doSpellingSuggestionResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

A Sample Fault Response <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Client</faultcode> <faultstring>Client Error</faultstring> <detail> <m:dowJonesfaultdetails xmlns:m="DowJones"> <message>Invalid Currency</message> <errorcode>1234</errorcode> </m:dowJonesfaultdetails> </detail> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

SOAP Encoding http://schemas.xmlsoap.org/soap/encoding/ Include all built-in data types of XML Schema Part 2: Datatypes xsi and xsd name spaces

SOAP Encoding Examples int a = 10; float x = 3.14159; String s = “SOAP”; <a xsi:type="xsd:int">10</a> <x xsi:type="xsd:float">3.14159</x> <s xsi:type="xsd:string">SOAP</s>

Compound Values and Other Rules <iArray xsi:type=SOAP-ENC:Array SOAP-ENC:arrayType="xsd:int[3]"> <val>10</val> <val>20</val> <val>30</val> </iArray> <Sample> <iVal xsi:type="xsd:int">10</iVal> <sVal xsi:type="xsd:string">Ten</sVal> </Sample> References, default values, custom types, complex types, custom serialization …

UDDI Universal Description Discovery and Integration A registry for web services A web API for publishing, retrieving, and managing information in the registry

UDDI Registries

Problems with SOAP Web Service Very complex Based on some very complex specifications Very difficult to create supporting libraries Virtually impossible to use without supporting libraries Not very efficient RESTful Web Services

A RESTful Web Service Request Get user with id=1: /service/user/1 XML Response or JSON Response <user> <id>1</id> <firstName>John</firstName> <lastName>Doe</lastName> <email>jdoe1@localhost</email> </user> { “id”: 1, “firstName”: “John”, “lastName”: “Doe”, “email”: “jdoe1@localhost” } A real-world example: https://dev.twitter.com/rest/public/search

Is That Really A Web Service? Where is the method call? Why does it look like a web application? Why is it called RESTful?

Where Is The Method Call? Answer: it’s kind of a method call … HTTP request: http://<host>/service/user/ 1 User user = getUser( 1 ); HTTP response The downside is that now it’s the client’s responsibility to turn an HTTP response into a “return value”, which is why the response is usually in XML or JSON format.

Why Does It Look Like A Web Application? Answer: it does, and it’s a good thing. Now all web technologies/languages/ platforms can be used to create web services (and you don’t have to implement complex specifications like SOAP).

Why Is It Called RESTful? REpresentational State Transfer Introduced by Roy Fielding in his Ph.D. dissertation on network-base software architecture Describes the common characteristics of scalable, maintainable, and efficient distributed software systems

The REST Constraints Client and server Stateless Support caching Uniformly accessible Layered (Optional) support code-on-demand

RESTful Web Services Web applications for programs Generate responses in formats to be read by machines (i.e. XML and JSON) rather than by humans (i.e. HTML) Simulate how the static web (the largest REST system) works Use URLs that look like URLs for static web pages Utilize HTTP request methods and headers Stateless, i.e. no session

RESTful API Example User Management List Get Add Update Delete

Resource Representation Data format should be easily “understandable” by all programming languages XML Already widely in use as a platform independent data exchange format XML parsers are readily available in many languages JSON Much more concise than XML Can be used directly in JavaScript

URL Design and Request Mapping Conventions (1) Operation: get a user URL /user/{id} or /user/get?id={id} Path variable based design is usually preferred to request parameter based design.

URL Design and Request Mapping Conventions (2) Operation: get a user Choose which data format to use Solution: /user/{id}.{format} Check the Accept request header Checking Accept header is preferred in theory, but the URL based solution is more convenient in practice, e.g. https://dev.twitter.com/rest/reference/get/users/lookup

URL Design and Request Mapping Conventions (3) Map HTTP Request Methods to CRUD operations POST GET PUT (or PATCH) DELETE Create Retrieve Update Delete

URL Design and Request Mapping Conventions (4) PUT vs PATCH Use PUT when the full object is provided Use PATCH when only some of the properties are provided

Request Mapping Example … Operation HTTP Request Get all users GET /users HTTP 1.1 Get a user GET /user/1 HTTP 1.1 Delete a user DELETE /user/1 HTTP 1.1 Add a user POST /users HTTP 1.1 { “firstName”:“John”, “lastName”:“Doe”, “email”:“jdoe@localhost”}

… Request Mapping Example Operation HTTP Request Update a user PUT /user/1 HTTP 1.1 { “id”:1, “firstName”:“Jane”, “lastName”:“Doe”, “email”:“jdoe@localhost”} Update a user PATCH /user/1 HTTP 1.1 { “firstName”:“Jane” }

Summary RPC and RMI CORBA SOAP, WSDL, UDDI RESTful web services IDL Create and consume SOAP web services using Metro RESTful web services

Readings The Rise and Fall of CORBA by Michi Henning Java Web Services Up and Running by Martin Kalin Security Fundamentals for Web Services RESTful Java Web Services by Jose Sandoval