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 :

[SAAJ]Help pour un nul


Sujet :

Services Web Java

  1. #1
    kit
    kit est déconnecté
    Membre averti
    Inscrit en
    Avril 2005
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 41
    Par défaut [SAAJ]Help pour un nul
    Rebonjour,

    Je dois récupérer un webservice via soap sous java en utilisant SAAJ mais je comprend rien!!!
    Le webservice sez trouve à une soap adresse location du style "http://bidule/chouette/machin.asmx" . Je dois l'attaquer avec 4 arguments et recevoir la reponse. Comment faire? J'ai lu le tutoriel de sun mais pas compris grand chose. Un petit coup de main serait bien sympathique.

    A+

  2. #2
    kit
    kit est déconnecté
    Membre averti
    Inscrit en
    Avril 2005
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 41
    Par défaut
    J'ai fais une petite recherche et j'ai développé un code me permettant de me connecter à un webservice. Attention je ne l'ai pas testé.

    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
    public void AttaqueWebserviceViaSAAJ(){
     
    			String serviceUrl = "http://bidule/chouette/machin.asmx";
    			String inputXml = "c:/repA/repB/xxx.xml";
    			SOAPMessage reply = null;
    			try
    			{
    				//Create Soap Connection
    				SOAPConnectionFactory scf = 
    					SOAPConnectionFactory.newInstance(); 
    				SOAPConnection con = scf.createConnection();
     
    				//Create Message
    				MessageFactory mf = 
    					MessageFactory.newInstance(); 
    				SOAPMessage msg = mf.createMessage(); 
     
    				// Get the SOAPPart from the message
    				SOAPPart soapPartInput = msg.getSOAPPart(); 
    				// Creating an attachment Part
    				/*AttachmentPart attachPart = 
    					msg.createAttachmentPart();
    				attachPart.setContent(
    					"This is a text attachment", "text/plain");*/
     
    				// Create and set the content from the 
    				// input XML document
    				StringReader stringReaderInput = 
    					new StringReader(inputXml); 
    				StreamSource ssInput = 
    					new StreamSource(stringReaderInput);
    				soapPartInput.setContent(ssInput);
     
    				// Save the changes to the message
    				msg.saveChanges();
     
    				// Invoke the service synchronously and 
    				// get the reply
    				reply = con.call(msg, serviceUrl);
     
    				// Get the SOAP body from the response
    				SOAPBody outSoapBody = 
    					reply.getSOAPPart().getEnvelope().getBody();
     
    				// Check to see if there is any SOAP Fault
    				if (outSoapBody.hasFault())
    				{
    					// Take any actions for the exception scenario
    					SOAPFault fault = outSoapBody.getFault();
     
    					// Log the fault details
    					System.out.println("SOAP Fault occurred");
    					System.out.println("Fault Code is " + 
    					fault.getFaultCode());
    					System.out.println("Fault String is " + 
    					fault.getFaultString());
    				}
    				else
    				{
    					// Print the output SOAP envelope
    					System.out.println(
    						reply.getSOAPPart().getEnvelope());   
    				}
     
    				// Close the connection
    				con.close();
    			}
    			catch (SOAPException e)
    			{    
    			     // Print the stack trace if there are any 
    			    // SOAPExceptions
    				e.printStackTrace();
    			}
     
    		  }

  3. #3
    kit
    kit est déconnecté
    Membre averti
    Inscrit en
    Avril 2005
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 41
    Par défaut
    J'ai essayé de tester la classe. Voila le message d'erreur que j'ai:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Unable to create SOAP connection factory: Provider com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory not found
    	at javax.xml.soap.SOAPConnectionFactory.newInstance(Unknown Source)
    Quelqu'un aurait une idée ?

  4. #4
    Membre éclairé
    Homme Profil pro
    Enseignant
    Inscrit en
    Octobre 2005
    Messages
    249
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Mali

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2005
    Messages : 249
    Par défaut
    je te propose le code suivant :
    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
     
    import javax.xml.namespace.QName;
    import javax.xml.rpc.ParameterMode;
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
     
    public class ExempleInv {
    	public static void main(String [] args){
    		String endpoint="http://localhost:8080/axis/Calculator.jws";
     
    		try {
    			Service service=new Service();
    			Call call=(Call)service.createCall();
     
    			call.setTargetEndpointAddress(new java.net.URL(endpoint));
    			call.setOperationName(new QName("http://localhost:8080/axis/Calculator.jws","add"));
    			call.addParameter("n1", new QName("http://www.w3.org/2001/XMLSchema","int"), ParameterMode.IN);
    			call.addParameter("n2", new QName("http://www.w3.org/2001/XMLSchema","int"), ParameterMode.IN);
    			call.setReturnType(new QName("http://www.w3.org/2001/XMLSchema","int"));
     
    			Object reponse=call.invoke(new Object[] {12,8});
    			System.out.println(reponse);
     
    		} catch (Exception e) {
    			// TODO Bloc catch auto-généré
    			System.err.println(e.toString());
    		}
    	}
    }

    Ce code permet d'invoker un service distant et affiche le résultat. Pour l'utiliser, tu dois mettre tes propres informations telles que URL, Operation, Données en entrée, type du résultat.

    merci.

  5. #5
    kit
    kit est déconnecté
    Membre averti
    Inscrit en
    Avril 2005
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 41
    Par défaut
    Merci demcoul, mais il faut installer axis. Coimment faire?

  6. #6
    kit
    kit est déconnecté
    Membre averti
    Inscrit en
    Avril 2005
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 41
    Par défaut
    Dites moi, quelq'un aurait le wsdl correspondant au code proposé par demcoul?

    Merci d'avance

  7. #7
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2007
    Messages
    75
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2007
    Messages : 75
    Par défaut
    Bonjour,
    Dites moi, quelq'un aurait le wsdl correspondant au code proposé par demcoul?
    ce code ne correspond pas à un serviceweb, donc il n'a pas de WSDL.

    generalement si tu veux avoir un WSDL d'un service, tu fais: http://hostname:port/service?wsdl.

Discussions similaires

  1. aide modif config oracle (sga) pour un nul (help)
    Par goliathk dans le forum Administration
    Réponses: 13
    Dernier message: 09/09/2009, 17h52
  2. C++ pour les nuls => Linux => Problème
    Par wizardman dans le forum Linux
    Réponses: 6
    Dernier message: 21/09/2005, 01h53
  3. need help pour : boucle & expression régulière
    Par Fabouney dans le forum Langage
    Réponses: 5
    Dernier message: 05/08/2005, 03h22
  4. Apprendre le réseau (pour les nuls)
    Par __fabrice dans le forum Développement
    Réponses: 5
    Dernier message: 08/03/2005, 14h49
  5. [TP]Help pour insertion d'un image sur tp7 svp !
    Par ilym dans le forum Turbo Pascal
    Réponses: 2
    Dernier message: 21/01/2004, 22h00

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