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
|
static public String[] useFonction(String localName1,String localName2, String valtext)
{
String[] items;
try
{
// url du service Web
URL url=new URL( "http://footballpool.dataaccess.eu/data/info.wso");
// lancement d'une connection de type SOAP (Simple Object Access Protocol)
SOAPConnectionFactory scFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
// ON envoie des messages dans une enveloppe avec un titre(header), et un "corps"
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
SOAPHeader header = envelope.getHeader();
header.detachNode(); // pas besoin de header pour cete appli
SOAPBody body = envelope.getBody(); // pointeur vers le "corps"
Name bodyName = envelope.createName(localName1, "NS1","http://footballpool.dataaccess.eu");
// si on avait un argument à envoyer, ce serait ici .....
SOAPBodyElement gltp = body.addBodyElement(bodyName);
// mais dans notre exemple, cela peut rester vide
Name name = envelope.createName(localName2);
SOAPElement symbol = gltp.addChildElement(name);
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
// ouverture
symbol.addTextNode(valtext);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// en entrée sortie
conn.setDoOutput(true);
conn.setDoInput(true);
// en POST
conn.setRequestMethod("POST");
URL endpoint = url;
SOAPMessage response = con.call(message, endpoint);
// et on reçoit la réponse
System.out.println("Retour du serveur :");
Pattern p = Pattern.compile("\n");
// System.out.println(p.split(response.getSOAPBody().getTextContent()));
items = p.split(response.getSOAPBody().getTextContent());
// String[] pays = new String[(items.length - 4)/3];
// int pos =0;
// Node test = (Node)(response);
// test.getChildNodes().getLength();
con.close();
} |
Partager