Welcome Guest! Log in

Topic-icon Idea How to retrieve an online XML file ?

  • Nicolas Verscheure
  • Nicolas Verscheure's Avatar Topic Author
  • Offline
More
24 Nov 2014 20:34 - 24 Nov 2014 20:46 #1 by Nicolas Verscheure
Nicolas Verscheure created the topic: How to retrieve an online XML file ?
Sometimes, it can be useful to retrieve an online XML file. Nevertheless, it is not possible to add an XML metadata and set the online URL.
An alternative solution consists to add an BeanShell shell on your process and to set scripting language to "javascript" and to use the following code :

var url = java.net.URL("http://api.wunderground.com/api/9028253e5a3ba47e/history_20120910/lang:FR/q/zmw:00000.259.07015.xml");
var str = com.indy.engine.common.CommonUtils.inputStreamToString(url.openStream());
var fw = java.io.FileWriter("/tmp/test.xml");
fw.write(str);
fw.close();

If you are running the process through a proxy, you must adapt your code :

var addr = new java.net.InetSocketAddress("webcache.mydomain.com", 8080);
var proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, addr);
var url = java.net.URL("http://api.wunderground.com/api/9028253e5a3ba47e/history_20120910/lang:FR/q/zmw:00000.259.07015.xml");
var connection = url.openConnection(proxy);
 
var s = new java.lang.String("user"+":"+"password");
connection.setRequestProperty("Proxy-Authorization", "Basic " + org.apache.xerces.impl.dv.util.Base64.encode(s.getBytes()));
 
var str = com.indy.engine.common.CommonUtils.inputStreamToString(connection.getInputStream());
var fw = java.io.FileWriter("/tmp/test.xml");
fw.write(str);
fw.close();
Last Edit: 24 Nov 2014 20:46 by Nicolas Verscheure.

Please Log in or Create an account to join the conversation.