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 11:55] 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éployer avec JWS le service web fourni dans le fichier +Déployez avec JWS les services webs suivants.   
-"HelloWorld.java"Consulter le guide utilisateur de Axis pour mettre + 
-en place ce service et tester la méthode "HelloWorld()" à partir de +<code java HelloWorld.java
-votre navigateur web. Afficher la description WSDL du service.+public class HelloWorld 
 +
 +    public String test(String data) 
 +    { 
 + return "Hello World! You sent the string '" + data + "'."; 
 +    } 
 +
 +</code> 
 + 
 +<code java Calculator.java> 
 +public class Calculator { 
 +  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====
  
-Consultez le fichier "HelloWorldClient.java"Vérifiez que le ENDPOINT est correct : "http://localhost:8080/axis/HelloWorld.jws".+Consultez le fichier "HelloWorldClient.java" 
 + 
 +<code java HelloWorldClient.java> 
 +import java.net.MalformedURLException; 
 +import java.net.URL; 
 +import java.rmi.RemoteException; 
 +import javax.xml.namespace.QName; 
 +import javax.xml.rpc.ServiceException; 
 +import org.apache.axis.client.Call; 
 +import org.apache.axis.client.Service; 
 + 
 +public class HelloWorldClient 
 +
 +     
 +    private static final String ENDPOINT "http://localhost:1234/axis/HelloWorld.jws"
 +    private static final String NAMESPACE = "http://soapinterop.org/"; 
 +    private static final String OPERATION = "test"; 
 +     
 +    public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException 
 +    {  
 + Service service = new Service();  
 + Call call = (Call)service.createCall(); 
 + call.setTargetEndpointAddress(new URL(ENDPOINT)); 
 + call.setOperationName(new QName(NAMESPACE, OPERATION));  
 + String returnValue = (String)call.invoke(new Object[]{"toto"});        
 + System.out.println(returnValue); 
 +    } 
 +
 +</code> 
 + 
 +Vérifiez que le ENDPOINT est configuré correctement pour votre serveur. 
 + 
 +Compilez et testez ce client.
  
   $ export CLASSPATH="${AXIS_HOME}/lib/*:"    $ export CLASSPATH="${AXIS_HOME}/lib/*:" 
Line 35: Line 138:
   $ java HelloWorldClient   $ java HelloWorldClient
  
-Compiler et tester ce client. En utilisant tcpmon, intercepté les + En utilisant tcpmon, intercepté les messages SOAP.
-messages SOAP.+
  
   java org.apache.axis.utils.tcpmon [listenPort targetHost targetPort]   java org.apache.axis.utils.tcpmon [listenPort targetHost targetPort]
  
-====Client Statique JAX-RPC==== 
- 
-Récupérer l'interface WSDL, puis générer les stubs avec la commande 
-"java org.apache.axis.wsdl.WSDL2Java <wsdl-file>". Compiler ces 
-derniers. Ecrire un client Java statique. Pour ce faire, utiliser la 
-classe "HelloWorldServiceLocator" pour instancier le stub. Il se 
-manipule ensuite comme un objet de type HelloWorld. 
  
 ====Déploiement avec WSDD==== ====Déploiement avec WSDD====
Line 54: 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 87: Line 182:
  
   $ java org.apache.axis.client.AdminClient MyServices/deploy.wsdd   $ java org.apache.axis.client.AdminClient MyServices/deploy.wsdd
- 
sysrep/tp2.1352894103.txt.gz · Last modified: 2024/03/18 15:05 (external edit)