Making REST calls in a Java application
You can use standard Java™ methods to access the TADDM REST API.
To access the REST interfaces securely using an HTTPS connection,
you must first copy the jssecacerts.cert security certificate to the
client system. This file is located in the $COLLATION_HOME/etc directory
on the TADDM server.
The following example shows how to access the REST API from a Java program.
To access the REST API from a Java program,
use the standard Java methods
for HTTP communication.
This example accesses the REST
API using a secure HTTPS connection:
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
System.out.println("Warning: URL Host: "+urlHostName+" vs. "
+session.getPeerHost());
return true;
}
};
// set this property to the location of the cert file
System.setProperty("javax.net.ssl.trustStore", "jssecacerts.cert");
HttpsURLConnection.setDefaultHostnameVerifier(hv);
URL url = new
URL("https://cab.tivlab.austin.ibm.com:9431/rest/model/"+
"Repository?depth=1&feed=json");
HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
System.out.println("sending request...");
urlConn.setRequestMethod("GET");
urlConn.setAllowUserInteraction(false); // no user interaction
urlConn.setDoOutput(true); // want to send
urlConn.setRequestProperty( "Content-type", "text/xml" );
urlConn.setRequestProperty( "accept", "text/xml" );
urlConn.setRequestProperty( "authorization", "Basic " +
encode("administrator:collation"));
Map headerFields = urlConn.getHeaderFields();
System.out.println("header fields are: " + headerFields);
int rspCode = urlConn.getResponseCode();
if (rspCode == 200) {
InputStream ist = urlConn.getInputStream();
InputStreamReader isr = new InputStreamReader(ist);
BufferedReader br = new BufferedReader(isr);
String nextLine = br.readLine();
while (nextLine != null) {
System.out.println(nextLine);
nextLine = br.readLine();
}
}