Java sample
Download the last 25 messages in error
This requires using Apache Commons httpclient, codec and logging for HTTP calls and SAX for XML parsing
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class RESTClient {
public static void main(String[] args) throws Exception {
String baseUrl = "https://www.babelway.net/SelfService3/rest/v2/";
Long myHub = 0L; // You can find this on the My Account page
String user = "";// the username you use to connect to Babelway
String pwd = ""; // the password you use to connect to Babelway
// Download the last 25 messages in ERROR
String request = baseUrl + "hub-" + myHub + "/messages.xml?status=ERROR";
HttpClient client = new HttpClient();
client.getState().setCredentials(AuthScope.ANY_REALM, "www.babelway.net", new UsernamePasswordCredentials(user, pwd));
GetMethod method = new GetMethod(request);
// Send the request
int statusCode = client.executeMethod(method);
// read the result
if (statusCode == 200) {
InputStream rstream = null;
rstream = method.getResponseBodyAsStream();
BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
SAXParser sxp = SAXParserFactory.newInstance().newSAXParser();
sxp.parse(rstream, new SaxHandler());
}
}
private static final class SaxHandler extends DefaultHandler {
// invoked when document-parsing is started:
public void startDocument() throws SAXException {
System.out.println("Document processing started");
}
// notifies about finish of parsing:
public void endDocument() throws SAXException {
System.out.println("Document processing finished");
}
// we enter to element 'qName':
public void startElement(String uri, String localName,
String qName, Attributes attrs) throws SAXException {
// Do your processing
System.out.println("Element " + qName);
}
// we leave element 'qName' without any actions:
public void endElement(String uri, String localName, String qName)
throws SAXException {
// do nothing;
}
}
}