erreur au moment d'invocation d'un service web
Bonjour à tous;
J'utilise le programme suivant (en Java) pour invoquer des services web.
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 56 57 58 59 60 61 62 63
|
package pgm2;
import java.net.*;
import java.io.*;
public class SendSoap {
public static void main(String[] args) throws Exception {
String soapMessage = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope/\" xmlns:web=\"http://www.webservicex.net/\">"
+ " <soap:Header/>"
+ " <soap:Body>"
+ " <web:GetGeoIP>"
+ "<!--Optional:-->"
+ " <web:IPAddress>8.8.8.8</web:IPAddress>"
+ " </web:GetGeoIP>"
+ "</soap:Body>" + "</soap:Envelope>";
String res = sendSOAP("http://www.webservicex.net/geoipservice.asmx", soapMessage);
System.out.println(res);
}
public static String sendSOAP(String SOAPUrl, String soapMessage)
throws Exception {
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
byte[] byteArray = soapMessage.getBytes("UTF-8");
httpConn.setRequestProperty("Content-Length", String.valueOf(byteArray.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction", "");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write(byteArray);
out.close();
BufferedReader in = null;
StringBuffer resultMessage= new StringBuffer();
try {
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
in = new BufferedReader(isr);
String inputLine;
while ((inputLine = in.readLine()) != null) {
resultMessage.append(inputLine);
}
} finally {
if (in != null) {
in.close();
}
}
return resultMessage.toString();
}
} |
Au moment de l'exécution (avec comme paramètres l'URL du service web "http://www.webservicex.net/geoipservice.asmx" ainsi que les valeurs attribuées à la variable "soapeMessage") j'obtiens le message d'erreur suivant:
Code:
1 2 3 4 5 6
|
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.webservicex.net/geoipservice.asmx
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at pgm2.SendSoap.sendSOAP(SendSoap.java:47)
at pgm2.SendSoap.main(SendSoap.java:18) |
Prière de me proposer vos solutions.
NB: Ce même programme fonctionne parfaitement avec d'autres services web (il suffit de changer l'URL et les valeurs attribuées à "soapMessage" évidemment).
Merci d'avance.