Welcome Guest! Log in
×

Notice

The forum is in read only mode.
Stambia versions 2.x, 3.x, S17, S18, S19 and S20 are reaching End of Support January, 15th, 2024. Please consider upgrading to the supported Semarchy xDI versions. See Global Policy Support and the Semarchy Documentation.

The Stambia User Community is moving to Semarchy! All the applicable resources have already been moved or are currently being moved to their new location. Read more…

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
How to retrieve an online XML file ? was created by Nicolas Verscheure
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.