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 :

Pb retour methode call.invoke


Sujet :

Services Web Java

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2008
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Pb retour methode call.invoke
    Bonjour à tous,
    j'essaye d'écrire un web service.

    Ok pour un WS qui me renvoie une String par la méthode call.invoke(....).
    Par contre je teste maintenant pour que le WS renvoie un ArrayList<String> et la
    j'ai l'erreur suivante

    Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;
    at SelectClient.main(SelectClient.java:46)
    à priori on ne peut pas caster :

    ArrayList retour = new ArrayList<String>();
    retour = (ArrayList<String>) call.invoke( new Object [] { requete });

    voici le code qui appelle le WS.
    Merci pour votre aide.


    import java.util.ArrayList;

    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.encoding.XMLType;
    import org.apache.axis.utils.Options;

    import com.sun.mail.iap.Response;

    import javax.xml.rpc.ParameterMode;

    public class SelectClient {
    public static void main(String [] args) throws Exception {
    Options options = new Options(args);

    String endpoint = "http://localhost:8080/axis/ConnexionMySQL.jws";

    // Do argument checking
    args = options.getRemainingArgs();

    if (args == null || args.length != 2) {

    return;
    }

    String method = args[0];
    if (!(method.equals("selectStatement") )) {

    return;
    }

    // Make the call
    String requete = new String(args[1]);

    Service service = new Service();
    Call call = (Call) service.createCall();

    call.setTargetEndpointAddress(new java.net.URL(endpoint));
    call.setOperationName( method );
    call.addParameter("op1", XMLType.XSD_STRING, ParameterMode.IN);
    //call.addParameter("op2", XMLType.XSD_INT, ParameterMode.IN);
    call.setReturnType(XMLType.SOAP_ARRAY);
    System.out.println("client:requete = " + requete);
    ArrayList retour = new ArrayList<String>();
    retour = (ArrayList<String>) call.invoke( new Object [] { requete });


    System.out.println("Got result : " + retour.size());
    }
    }

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    239
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 239
    Points : 173
    Points
    173
    Par défaut
    Moi personnellement je n'ai jamais réussi à faire passer une liste avec axis,, alors ,, je te conseille de transformer ta liste en tableau.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2008
    Messages : 2
    Points : 2
    Points
    2
    Par défaut WS methode call.invoke avec String[] OK
    Merci beaucoup !
    ça fonctionne très bien.
    Voici ce que j'ai fait :
    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
     
     
    import java.lang.reflect.Array;
    import java.util.ArrayList;
     
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.encoding.XMLType;
    import org.apache.axis.utils.Options;
     
    import com.sun.mail.iap.Response;
     
    import javax.xml.rpc.ParameterMode;
     
    public class SelectClient {
    	public static void main(String [] args) throws Exception {
    		Options options = new Options(args);
     
    		String endpoint = "http://localhost:8080/axis/ConnexionMySQL.jws";
     
    		// Do argument checking
    		args = options.getRemainingArgs();
     
    		if (args == null || args.length != 2) {
     
    			return;
    		}
     
    		String method = args[0];
    		if (!(method.equals("selectStatement") )) {
     
    			return;
    		}
     
    		// Make the call
    		String requete = new String(args[1]);
     
    		Service  service = new Service();
    		Call     call    = (Call) service.createCall();
     
    		call.setTargetEndpointAddress(new java.net.URL(endpoint));
    		call.setOperationName( method );
    		call.addParameter("op1", XMLType.XSD_STRING, ParameterMode.IN);
    		//call.addParameter("op2", XMLType.XSD_INT, ParameterMode.IN);
    		call.setReturnType(XMLType.SOAP_ARRAY);
    		System.out.println("client:requete = " + requete);
    		String[] retour  = new String [10];
    		retour =  (String []) call.invoke( new Object [] { requete });
     
     
    		for (int i=0; i< retour.length; i++) {
    			System.out.println("Got result : " + retour[i]);
    		}
    	}
    }

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

Discussions similaires

  1. "pure method called" au test d'un wrapper boost::thread simple
    Par kidpaddle2 dans le forum Threads & Processus
    Réponses: 5
    Dernier message: 02/07/2010, 08h36
  2. Impossible de retourner un objet avec la methode _call.invoke
    Par nemo69500 dans le forum Services Web
    Réponses: 0
    Dernier message: 04/12/2008, 08h45
  3. [Débutant] call.invoke et pièce jointe
    Par bannik dans le forum Services Web
    Réponses: 0
    Dernier message: 14/11/2008, 16h10
  4. Réponses: 4
    Dernier message: 17/05/2007, 16h47

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