It's not pretty but I have written a script that does a ConversionRate
request and displays the rate in plan text. Maybe not the prettiest
way to construct the request, but it works :)
URL url = new URL("
http://www.webservicex.net/
CurrencyConvertor.asmx");
HttpURLConnection connection = (HttpURLConnection) url.openConnection
();
connection.setRequestMethod("POST")
connection.setRequestProperty("Content-Type","text/xml")
connection.setDoOutput(true);
static def request = '''
<soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/
envelope/" xmlns:web="
http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>USD</web:FromCurrency>
<web:ToCurrency>SEK</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
'''
Writer out = new OutputStreamWriter(connection.outputStream)
out.write(request)
out.flush()
out.close()
inputstream = connection.getInputStream();
int length = (int) connection.getContentLength();
if (length != -1) {
def incomingData = new byte[length];
inputstream.read(incomingData);
rawResponse = new String(incomingData);
}
else {
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch = 0;
while ((ch = inputstream.read()) != -1) {
bytestream.write(ch);
}
rawResponse = new String(bytestream.toByteArray());
bytestream.close();
}
def slurpedResponse = new XmlSlurper().parseText(rawResponse)
println(slurpedResponse);