User Tools

Site Tools


sysrep:tp2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sysrep:tp2 [2012/11/14 12:31] orelsysrep:tp2 [2024/03/18 15:06] (current) – external edit 127.0.0.1
Line 2: Line 2:
 ====== TP2 : Web Services ====== ====== TP2 : Web Services ======
  
 +On suppose le serveur Apache Tomcat correctement installé (cf. TP1).
  
-Guide utilisateur : http://ws.apache.org/axis/java/user-guide.html+__Documentation__
  
-On suppose le serveur Apache Tomcat correctement installé (cfTP1).+  * Guide utilisateur Axis : http://ws.apache.org/axis/java/user-guide.html 
 +  * Un peu d'aide sur WSDL : http://msdn.microsoft.com/fr-fr/library/bb469924.aspx
  
 ==== Installation de Axis ==== ==== Installation de Axis ====
Line 12: Line 14:
 nomme ce répetoire <axis> nomme ce répetoire <axis>
  
-  wget http://apache.cict.fr/ws/axis/1_4/axis-bin-1_4.tar.gz +  wget http://apache.crihan.fr/dist/ws/axis/1_4/axis-bin-1_4.tar.gz 
 +  wget http://apache.mirrors.multidist.eu/axis/axis/java/1.4/axis-bin-1_4.tar.gz 
 +  
 Configurer votre environnement Bash. Configurer votre environnement Bash.
  
Line 22: Line 25:
 ==== Déploiement avec JWS==== ==== Déploiement avec JWS====
  
-Déployez avec JWS le service web fourni dans le fichier +Déployez avec JWS les services webs suivants 
-"HelloWorld.java"+
  
-<code java HelloWorld.java>+<code java HelloWorld.java>
 public class HelloWorld public class HelloWorld
 { {
Line 35: Line 37:
 </code> </code>
  
-Consultez le guide utilisateur de Axis pour mettre +<code java Calculator.java> 
-en place ce service et tester la méthode "HelloWorld()" à partir de +public class Calculator { 
-votre navigateur web. Afficher la description WSDL du service.+  public int add(int i1, int i2) { 
 +    return i1 + i2;  
 +  } 
 + 
 +  public int subtract(int i1, int i2) { 
 +    return i1 - i2; 
 +  } 
 +
 +</code> 
 + 
 +  * Consultez le guide utilisateur de Axis pour mettre en place ce service et tester les méthodes à partir de votre navigateur web.  
 +  * Affichez la description WSDL du service. 
 + 
 +====Client Statique JAX-RPC==== 
 + 
 +Récupérez la description WSDL du service HelloWorld, puis générez les stubs avec la commande : 
 + 
 +  java  -cp ${AXIS_HOME}/lib/\* org.apache.axis.wsdl.WSDL2Java HelloWorld.wsdl 
 + 
 +Compilez les fichiers stubs.  
 + 
 +Ecrire un client Java statique. Pour ce faire, il faut utiliser la classe "HelloWorldServiceLocator" pour instancier le stub. Il se manipule ensuite comme un objet de type HelloWorld. 
 + 
 +<code java HelloWorldStaticClient.java> 
 +import java.rmi.RemoteException; 
 +import javax.xml.rpc.ServiceException; 
 +import localhost.axis.HelloWorld_jws.*; 
 + 
 +public class HelloWorldStaticClient 
 +
 +    public static void main(String[ ] args)  
 + throws ServiceException, RemoteException 
 +    {  
 + HelloWorldService locator = new HelloWorldServiceLocator(); 
 + HelloWorld stub = locator.getHelloWorld(); 
 + String returnValue = stub.test("toto"); 
 + System.out.println(returnValue); 
 +    } 
 +
 +</code> 
 + 
 +Pour compiler et exécuter : 
 +  
 +<code bash> 
 +  $ javac -cp ${AXIS_HOME}/lib/\* HeloWorldStaticClient.java localhost/axis/HelloWorld_jws/*.java 
 +  $ java -cp ${AXIS_HOME}/lib/\*:. HeloWorldStaticClient 
 +</code>   
 +   
 +====Utilisation d'un Web Service sur Internet==== 
 + 
 +Ecrire un client statique pour un web service SOAP 1.2 trouvé sur le web.  
 + 
 +Par exemple :  
 + 
 +  * http://wsf.cdyne.com/WeatherWS/Weather.asmx 
 +  * http://www.webservicex.net/CurrencyConvertor.asmx 
 +  * http://footballpool.dataaccess.eu/data/info.wso 
 +  * http://chennaiemergency.co.in/sree/s2.php
  
 ====Client Dynamique JAX-RPC==== ====Client Dynamique JAX-RPC====
Line 83: Line 142:
   java org.apache.axis.utils.tcpmon [listenPort targetHost targetPort]   java org.apache.axis.utils.tcpmon [listenPort targetHost targetPort]
  
-====Client Statique JAX-RPC==== 
- 
-Récupérez l'interface WSDL, puis générer les stubs avec la commande 
-"java org.apache.axis.wsdl.WSDL2Java <wsdl-file>". Compilez ces 
-derniers.  
- 
-Ecrire un client Java statique. Pour ce faire, il faut utiliser la 
-classe "HelloWorldServiceLocator" pour instancier le stub. Il se 
-manipule ensuite comme un objet de type HelloWorld. 
- 
-<code java HelloWorldStaticClient.java> 
-import java.rmi.RemoteException; 
-import javax.xml.rpc.ServiceException; 
-import localhost.axis.HelloWorld_jws.*; 
- 
-public class HelloWorldStaticClient 
-{ 
-    public static void main(String[ ] args)  
- throws ServiceException, RemoteException 
-    {  
- HelloWorldService locator = new HelloWorldServiceLocator(); 
- HelloWorld stub = locator.getHelloWorld(); 
- String returnValue = stub.test("toto"); 
- System.out.println(returnValue); 
-    } 
-} 
-</code> 
  
 ====Déploiement avec WSDD==== ====Déploiement avec WSDD====
Line 117: Line 149:
 HelloWorld.java, fournie ci-dessous. HelloWorld.java, fournie ci-dessous.
  
-<code java>+<code java HelloWorld.java >
   public interface HelloWorld {   public interface HelloWorld {
     public java.lang.String test(java.lang.String data);     public java.lang.String test(java.lang.String data);
Line 150: Line 182:
  
   $ java org.apache.axis.client.AdminClient MyServices/deploy.wsdd   $ java org.apache.axis.client.AdminClient MyServices/deploy.wsdd
- 
sysrep/tp2.1352896288.txt.gz · Last modified: 2024/03/18 15:05 (external edit)