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.
Citation:
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());
}
}
WS methode call.invoke avec String[] OK
Merci beaucoup !
ça fonctionne très bien.
Voici ce que j'ai fait :
Code:
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]);
}
}
} |