Skip to content

Instantly share code, notes, and snippets.

@IT-Berater
Created May 14, 2016 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IT-Berater/3e00dc4c4c3402e0a784d8b429db4dc4 to your computer and use it in GitHub Desktop.
Save IT-Berater/3e00dc4c4c3402e0a784d8b429db4dc4 to your computer and use it in GitHub Desktop.
REST Abfrage Beispiel mit JDOM
public class Abfrage {
// URL des Feeds aller Flugzeuge in Hannover von Thomas Wenzlaff. //
private final static String FLUGZEUG_URL = "https://api.thingspeak.com/channels/44177/feeds/last.xml";
/**
* Start Methode.
*
* @param args
* keine.
* @throws JDOMException
* @throws IOException
*/
public static void main(String[] args) throws JDOMException, IOException {
String result = ClientBuilder.newClient().target(FLUGZEUG_URL).request().get(String.class);
// result get sample:
// <?xml version="1.0" encoding="UTF-8"?>
// <feed>
// <created-at type="dateTime">2016-05-13T12:20:01Z</created-at>
// <entry-id type="integer">79166</entry-id>
// <field1>18</field1>
// <id type="integer" nil="true"/>
// </feed>
String field1 = new SAXBuilder().build(new StringReader(result)).getDocument().getRootElement().getChild("field1").getText();
System.out.println("Aktuelle Anzahl Flugzeuge in Langenhagen: " + field1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment