![Page 1: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/1.jpg)
Architecture Orientee Service, JSON et API REST
Ludovic DENOYER - [email protected]
UPMC
3 fevrier 2015
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 2: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/2.jpg)
Precedemment, en LI328
Architecture generale du projet
Programmation serveur
Servlet/TOMCAT
Aujourd’hui
Quelques mots sur les SOA
API - REST
Le format JSON
API - REST et Servlet
API - SOAP (un peu)
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 3: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/3.jpg)
Paradigmes de programmation
Differents paradigmes :
Procedures
Programmation Orientee Objet
Programmation Orientee Composants
Programmation Orientee Service
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 4: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/4.jpg)
Paradigmes de programmation
Differents paradigmes :
Procedures
(source wikipedia)
La programmation procedurale est un paradigme deprogrammation base sur le concept d’appel procedural. Uneprocedure contient simplement une serie d’etapes a realiser.N’importe quelle procedure peut etre appelee a n’importe quelleetape de l’execution du programme.
Programmation Orientee Objet
Programmation Orientee Composants
Programmation Orientee Service
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 5: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/5.jpg)
Paradigmes de programmation
Differents paradigmes :
Procedures
Programmation Orientee Objet
(source wikipedia)
Un objet represente un concept, une idee ou toute entite du mondephysique. Il possede une structure interne et un comportement, etil sait communiquer avec ses pairs. Il s’agit donc de representer cesobjets et leurs relations ; la communication entre les objets vialeurs relations permet de realiser les fonctionnalites attendues, deresoudre le ou les problemes.
Programmation Orientee Composants
Programmation Orientee Service
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 6: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/6.jpg)
Paradigmes de programmation
Differents paradigmes :
Procedures
Programmation Orientee Objet
Programmation Orientee Composants
(source wikipedia)
La programmation orientee composant (POC) consiste a utiliserune approche modulaire au niveau de l’architecture d’un projetinformatique, ce qui permet d’assurer au logiciel une meilleurelisibilite et une meilleure maintenance. Les developpeurs, au lieu decreer un executable monolithique, se servent de briquesreutilisables.
Programmation Orientee Service
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 7: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/7.jpg)
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 8: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/8.jpg)
Architecture orientee Service
Une architecture orientee services (notee SOA pour ServicesOriented Architecture) est une architecture logicielle s’appuyantsur un ensemble de services simples. Elle permet de decomposerune fonctionnalite en un ensemble de fonctions basiques, appeleesservices, fournies par des composants et de decrire finement leschema d’interaction entre ces services.Lorsque l’architecture SOA s’appuie sur des web services, on parlealors de WSOA, pour Web Services Oriented Architecture.
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 9: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/9.jpg)
Avantages des WS
Les services Web fournissent l’interoperabilite entre diverslogiciels fonctionnant sur diverses plates-formes.
Les services Web utilisent des standards et protocoles ouverts.
Les protocoles et les formats de donnees sont au format textedans la mesure du possible, facilitant ainsi la comprehensiondu fonctionnement global des echanges.
Bases sur le protocole HTTP, les services Web peuventfonctionner au travers de nombreux pare-feu sans necessiterdes changements sur les regles de filtrage.
Les outils de developpement, s’appuyant sur ces standards,permettent la creation automatique de programmes utilisantles services Web existants.
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 10: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/10.jpg)
Inconvenients des WS
Les normes de services Web dans certains domaines sontactuellement recentes.
Les services Web souffrent de performances faibles comparee ad’autres approches de l’informatique repartie telles que leRMI, CORBA, ou DCOM.[ref. necessaire]
Par l’utilisation du protocole HTTP, les services Web peuventcontourner les mesures de securite mises en place au traversdes pare-feu.
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 11: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/11.jpg)
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 12: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/12.jpg)
Les Web Services
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 13: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/13.jpg)
API REST (Wikipedia)
REST
REST = REpresentational State Transfer
C’est une maniere de construire une application pour lessystemes distribues
REST n’est pas un protocole ou un format, c’est un styled’architecture
Il est de plus en plus utilise pour la realisation d’architecturesorientees services utilisant des services Web destines a lacommunication entre machines.
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 14: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/14.jpg)
API REST
Principes
l’URI est important : connaıtre l’URI doit suffire pour nommeret identifier une ressource.
HTTP fournit toutes les operations necessaires (GET, POST,PUT et DELETE, essentiellement).
Chaque operation est auto-suffisante : il n’y a pas d’etat.
Utilisation des standards hypermedia : HTML ou XML ouJSON
Reference : RESTful Web Services, par Leonard Richardson etSam Ruby
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 15: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/15.jpg)
API REST : Exemple Twitter
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 16: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/16.jpg)
API REST : Exemple Flickr
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 17: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/17.jpg)
API REST : Exemple Flickr
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 18: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/18.jpg)
API REST : Exemple Flickr
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 19: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/19.jpg)
API REST : Exemple Flickr
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 20: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/20.jpg)
API REST : Principes
Principes Generaux
Les parametres sont passe (a travers HTTP) en utilisant leprotocole GET (le plus souvent)
La reponse est un document sous forme JSON ou XML
Avantages
Simplicite
Lisibilite par l’humain
Evolutivite
Repose sur les principes du Web
Representations multiples
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 21: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/21.jpg)
Avantages
Simplicite
Lisibilite par l’humain
Evolutivite
Repose sur les principes du Web
Representations multiples
Inconvenients
Securite restreinte par l’emploi de HTTP
Cible uniquement l’appel de ressources
Architecture orientee ressources (ROA)ou Architecture orientee donnees (DOA)
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 22: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/22.jpg)
REST vs SOAP
Les Services Web etendus (SOAP) et les Services Web REST sontdifferents par le fait que :
Services Web etendus (SOAP)
Avantages
StandardiseInteroperabiliteSecurite (WS-Security)Outille
Inconvenients
Performances (enveloppe SOAP supplementaire)Complexite, lourdeurCible l’appel de service
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 23: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/23.jpg)
JSON
JavaScript Object Notation
Initialement cree pour la serialisation et l’echange d’objetsJavaScript
Langage pour l’echange de donnees semi-structurees (eteventuellement structurees)
Format texte independant du language de programmationutilise pour le manipuler.
Assez proche du XML, mais moins c**** embetant
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 24: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/24.jpg)
JSON
Un document JSON ne comprend que deux elements structurels :
des ensembles de paires nom / valeur ;
des listes ordonnees de valeurs.
Ces memes elements representent 3 types de donnees :
des objets ;
des tableaux ;
des valeurs generiques de type tableau, objet, booleen,nombre, chaine ou null.
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 28: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/28.jpg)
JSON et JAVA
Nous allons utiliser la librairie JSONObject de JAVA.
Un JSONObject est une collection non-ordonnee de pairesnom/valeur
La methode put permet d’ajouter une paire a l’objet
Le texte de la methode toString est conforme a laspecification JSON
1 myString = new JSONObject ().put("JSON", "Hello ,World!"). toString ();
2 // myString is {"JSON": "Hello , World"}
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 29: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/29.jpg)
TOMCAT et REST
12 public class Example extends HttpServlet
3 {
4 .....
56 protected void doGet(HttpServletRequest request , HttpServletResponse response) throws ServletException , IOException
7 {
8 response.setContentType("text/plain");
9 String prenom=request.getParameter("prenom");
10 if (prenom ==null)
11 {
12 JSONObject json=new JSONObject ();
13 try {
14 json.put("error","Missing parameter");
15 } catch (JSONException e) {
16 e.printStackTrace ();
17 }
18 response.getWriter (). println(json.toString ());
19 }
20 else
21 {
22 JSONObject json=new JSONObject ();
23 try {
24 json.put("output","OK");
25 } catch (JSONException e) {
26 // TODO Auto -generated catch block
27 e.printStackTrace ();
28 }
29 response.getWriter (). println(json.toString ());
30 }
31 }
32 }
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 30: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/30.jpg)
Conclusion
Conclusion
Vous connaissez :
TOMCAT
REST
TD / TP
Specifier les services a developper
Mettre en place l’architecture des services (en attendantl’acces au BDs)
Prochain Cours : SQL et JDBC
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST
![Page 31: Architecture Orientée Service, JSON et API RESTdenoyer/wordpress/wp-content/uploads/2015/01/... · Ludovic DENOYER - ludovic.denoyer@lip6.fr Architecture Orient ee Service, JSON](https://reader034.vdocuments.site/reader034/viewer/2022051407/5ad113f47f8b9aca598e67eb/html5/thumbnails/31.jpg)
Quelques mots sur le projet
Vous devez tenir a jour un fichier specifiant les servicesdeveloppes (a developper)
Les rappels de cours seront evalues lors des TDs
Vous devez separer les traitements des servlets et tester vostraitements avant de deployer les servlets. Une (grosse) erreurdans vos servlet risque de faire planter tout le serveur et donctous les servlets de vos camarades
Les binomes de travail devront etre fixes definitivement lorsdu prochain TD
Ludovic DENOYER - [email protected] Architecture Orientee Service, JSON et API REST