IBM Notes Traveler Administration REST API Test


package biz.bcc.traveler;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;

public class TravelerApiTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		HttpHost targetHost = new HttpHost("YourHostOrIpAddress", 80, "http");
		
		DefaultHttpClient httpclient = new DefaultHttpClient();
		try {
			httpclient.getCredentialsProvider().setCredentials(
					new AuthScope(targetHost.getHostName(),
							targetHost.getPort()),
					new UsernamePasswordCredentials("user","password"));
			AuthCache authCache = new BasicAuthCache();
			BasicScheme basicAuth = new BasicScheme();
			authCache.put(targetHost, basicAuth);

			// Add AuthCache to the execution context
			BasicHttpContext localcontext = new BasicHttpContext();
			localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

			//HttpGet httpget = new HttpGet("/api/traveler/devices");
			HttpGet httpget = new HttpGet("/api");

			HttpResponse response = httpclient.execute(targetHost, httpget,
					localcontext);
			HttpEntity entity = response.getEntity();

			System.out.println(response.getStatusLine());
			System.out.println("----------------------------------------");

			if (entity != null) {
				final BufferedReader in = new BufferedReader(
						new InputStreamReader(entity.getContent()));
				String inputLine;
				while ((inputLine = in.readLine()) != null) {
					System.out.println(inputLine);
				}
				in.close();
			}
			EntityUtils.consume(entity);

		} finally {

			httpclient.getConnectionManager().shutdown();
		}
	}

}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...