sysrep:tp2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sysrep:tp2 [2012/11/14 11:55] – orel | sysrep: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:// | + | __Documentation__ |
- | On suppose le serveur Apache Tomcat correctement installé (cf. TP1). | + | * Guide utilisateur Axis : http://ws.apache.org/ |
+ | * Un peu d'aide sur WSDL : http:// | ||
==== Installation de Axis ==== | ==== Installation de Axis ==== | ||
Line 12: | Line 14: | ||
nomme ce répetoire < | nomme ce répetoire < | ||
- | wget http:// | + | wget http:// |
+ | wget http:// | ||
+ | | ||
Configurer votre environnement Bash. | Configurer votre environnement Bash. | ||
Line 22: | Line 25: | ||
==== Déploiement avec JWS==== | ==== Déploiement avec JWS==== | ||
- | Déployer | + | Déployez |
- | "HelloWorld.java" | + | |
- | en place ce service et tester | + | <code java HelloWorld.java> |
- | votre navigateur web. Afficher | + | public class HelloWorld |
+ | { | ||
+ | public String test(String data) | ||
+ | { | ||
+ | return "Hello World! You sent the string '" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <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; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | * Consultez | ||
+ | * Affichez | ||
+ | |||
+ | ====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}/ | ||
+ | |||
+ | Compilez les fichiers stubs. | ||
+ | |||
+ | Ecrire un client Java statique. Pour ce faire, il faut utiliser la classe " | ||
+ | |||
+ | <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, | ||
+ | { | ||
+ | HelloWorldService locator = new HelloWorldServiceLocator(); | ||
+ | HelloWorld stub = locator.getHelloWorld(); | ||
+ | String returnValue = stub.test(" | ||
+ | System.out.println(returnValue); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Pour compiler et exécuter : | ||
+ | |||
+ | <code bash> | ||
+ | $ javac -cp ${AXIS_HOME}/ | ||
+ | $ java -cp ${AXIS_HOME}/ | ||
+ | </ | ||
+ | |||
+ | ====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:// | ||
+ | * http:// | ||
+ | * http:// | ||
+ | * http:// | ||
====Client Dynamique JAX-RPC==== | ====Client Dynamique JAX-RPC==== | ||
- | Consultez le fichier " | + | Consultez le fichier " |
+ | |||
+ | <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 | ||
+ | private static final String NAMESPACE = " | ||
+ | private static final String OPERATION = " | ||
+ | |||
+ | public static void main(String[] args) throws ServiceException, | ||
+ | { | ||
+ | Service service = new Service(); | ||
+ | Call call = (Call)service.createCall(); | ||
+ | call.setTargetEndpointAddress(new URL(ENDPOINT)); | ||
+ | call.setOperationName(new QName(NAMESPACE, | ||
+ | String returnValue = (String)call.invoke(new Object[]{" | ||
+ | System.out.println(returnValue); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Vérifiez que le ENDPOINT est configuré correctement pour votre serveur. | ||
+ | |||
+ | Compilez et testez ce client. | ||
$ export CLASSPATH=" | $ export CLASSPATH=" | ||
Line 35: | Line 138: | ||
$ java HelloWorldClient | $ java HelloWorldClient | ||
- | Compiler et tester ce client. | + | 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' | ||
- | "java org.apache.axis.wsdl.WSDL2Java < | ||
- | derniers. Ecrire un client Java statique. Pour ce faire, utiliser la | ||
- | classe " | ||
- | manipule ensuite comme un objet de type HelloWorld. | ||
====Déploiement avec WSDD==== | ====Déploiement avec WSDD==== | ||
Line 54: | Line 149: | ||
HelloWorld.java, | HelloWorld.java, | ||
- | <code 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/ | $ java org.apache.axis.client.AdminClient MyServices/ | ||
- |
sysrep/tp2.1352894103.txt.gz · Last modified: 2024/03/18 15:05 (external edit)