LDAP: couldn't connect to LDAP server
Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
lpro:ws [2016/12/15 14:27] jbaudry [Exercice 3 : Consommer des WebServices en PHP/Java] |
lpro:ws [2017/12/18 09:58] (current) jbaudry [Liens webservices] |
||
|---|---|---|---|
| Line 20: | Line 20: | ||
| {{:lpro:05-rest.pdf| Introduction REST}} | {{:lpro:05-rest.pdf| Introduction REST}} | ||
| + | |||
| + | ==== Liens webservices ==== | ||
| + | * http://litis.univ-lehavre.fr/wiki/lpro/ws/rest | ||
| + | * Livres | ||
| + | * https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699 | ||
| + | * Adresse | ||
| + | * https://maps.googleapis.com/maps/api/geocode/json?address=universite%20du%20havre,%20france&sensor=false | ||
| + | * Iceland API gouv | ||
| + | * http://docs.apis.is/ | ||
| + | * Photos | ||
| + | * https://www.flickr.com/services/feeds/docs/photos_public/ | ||
| + | * Pays | ||
| + | * https://restcountries.eu | ||
| + | * Pays 2 | ||
| + | * https://geo.api.gouv.fr/communes?codePostal=76600&fields=nom,code,codesPostaux,codeDepartement,codeRegion,population&format=json&geometry=centre' | ||
| + | * Adresses | ||
| + | * https://adresse.data.gouv.fr/api/ | ||
| + | |||
| * http://blog.programmableweb.com/2012/01/11/12-json-weather-apis/ | * http://blog.programmableweb.com/2012/01/11/12-json-weather-apis/ | ||
| * [[lpro:ws:rest_php|Exemple en php]] | * [[lpro:ws:rest_php|Exemple en php]] | ||
| + | * WSDL : http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl | ||
| + | * WSDL La poste : {{ :lpro:spec_ws_suivi_en.pdf |}} | ||
| Line 72: | Line 92: | ||
| </code> | </code> | ||
| + | * Python | ||
| + | |||
| + | <code python> | ||
| + | from SOAPpy import WSDL | ||
| + | import zeep | ||
| + | |||
| + | client = zeep.Client('http://www.webservicex.net/ConvertSpeed.asmx?WSDL') | ||
| + | result = client.service.ConvertSpeed( | ||
| + | 102, 'kilometersPerhour', 'milesPerhour') | ||
| + | print result | ||
| + | </code> | ||
| ===== Exercice 2 : Consommer des WebServices en PHP / Java (Partie 2) ===== | ===== Exercice 2 : Consommer des WebServices en PHP / Java (Partie 2) ===== | ||
| * Conversion de température fahrenheit -> Celsius | * Conversion de température fahrenheit -> Celsius | ||
| * Réalisez le même exercice que précédemment en utilisant la fonction inverse pour convertir une température de fahrenheit -> Celsius. | * Réalisez le même exercice que précédemment en utilisant la fonction inverse pour convertir une température de fahrenheit -> Celsius. | ||
| - | * Utilisez Eclipse pour vous connecter à ce webservice | + | * Utilisez Eclipse pour vous connecter à ce webservice : http://www.webservicex.net/ConvertSpeed.asmx?WSDL |
| <code java> | <code java> | ||
| public static void main(String[] args) { | public static void main(String[] args) { | ||
| Line 89: | Line 120: | ||
| } | } | ||
| } | } | ||
| + | </code> | ||
| + | |||
| + | <code java> | ||
| + | public class TestSpeed { | ||
| + | |||
| + | public static void main(String[] args) { | ||
| + | // TODO Auto-generated method stub | ||
| + | ConvertSpeedsSoapProxy c = new ConvertSpeedsSoapProxy(); | ||
| + | |||
| + | SpeedUnit s1 = new SpeedUnit(SpeedUnit._kilometersPerhour); | ||
| + | SpeedUnit s2 = new SpeedUnit(SpeedUnit._milesPerhour); | ||
| + | try { | ||
| + | System.out.println(c.convertSpeed(102, s1, s2)); | ||
| + | } catch (RemoteException e) { | ||
| + | // TODO Auto-generated catch block | ||
| + | e.printStackTrace(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| </code> | </code> | ||
| ===== Exercice 3 : Consommer des WebServices en PHP/Java ===== | ===== Exercice 3 : Consommer des WebServices en PHP/Java ===== | ||
| Line 107: | Line 157: | ||
| * Créez votre propre fichier wsdl avec eclipse | * Créez votre propre fichier wsdl avec eclipse | ||
| * [[lpro:ws:ws_avec_wsdl|Exemple avec fichier WSDL]] | * [[lpro:ws:ws_avec_wsdl|Exemple avec fichier WSDL]] | ||
| + | * {{ :lpro:151216.zip |}} | ||
| * Exemple serveur php | * Exemple serveur php | ||
| Line 154: | Line 205: | ||
| ?> | ?> | ||
| </code> | </code> | ||
| + | |||
| + | * WSDL : Client | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | // Pour supprimer le cache du web-service | ||
| + | ini_set('soap.wsdl_cache_enabled', 0); | ||
| + | |||
| + | // Nouveau Client SOAP | ||
| + | try { | ||
| + | // Nouvelle instance de la classe soapClient | ||
| + | $client = new SoapClient('http://127.0.0.1/lpro/ws1/Hello.wsdl', array('trace' => 1)); | ||
| + | |||
| + | $parm = 'LPRO'; | ||
| + | // Appel de la méthode hellotest du service web | ||
| + | |||
| + | try{ | ||
| + | $oReturn = $client->bonjour("LPRO"); | ||
| + | |||
| + | } catch (Exception $e) { | ||
| + | echo 'erreur1'.$e; | ||
| + | } | ||
| + | catch (SoapFault $fault) { | ||
| + | echo "il y a une erreur"; | ||
| + | trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR); | ||
| + | } | ||
| + | // affiche le résultat | ||
| + | echo "Resultat : ".$oReturn."<br/>" ; | ||
| + | } catch (SoapFault $fault) { | ||
| + | echo 'erreur : '.$fault; | ||
| + | } | ||
| + | |||
| + | // Affichage des requetes et reponses SOAP (pour debug) | ||
| + | |||
| + | echo '<br />Requete SOAP : '.htmlspecialchars($client->__getLastRequest()).'<br />'; | ||
| + | |||
| + | echo '<br />Reponse SOAP : '.htmlspecialchars($client->__getLastResponse()).'<br />'; | ||
| + | |||
| + | echo '<br/>'.var_dump($oReturn); | ||
| + | |||
| + | ?> | ||
| + | </code> | ||
| + | |||
| + | * WSDL : server | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | // Pour supprimer le cache du web-service | ||
| + | ini_set('soap.wsdl_cache_enabled', 0); | ||
| + | // Pour définir le temp maximal d'éxecution de notre web-service | ||
| + | ini_set('default_socket_timeout', 180); | ||
| + | |||
| + | // Nom de notre web-service | ||
| + | class Server { | ||
| + | // Le service QuelJour que l'on a définit dans notre format wsdl | ||
| + | |||
| + | function bonjour($parm) { | ||
| + | return "bonjour ".$parm ; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | // On tente d'instancier la classe soapServer | ||
| + | // Si cela s'avère impossible, on affiche une erreur | ||
| + | try { | ||
| + | $server = new SoapServer('Hello.wsdl', array('trace' => 1,'encoding' => 'ISO-8859-1')); | ||
| + | // On définit la classe qui va gérer les requêtes SOAP (pour nous c'est la class Server) | ||
| + | $server->setclass('Server'); | ||
| + | $server->setPersistence(SOAP_PERSISTENCE_REQUEST); | ||
| + | } catch (Exception $e) { | ||
| + | echo 'erreur'.$e; | ||
| + | } | ||
| + | |||
| + | |||
| + | /* | ||
| + | * Gestion des requêtes | ||
| + | */ | ||
| + | |||
| + | // Si l'appel provient d'un Web-Service | ||
| + | if ($_SERVER['REQUEST_METHOD'] == 'POST') { | ||
| + | try { | ||
| + | $server -> handle();} | ||
| + | catch (Exception $e) { | ||
| + | echo 'erreur'.$e; | ||
| + | } | ||
| + | } | ||
| + | // Facultatif seulement pour montrer les fonctions disponibles par le web-service | ||
| + | else { | ||
| + | echo '<strong>This SOAP server can handle following functions : </strong>'; | ||
| + | echo '<ul>'; | ||
| + | foreach($server -> getFunctions() as $func) { | ||
| + | echo '<li>' , $func , '</li>'; | ||
| + | } | ||
| + | echo '</ul>'; | ||
| + | } | ||
| + | |||
| + | |||
| + | ?> | ||
| + | </code> | ||
| + | |||
| ====== Exercice 5 : Manipuler le format JSON (open data Nantes) ====== | ====== Exercice 5 : Manipuler le format JSON (open data Nantes) ====== | ||
| Line 162: | Line 313: | ||
| * Créez un formulaire pour retrouver une adresse complète | * Créez un formulaire pour retrouver une adresse complète | ||
| * https://adresse.data.gouv.fr/api/ | * https://adresse.data.gouv.fr/api/ | ||
| - | * Créez une page album des dernières images flickr : | + | * Créez une page album des dernières images flickr avec un formulaire de saisie: |
| * http://api.flickr.com/services/feeds/photos_public.gne?tags=90210&tagmode=all&format=json&nojsoncallback=1 | * http://api.flickr.com/services/feeds/photos_public.gne?tags=90210&tagmode=all&format=json&nojsoncallback=1 | ||
| Line 241: | Line 392: | ||
| //echo prettyPrint(prettyPrint($json)); | //echo prettyPrint(prettyPrint($json)); | ||
| //echo json_encode($json, JSON_PRETTY_PRINT); | //echo json_encode($json, JSON_PRETTY_PRINT); | ||
| - | |||
| - | ?> | ||
| - | </code> | ||
| - | |||
| - | * Webservice Json | ||
| - | |||
| - | <code php> | ||
| - | <?php | ||
| - | $keyword = "twitter"; | ||
| - | $keyword = $_POST["key"] ; | ||
| - | |||
| - | |||
| - | echo <<<EOB | ||
| - | <br/> | ||
| - | <center> | ||
| - | <form action="twitter.php" method="post"> | ||
| - | <p>Mot cle : <input type="text" name="key" value="{$keyword}" /> <input type="submit" value="OK"> </p> | ||
| - | </form> | ||
| - | </center> | ||
| - | EOB; | ||
| - | |||
| - | |||
| - | |||
| - | //$Flickr = file_get_contents("http://api.flickr.com/services/feeds/photos_public.gne?tags=".$keyword."&tagmode=all&format=json"); | ||
| - | |||
| - | $feed_Flickr = 'http://api.flickr.com/services/feeds/photos_public.gne?tags='.$keyword.'&lang=en-us&format=json&nojsoncallback=1'; | ||
| - | $Flickr = file_get_contents($feed_Flickr); | ||
| - | $flickrResponse = str_replace("\\'", "'", $Flickr); | ||
| - | $results = json_decode($flickrResponse, true); | ||
| - | |||
| - | print_r($results); | ||
| ?> | ?> | ||
| Line 292: | Line 412: | ||
| ===== Exercice 6 ===== | ===== Exercice 6 ===== | ||
| * [[lpro:exercice6|Rest exercice]] | * [[lpro:exercice6|Rest exercice]] | ||
| + | * Recherchez un webservice permettant de lister les villes en fonction d'un code postal | ||
| ===== Mots clés ===== | ===== Mots clés ===== | ||