IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

[WSDL] Parser un fichier WSDL


Sujet :

Services Web Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 3
    Par défaut [WSDL] Parser un fichier WSDL
    Bonjour,

    Je cherche à parser un fichier WSDL, dans le but d'écrire un formulaire de test dynamique pour des webservices (on lui passe un WSDL, et il génère automatiquement un formulaire).

    L'idée est donc d'obtenir à partir du WSDL les différentes opérations et leurs paramètres (qui peuvent être des paramètres complexes), pour pouvoir ensuite les invoquer de manière dynamique.

    J'ai vu WSDL4J qui semble se rapprocher le plus de ce que je recherche, mais qui reste à mon gout assez complexe. Existe-t-il une librairie existante qui fasse ce parsing de manière plus simple ? A défaut quelqu'un peut-il m'indiquer des exemples utilisant WSDL4J pour faire ce que je recherche ?

    Merci d'avance de vos réponse,
    Cordialement,
    Thierry.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 36
    Par défaut
    Bonjour thierry,

    Alors d'après ce que j'ai trouvé tu as deux solutions:
    - soit utiliser une library DOM et parser le wsdl comme si c'était un simple xml (mais la faut bien connaitre la structure des wsdl)

    -soit utiliser wsdl4j sachant que tu peux récupérer les opération mais pas les paramètres => en tout cas j'ai pas réussi et du coup j'ai aussi utiliser une library dom

    Voilà comment j'ai fait pour récuperer tout les paramètres du wsdl, pour les méthodes suffit de s'arrêter quand on a récupérer les operations.

    J'utilise Axis2 et org.w3c.dom.Element, c'est assez complexe donc si certains arrivent a optimiser le truc c'est pas de refus

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
     public Vector getParamsFromWSDL()
    	{
    		Vector params = new Vector();
    		try
    		{
    	//		 Mise à jour de la combobox de la méthode
    			byte[] filestr = getServiceWeb().getWsdl();
    			if (filestr == null)
    			{
    				String ds = FileToolBox.load(serviceWebPropertyPage.getWSDLPane().getStructureFile().getAbsolutePath());
    				filestr = ds.getBytes();
    			}
    			File structureFile = getFileFromBytes(filestr,serviceWebPropertyPage.getInfoGeneralPanel().getCodeFld().getText()+"_"+getServiceWeb().getWsdlName());
    			WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    	        String wsdlURI = structureFile.toURI().toString();
    	        Definition def = wsdlReader.readWSDL(wsdlURI);
     
     
     
    	        Map ports = def.getPortTypes();
    	        Set set = ports.keySet();
    	        for (Iterator it = set.iterator();it.hasNext();)
    	        {
    	            Object key = it.next();
    	            PortType pt = (PortType)ports.get(key);
    	            List l = pt.getOperations();
    	            for (int i = 0; i < l.size(); i++) {
    	            	Operation op = (Operation) l.get(i);
    	            	if (op.getName().equalsIgnoreCase(getServiceWeb().getMethod()))  
    	            	{
    	            		Input entree = op.getInput();
    	            		Map parts =entree.getMessage().getParts();
    	            		Set setParts = parts.keySet();
    	            		for (Iterator itParts = setParts.iterator();itParts.hasNext();)
    	        	        {
    	            			Object partKey = itParts.next();
    	        	            Part part = (Part)parts.get(partKey);
    	        	            String nom;
    	        	            if (part.getTypeName() == null)
    	        	            {
    		        	            nom = part.getElementName().getLocalPart();
    		        	            Types types = def.getTypes();
    		        		        List lst = types.getExtensibilityElements();
    		        		        for (int j = 0; j < lst.size(); j++) {
    		        		        	ExtensibilityElement schemaExtElem = (ExtensibilityElement)lst.get(j);
    			        		        if ((schemaExtElem != null) && (schemaExtElem instanceof UnknownExtensibilityElement))
    			        		        {
    			        			        Element schemaElement = ((UnknownExtensibilityElement) schemaExtElem).getElement();
    			        			        NodeList nl = schemaElement.getChildNodes();
    			        			        getComplexParam(nl, nom, "Entrée", params, "");
    			        		        }
    			        		        if ((schemaExtElem != null) && (schemaExtElem instanceof Schema))
    			        		        {
    			        			        Element schemaElement = ((Schema) schemaExtElem).getElement();
    			        			        NodeList nl = schemaElement.getChildNodes();
    			        			        getComplexParam(nl, nom, "Entrée", params, "");
    			        		        }
    								} 
    	        	            }
    	        	            else
    	        	            {
    	        	            	nom = part.getTypeName().getLocalPart();
    	        	            	params.add(part.getName()+"("+nom+", Entrée)");
    	        	            }  
    	        	        }
    	            		Output sortie = op.getOutput();
    	            		Map partsSortie = sortie.getMessage().getParts();
    	            		Set setPartsSortie = partsSortie.keySet();
    	            		for (Iterator itParts = setPartsSortie.iterator();itParts.hasNext();)
    	        	        {
    	            			Object partKey = itParts.next();
    	        	            Part part = (Part)partsSortie.get(partKey);
    	        	            String nom;
    	        	            if (part.getTypeName() == null)
    	        	            {
    		        	            nom = part.getElementName().getLocalPart();
    		        	            Types types = def.getTypes();
    		        		        List lst = types.getExtensibilityElements();
    		        		        for (int j = 0; j < lst.size(); j++) {
    		        		        	ExtensibilityElement schemaExtElem = (ExtensibilityElement)lst.get(j);
    			        		        if ((schemaExtElem != null) && (schemaExtElem instanceof UnknownExtensibilityElement))
    			        		        {
    			        			        Element schemaElement = ((UnknownExtensibilityElement) schemaExtElem).getElement();
    			        			        NodeList nl = schemaElement.getChildNodes();
    			        			        getComplexParam(nl, nom, "Sortie", params, "");
    			        		        }
    			        		        if ((schemaExtElem != null) && (schemaExtElem instanceof Schema))
    			        		        {
    			        			        Element schemaElement = ((Schema) schemaExtElem).getElement();
    			        			        NodeList nl = schemaElement.getChildNodes();
    			        			        getComplexParam(nl, nom, "Sortie", params, "");
    			        		        }
    								} 
    	        	            }
    	        	            else
    	        	            {
    	        	            	nom = part.getTypeName().getLocalPart();
    	        	            	params.add(part.getName()+"("+nom+", Sortie)");
    	        	            } 
    	        	        }
    	            	}
    				}  
    	        }
    		}
    		catch (Exception ex)
    		{
    			handleException(ex);
    		}
    	 return params;
    	}
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    private void getComplexParam(NodeList nl, String nom, String EntreeSortie, Vector allparams, String parent)
    	{
    		for (int j=0;j<nl.getLength();j++)
            {
            	if (nl.item(j).getNodeType() == Node.ELEMENT_NODE)
            	{
    	        	Element elt = (Element)nl.item(j);
    	        	if (elt.getNodeName().equals("element"))
    	        	{
    		        	if (elt.getAttribute("name").equals(nom))
    		        	{
    		        		String type = elt.getAttribute("type");
     
    		        		if (type.length() == 0)
    		        		{
    		        			Element eltComplexType = getFirstElement(elt);
    		        			Element eltSequence = getFirstElement(eltComplexType);
    		        			if (eltSequence == null)
    		        				continue;
    		        			NodeList nl2 = eltSequence.getChildNodes();
    		        			for (int k=0;k<nl2.getLength();k++)
    		        			{
    		        				if (nl2.item(k).getNodeType() == Node.ELEMENT_NODE)
    		        	        	{
    			        				String eltNom = ((Element)nl2.item(k)).getAttribute("name");
    			        				String type2 = ((Element)nl2.item(k)).getAttribute("type");
    					        		String occurs = ((Element)nl2.item(k)).getAttribute("maxOccurs");
    			        				if (!type2.startsWith("xsd:"))
    					        		{
    					        			getComplexParam(nl, type2.substring(type2.indexOf(":") + 1),EntreeSortie, allparams, parent + eltNom + ":"+type2.substring(type2.indexOf(":") + 1)+".");
    					        		}
    					        		else
    					        		{
    					        			if (type2.equalsIgnoreCase("xsd:string") && occurs.equalsIgnoreCase("unbounded"))
    					        				allparams.add(parent + eltNom+"(string[], "+EntreeSortie+")");
    					        			else
    					        				allparams.add(parent + eltNom+"("+type2+", "+EntreeSortie+")");
    					        		}			
    		        	        	}
    		        			}
    		        		}
    		        		if (!type.startsWith("xsd:"))
    		        		{
    		        			getComplexParam(nl, type.substring(type.indexOf(":") + 1),EntreeSortie, allparams, parent + elt.getAttribute("name")+":"+type.indexOf(":") + 1 + ".");
    		        		}
    		        		else
    		        		{	
    		        			allparams.add(parent + elt.getAttribute("name")+"("+type+", "+EntreeSortie+")");
    		        		}
    		        	}
    	        	}
    	        	else if (elt.getNodeName().equals("complexType"))
    	        	{
    	        		if (elt.getAttribute("name").equals(nom))
    		        	{
    	        			Element eltSequence = getFirstElement(elt);
    	        			if (eltSequence == null)
    	        				continue;
    	        			NodeList nl2 = eltSequence.getChildNodes();
    	        			for (int k=0;k<nl2.getLength();k++)
    	        			{
    	        				if (nl2.item(k).getNodeType() == Node.ELEMENT_NODE)
    	        	        	{
    		        				String eltNom = ((Element)nl2.item(k)).getAttribute("name");
    		        				String type2 = ((Element)nl2.item(k)).getAttribute("type");
    		        				String occurs = ((Element)nl2.item(k)).getAttribute("maxOccurs");
    		        				if (!type2.startsWith("xsd:"))
    				        		{
    				        			getComplexParam(nl, type2.substring(type2.indexOf(":") + 1),EntreeSortie, allparams, parent + eltNom + ".");
    				        		}
    				        		else
    				        		{
    				        			if (type2.equalsIgnoreCase("xsd:string") && occurs.equalsIgnoreCase("unbounded"))
    				        				allparams.add(parent + eltNom+"(string[], "+EntreeSortie+")");
    				        			else
    				        				allparams.add(parent + eltNom+"("+type2+", "+EntreeSortie+")");
    				        		}	
    	        	        	}
    	        			}	
    		        	}
    	        	}
            	}
            }
    	}
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    	private Element getFirstElement(Element elt)
    	{
    		NodeList nl = elt.getChildNodes();
    		for (int j=0;j<nl.getLength();j++)
            {
            	if (nl.item(j).getNodeType() == Node.ELEMENT_NODE)
            	{
            		return (Element)nl.item(j);
            	}
            }
    		return null;
    	}

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 3
    Par défaut
    Merci beaucoup Aphrael, ça marche tout pile poil

    J'ai adapté à mon code, et ça a tourné presque tout de suite. La seule modification que j'ai apportée c'est les elt.getNodeName().equals("element") que j'ai remplacé par des elt.getLocalName().equals("element"). Sinon ça renvoyait "xsd:element" et pas "element".

    Merci encore pour cette réponse rapide, je posterai à nouveau si je fais des modifications plus importantes du code ou des améliorations.

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 36
    Par défaut
    Niquel, te restes plus qu'à cliquer sur résolu

    Perso j'ai garder le xsd car ca me permet de faire des test ensuite mais c'est vrai que y a pas besoin

  5. #5
    Candidat au Club
    Inscrit en
    Janvier 2008
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 3
    Par défaut bonjour
    Bonjour je veux utiliser ton code mais j'ai pas trouver le package org.w3c.dom , je ss débutante ds se domaine des Web services

  6. #6
    Membre habitué
    Femme Profil pro
    Doctorante
    Inscrit en
    Juillet 2011
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorante

    Informations forums :
    Inscription : Juillet 2011
    Messages : 10
    Par défaut
    Bonjour,
    j'aimerais si possible avoir plus de détails sur le code que vous avez publié, et notamment sur les bibliothèques.
    Merci par avance
    Nass

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comment parser un fichier WSDL(java-eclipse)
    Par bleu angle dans le forum Services Web
    Réponses: 2
    Dernier message: 10/06/2009, 17h45
  2. [Débutant] Généré le client depuis un fichier WSDL
    Par chronos dans le forum Services Web
    Réponses: 6
    Dernier message: 02/08/2007, 12h01
  3. [Debutant] Fichier WSDL : Retourner un document de type PDF
    Par mesk93 dans le forum Services Web
    Réponses: 2
    Dernier message: 30/10/2006, 14h54
  4. [WebService]Ou trouver une liste de fichier WSDL?
    Par javazer dans le forum Services Web
    Réponses: 6
    Dernier message: 07/04/2006, 14h02
  5. [C /C++] generer SOAP a partir d'un fichier WSDL
    Par Mokhtar BEN MESSAOUD dans le forum XML
    Réponses: 1
    Dernier message: 26/07/2005, 13h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo