Académique Documents
Professionnel Documents
Culture Documents
Mineure SOA
Web Services
Idir AIT SADOUNE
idir.aitsadoune@supelec.fr
Plan
Qu'est-ce qu'un Web Service ?
1.
2.
3.
4.
Dfinition et principe
Rappels sur le protocole HTTP
Rappels sur le langage XML
Implmentation des Web Services
Standards et acteurs
Principales technologies : WSDL, SOAP, UDDI
Exposer une application Java sous la forme d'un Web Service WS-*
Appeler un Web Service WS-* en Java
Principes
Appeler un Web Service RESTful en Java
Exposer une application Java sous la forme d'un Web Service RESTful
Dcouverte
HTTP +
XML
Publication
Client
Fournisseur
Internet
Application
Web Service
Utilisation
Interface
Annuaire
Client
Enregistrement
Dploiement
du service
Recherche du service A
Voici ladresse du serveur
qui hberge A
Quel format utiliser pour le service A ?
Contrat de service
Requte
Rponse
vendredi 5 dcembre 2014
HTTP +
XML
5
o Rponse
o En-tte : code de statut, type
de serveur, type de contenu
o Contenu de la ressource demande
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7
Last-Modified: Wed, 08 Jan 2003 23:11:55
GMT Etag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8
Exemple
o Accs en lecture une page web pour affichage dans un navigateur
Serveur web
www.free.fr
Client
1 Requte :
GET http://idir.aitsadoune.free.fr/index. html
3 Affichage :
interprtation
HTML
\htdocs\idir.aitsadoune\
HTML
HTML
index. html
2 Rponse :
contenu de index.html
index. html
text/xml
audio/mpeg
image/jpeg
application/pdf
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7
Last-Modified: Wed, 08 Jan 2003 23:11:55
GMT Etag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8
Idir AIT SADOUNE - <idir.aitsadoune@supelec.fr>
prenom
nom
Gaston
Lagaffe
date_naissance
compagnie
vendredi 5 dcembre 2014
adresse
boite_postale
ville
poids
taille
unite
180
cm
code_postal pays
prenom
nom
Gaston
Lagaffe
date_naissance
compagnie
vendredi 5 dcembre 2014
personne
adresse
boite_postale
ville
poids
taille
unite
180
cm
code_postal pays
10
<personne>
<prenom>Gaston</prenom>
<nom>Lagaffe</nom>
</personne>
11
Fournisseur
Internet
Web Service
Interface
12
Ct fournisseur
Client
Fournisseur
Internet
Application
Web Service
Interface
13
Ct client
Client
Fournisseur
Internet
Application
Web Service
Interface
14
Plan
Qu'est-ce qu'un Web Service ?
1.
2.
3.
4.
Dfinition et principe
Rappels sur le protocole HTTP
Rappels sur le langage XML
Implmentation des Web Services
Standards et acteurs
Principales technologies : WSDL, SOAP, UDDI
Exposer une application Java sous la forme d'un Web Service WS-*
Appeler un Web Service WS-* en Java
Principes
Appeler un Web Service RESTful en Java
Exposer une application Java sous la forme d'un Web Service RESTful
15
Principales technologies
Annuaire de services
SOAP/UDDI
Dcouverte
SOAP/UDDI
Publication
Client
Fournisseur
Internet
Application
Web Service
Utilisation
SOAP
vendredi 5 dcembre 2014
Interface
WSDL
16
17
Acteurs majeurs
o W3C (World Wide Web Consortium)
o Consortium acadmique international fond en 1994
o Principal organisme de standardisation concernant le web
o HTTP, URI, HTML, XML
o Mcanisme de recommandations
18
Principales technologies
Annuaire de services
SOAP/UDDI
Dcouverte
SOAP/UDDI
Publication
Client
Fournisseur
Internet
Application
Web Service
Utilisation
SOAP
Interface
WSDL
19
20
Port
Port
Binding
Binding
Protocole de transport et
format des messages
PortType
Operation
Interface
du service
(fonctionnelle)
Input
Operation
Output
Message
Part
vendredi 5 dcembre 2014
Part
Type
Type
Type
21
<portType []>
<operation []>
<input [] />
<output [] />
</operation>
</portType>
Interface
du service
(fonctionnelle)
<binding []>[]</binding>
<service []>
<port []>[]</port>
</service>
Informations
techniques
</definitions>
vendredi 5 dcembre 2014
22
23
element="sayHello" />
24
<service name="HelloService">
<port name="HelloPort" binding="tns:HelloPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
vendredi 5 dcembre 2014
25
Principales technologies
Annuaire de services
SOAP/UDDI
Dcouverte
SOAP/UDDI
Publication
Client
Fournisseur
Internet
Application
Web Service
Utilisation
SOAP
vendredi 5 dcembre 2014
Interface
WSDL
26
o Objectif = formater les requtes et les rponses changes entre client et Web
Service pour le transport (notamment sur HTTP)
o Grammaire drive dXML
<Envelope>
o Dfinit principalement
o Un modle de structure pour les requtes et
les rponses (messages)
o Envelope : obligatoire, dfinit un message SOAP
o Header : optionnel, informations non applicatives
(scurit) ou destines aux intermdiaires
o Body : dcrit la requte ou la rponse
<Header>
<transId>1234</transId>
</Header>
<Body>
<add>
<varx>3</varx>
<vary>4</varY>
</add>
</Body>
</Envelope>
27
SOAP : Exemple
o Requte : sayHello("Robert")
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns:sayHello xmlns:ns="http://hello/">
<n>Robert</n>
</ns:sayHello>
</soap:Body>
</soap:Envelope>
28
Principales technologies
Annuaire de services
SOAP/UDDI
Dcouverte
SOAP/UDDI
Publication
Client
Fournisseur
Internet
Application
Web Service
Utilisation
SOAP
vendredi 5 dcembre 2014
Interface
WSDL
29
UDDI
o UDDI : Unversal Discovery Description and Integration
o Standard port par un consortium dindustriels
o Version 3 en 2005
Pages jaunes
Nom de la socit
Information sur les contacts
Description texte
Identifications (DUNS, SIRET, etc.)
Pages vertes
Procdures e-business
Descriptions technique des services
Paramtres des services
30
31
32
Client
Fournisseur
Internet
Application
Web Service
SOAP/HTTP
Interface
Java
JAX-WS
+JAXB
WSDL
Java
JAX-WS
+JAXB
33
Correspondance
annotation WSDL
= JAX-WS
34
35
o Donnes ncessaires :
o Schma XML Schema
o ou classes Java annotes
o Oprations supportes :
o Compilation : XML Schma classe Java annote
o Excution : objet Java reprsentation XML
= marshalling/unmarshalling
o Validation
36
}
vendredi 5 dcembre 2014
37
o Principe =
1. Implmenter la logique mtier
2. Gnrer automatiquement le contrat
WSDL pour le publier
o Avantages
o Avantages
o Simple raliser
o Utilit pour exposer du code legacy,
ou pour faire des tests
o Inconvnients
o Inconvnients
o Plus complexe raliser
38
Client
Fournisseur
Internet
Application
Web Service
SOAP/HTTP
Interface
Java
JAX-WS
+JAXB
WSDL
Java
JAX-WS
+JAXB
39
JAX-WS
40
Il est possible
de gnrer
automatiqueme
nt un client :
voir les
exercices
41
Client
Fournisseur
Internet
Application
Web Service
SOAP/HTTP
Interface
Java
JAX-WS
+JAXB
WSDL
Java
JAX-WS
+JAXB
42
Problmatique de linteroprabilit
o Problme = variations dans les implmentations des standards
o WS-I (Web Service Interoperability)
o Consortium dditeurs de logiciels
o Objectif = assurer linteroprabilit
entre les implmentations des normes
lies aux Web Services
o Produit
STAN D ARD S
SPECI FI CATI ON S
BESOI N S
GUI D E
D I M PLEM EN TATI ON
BESOI N S
43
Plan
Qu'est-ce qu'un Web Service ?
1.
2.
3.
4.
Dfinition et principe
Rappels sur le protocole HTTP
Rappels sur le langage XML
Implmentation des Web Services
Standards et acteurs
Principales technologies : WSDL, SOAP, UDDI
Exposer une application Java sous la forme d'un Web Service WS-*
Appeler un Web Service WS-* en Java
Principes
Appeler un Web Service RESTful en Java
Exposer une application Java sous la forme d'un Web Service RESTful
44
45
o Contraintes de conception :
o Oprations idempotentes
o Pas de session client-serveur (mais le client ou le serveur peut tre stateful)
46
o Equivalent SOAP
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<serv:reverse
xmlns:serv="http://open.mapquestapi.com/nominatim/v1/">
<format>xml</format>
<lat>48.7099500104522</lat>
<lon>2.16758762635404</lon>
</serv:reverse >
</soap:Body>
</soap:Envelope>
47
<addressparts>
<bus_stop>Le Moulon</bus_stop>
<road>Rue Joliot-Curie</road>
<suburb>Montjay</suburb>
<city>Gif-sur-Yvette</city>
<administrative>Palaiseau</administrative>
<county>Essonne</county>
<state>le-de-France</state>
<postcode>91400</postcode>
<country>France mtropolitaine</country>
<country_code>fr</country_code>
</addressparts>
</reversegeocode>
vendredi 5 dcembre 2014
48
49
50
@GET
@Produces("text/plain")
public String getHello() {
return "Hello "+this.getName()+" !";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
vendredi 5 dcembre 2014
51
public HelloResource(){
this.name="Robert";
}
@GET
@Produces("text/plain")
public String getHello() {
return "Hello "+this.getName()+" !";
}
@POST
+ consomme et produit du texte
@Consumes("text/plain")
@Produces("text/plain")
public String putHello(String content) {
this.setName(content);
return "New name = "+this.getName();
}
}
vendredi 5 dcembre 2014
52