1 / 48

AXIS

AXIS. Master MIAGE/SID – Université NANCY2. Généralités. Open source de Apache Software Foundation Moteur SOAP Compatible JAX-RPC Distribué avec des outils de développement et de monitoring Accompagné de documentation et d'exemples. Architecture JAX-RPC. WSDL. CLIENT. SERVICE. JAX-RPC.

tave
Télécharger la présentation

AXIS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AXIS Master MIAGE/SID – Université NANCY2 A. Roussanaly - Université Nancy2

  2. Généralités • Open source de Apache Software Foundation • Moteur SOAP • Compatible JAX-RPC • Distribué avec des outils de développement et de monitoring • Accompagné de documentation et d'exemples A. Roussanaly - Université Nancy2

  3. Architecture JAX-RPC WSDL CLIENT SERVICE JAX-RPC JAX-RPC API Client API Serveur SOAP HTTP A. Roussanaly - Université Nancy2

  4. Architecture Axis D'après Xavier Blanc La Servlet AxisServlet reçoit et renvoie les messages SOAP et transmet aux objets Java correspondant Les Objets Java effectuent les services. Ils sont des objets Java classiques. AxisServlet SOAP/HTTP Moteur de Servlet Le client envoie des messages SOAP/HTTP JVM Objets Java et Servlet sont dans la même JVM (pas de répartition). A. Roussanaly - Université Nancy2

  5. Axis2 Archives au format .aar AxisServlet SOAP/HTTP Moteur de Servlet JVM A. Roussanaly - Université Nancy2

  6. Activité : développer un serveur • Développer un serveur qui fournit le change de différentes monnaies par rapport au DM • Ecrire ensuite une application de conversion de monnaies (client) • Exemple d’opérations: • getDollar() • getFrancSuisse() • getLivre() • getYen() A. Roussanaly - Université Nancy2

  7. ARCHIVES A. Roussanaly - Université Nancy2

  8. Créer un service web avec Axis2… …et Eclipse for J2EE developper A. Roussanaly - Université Nancy2

  9. Configuration A. Roussanaly - Université Nancy2

  10. Créer un projet A. Roussanaly - Université Nancy2

  11. Ajouter automatiquement les jar de Axis2 dans lib A. Roussanaly - Université Nancy2

  12. A. Roussanaly - Université Nancy2

  13. A. Roussanaly - Université Nancy2

  14. Créer une classe A. Roussanaly - Université Nancy2

  15. Générer le WS A. Roussanaly - Université Nancy2

  16. A. Roussanaly - Université Nancy2

  17. A. Roussanaly - Université Nancy2

  18. A. Roussanaly - Université Nancy2

  19. A. Roussanaly - Université Nancy2

  20. Tester le service A. Roussanaly - Université Nancy2

  21. Axis Ecriture d’un serveur A. Roussanaly - Université Nancy2

  22. Projet Eclipse/Tomcat axis-change WEB-INF build.xmlproject.propertiesdeploy.wsddundeploy.wsddindex.jsp… lib classes src .class <ext-jars>axis.jaraxis-ant.jarwsdl4j.jarmail.jaractivation.jar… fr.miage.sid.axis.server .java web.xmlserver-config.wsddperms.lstusers.lst… A. Roussanaly - Université Nancy2

  23. Properties name=poub version=1.0 year=2006 debug=on deploy.file=deploy.wsdd undeploy.file=undeploy.wsdd service.host=localhost service.port=80 service.package=fr.miage.sid.axis.server A. Roussanaly - Université Nancy2

  24. Service « rapide » • Dans un premier temps, il nous faut un service ; Axis permet d’en créer de manière très rapide. • Pour notre application, nous allons créer un service qui nous permet d’obtenir le cours de différentes monnaies en euro. • Exemple d’opérations: • getDollar() • getFrancSuisse() • getLivre() • getYen() A. Roussanaly - Université Nancy2

  25. Change : service • Créer un programme source java • exemple : une classe Change qui fournit le taux de change de l’USD, CHF, JPY, GBP • Modifier l'extension .java du fichier source en .jws • Déployer le fichier .jws • copie dans %tomcat%\webapps\axis A. Roussanaly - Université Nancy2

  26. Listing : Change.jws public class Change { private double EU_USD = 1.251; private double EU_CHF = 1.592; private double EU_JPY = 149.00; private double EU_GBP = 0.670; public double getDollar(){return EU_USD;} public double getFrancSuisse(){return EU_CHF;} public double getYen(){return EU_JPY;} public double getLivre(){return EU_GBP;} } A. Roussanaly - Université Nancy2

  27. Test du service Change • Examiner sa description WSDL • http://localhost:8080/axis/Change.jws?wsdl • Enregistrer le fichier WSDL dans un projet Eclipse • Exemple : change.wsdl • Tester ce service avec les outils Eclipse/WTP • Menu contextuel Web Services sur change.wsdl et Test with Web services Explorer… A. Roussanaly - Université Nancy2

  28. Change : client • On peut maintenant écrire une application cliente du service change. • Par exemple, un convertisseur de monnaie : A. Roussanaly - Université Nancy2

  29. Ecriture « normale » d’un service • Usage des fichiers JWS limité : • Obligation de travailler avec le code source • Pas de possibilité de mappings • Pas de possibilité de contrôle avec un handler • On est donc amené à déployer des classes (ou éventuellement des jars) A. Roussanaly - Université Nancy2

  30. Ecriture « normale » d’un service • Le point de départ peut être : • un fichier WSDL : • On utilise alors l’outil WSDL2JAVA pour engendrer le « squelette » d’un serveur (skeleton) • une classe JAVA : • Le fichier WSDL est dynamiquement engendré par le servlet Axis A. Roussanaly - Université Nancy2

  31. Etapes • Développer le service et l’intégrer dans un projet Tomcat contenant le servlet Axis (autrement dit déployer le servlet Axis sous Tomcat) • A l’aide d’un fichier de descripteur de déploiement (WSDD) propre à Axis, déployer le service Axis • Il s’agit de mettre à jour le fichier de configuration server-config.wsdd qui se trouve dans le dossier WEB-INF d’Axis • On utilise l’outil AdminClient d’Axis A. Roussanaly - Université Nancy2

  32. Ant <taskdef name="axis-admin" classname="org.apache.axis.tools.ant.axis.AdminClientTask"> <classpath refid="classpath" /> </taskdef> <target name="deployer" description="Déploiement du serveur"> <axis-admin port="${service.port}" hostname="${service.host}" failonerror="true" servletpath="${name}/services/AdminService" debug="true" xmlfile="${deploy.file}" /> </target> A. Roussanaly - Université Nancy2

  33. WSDD <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="change" provider="java:RPC"> <parameter name="className" value="fr.miage.sid.axis.server.Change"/> <parameter name="allowedMethods" value="*"/> </service> </deployment> A. Roussanaly - Université Nancy2

  34. Explications • L’outil AdminClient s’appuie (1) sur les informations contenues dans le fichier WSDD et (2) sur les arguments passés en paramètres (host, port, axis-root) • axis.jar et axis-ant.jar doivent être dans le classpath. • Axis crée un servive appelé • http://<host>:<port>/<axis-root>/services/<service-name> • Le WSDL du service is accessible à • http://<host>:<port>/<axis-root>/services/<service-name>?wsdl • Une liste des services est visible à • http://<host>:<port>/<axis-root>/services A. Roussanaly - Université Nancy2

  35. WSDD avancée • Scope <service name=<service>...> <parameter name="scope" value=<valeur>/> ... </service> • <valeur> : • "Request" • "Session"   • "Application" A. Roussanaly - Université Nancy2

  36. Annexes (archives) A. Roussanaly - Université Nancy2

  37. Exemple client n°1 (DII) public String endPoint = "http://localhost:8080/axis/AddFunction.jws"; public String operationName = "addInt"; public int invokeService(int a, int b) throws Exception{ Service service = new Service(); Call call = (Call) service.createCall(); call.setOperationName(new QName(endPoint, operationName)); call.setTargetEndpointAddress( new URL(endPoint) ); Integer ret = (Integer) call.invoke( new Object[] { new Integer(a), new Integer(b)} ); return ret.intValue();} A. Roussanaly - Université Nancy2

  38. Exemple client n°2 (PROXY) public String wsdlUrl = "http://localhost:8080/axis/AddFunction.jws?wsdl";public String nameSpaceUri = "http://localhost:8080/axis/AddFunction.jws";public String serviceName = "AddFunctionService";public String portName = "AddFunction"; public int invokeService(int a, int b) throws Exception{ ServiceFactory serviceFactory = ServiceFactory.newInstance(); Service afService = serviceFactory.createService( new URL(wsdlUrl), new QName(nameSpaceUri, serviceName)); AddFunctionServiceIntf afsIntf =(AddFunctionServiceIntf)afService .getPort(new QName(nameSpaceUri, portName), AddFunctionServiceIntf.class); return afsIntf.addInt(a, b);} A. Roussanaly - Université Nancy2

  39. Exemple client n°2 (PROXY) public interface AddFunctionServiceIntf extends java.rmi.Remote { public int addInt(int a, int b) throws java.rmi.RemoteException; } A. Roussanaly - Université Nancy2

  40. Exemple client n°3 (STUB) Générer préalablement le stub à l'aide de l'outil WSDL2Java public int invokeService(int a, int b) throws Exception{ AddFunctionService afs = new AddFunctionServiceLocator(); AddFunction af = afs.getAddFunction(); return af.addInt(a, b);} A. Roussanaly - Université Nancy2

  41. Déploiement de service <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="MyService" provider="java:RPC"> <parameter name="className" value="samples.userguide.example3.MyService"/> <parameter name="allowedMethods" value="*"/> </service> </deployment> %java org.apache.axis.client.AdminClient MyService.wsdd A. Roussanaly - Université Nancy2

  42. Axis Ecriture d’un client A. Roussanaly - Université Nancy2

  43. Ecriture d'un client • On a le choix entre 3 méthodes : • Proxy • Cas d’utilisation : type des paramètres et résultat connus (voir exemple annexe de présentation) • Interface d'invocation dynamique (DII) : • Cas d’utilisation : on ne connaît que l’url du service => invocation dynamique des méthodes (voir exemple annexe de présentation) • Génération d'un Stub à partir d'une description WSDL • Cas d’utilisation : connaissance préalable du WSDL • On se place dans ce cas dans la suite… A. Roussanaly - Université Nancy2

  44. Synopsis de l’application Change.java WSDL2JAVA Change.wsdl ChangeService.java ChangeServiceLocator ChangeSoapBindindStub.java JAVAC UI.java Convertisseur.java A. Roussanaly - Université Nancy2

  45. Projet Eclipse ChangeAxisClient build.xmlproject.properties lib bin src .class axis.jaraxis-ant.jarwsdl4j.jarmail.jaractivation.jar… img fr.miage.sid.axis.client .jpg .java stub .java(wsdl2java) A. Roussanaly - Université Nancy2

  46. Ant <project default="compiler" basedir="."> <!-- Variable d'accès aux variables d'environnement --> <property environment="env" /> <!-- Accès aux variables locales du projet --> <property file="project.properties" /> <!-- Où se trouvent les jar --> <property name="lib.dir" value="lib" /> <!-- Où se trouvent les src --> <property name="src.dir" value="src" /> <!-- Où se trouvent les img --> <property name="img.dir" value="${src.dir}/img" /> <!-- Où se trouvent les class --> <property name="bin.dir" value="bin" /> <!-- Où se trouvent les javadoc --> <property name="javadoc.dir" value="${bin.dir}/javadoc" /> … </project> A. Roussanaly - Université Nancy2

  47. Ant <!-- Definition de la tache ant wsdl2java --> <taskdef name="wsdl2java" classname="org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask"> <classpath refid="classpath" /> </taskdef> A. Roussanaly - Université Nancy2

  48. Ant <!-- ==================================================================== Créer un stub avec wsdl2java ==================================================================== --> <target name="wsdl2java" description="Génération d'un stub (client)"> <wsdl2java url="${wsdl.file}" output="${src.dir}"> <mapping namespace="${service.urn}" package="${service.package}"/> </wsdl2java> </target> A. Roussanaly - Université Nancy2

More Related