TrafficOps Api Client

Simple Java API client for communicating with the TrafficOps API

Example Usage

Create Traffic Ops session

Using a provided URI

//Construct TrafficOps Session
final URI trafficOpsUri = new URI("https://trafficops.mycdn.com:443");
final TOSession.Builder toSessionBuilder = TOSession.builder()
	.fromURI(trafficOpsUri);
final RestApiSession.Builder restSession = toSessionBuilder.restClientBuilder();
final TOSession toSession = toSessionBuilder.build();

Explicitly set properties

//Construct TrafficOps Session
final URI trafficOpsUri = new URI("http://trafficops.mycdn.com:443");
final TOSession.Builder toSessionBuilder = TOSession.builder()
	.setHost("trafficops.mycdn.com")
	.setPort(443)
	.setSsl(true);
final RestApiSession.Builder restSession = toSessionBuilder.restClientBuilder();
final TOSession toSession = toSessionBuilder.build();

Logging In

//Login
final CompletableFuture<Boolean> loginFuture = toSession
	.login("MyUsername", "MyPassword");
try {
	//Timeout if login takes longer then 1sec
	loginFuture.get(1000, TimeUnit.MILLISECONDS);
} catch(TimeoutException e) {
	loginFuture.cancel(true);
	LOG.error("Timeout while logging in");
	System.exit(1);
}

Getting a list of All Servers

Synchronously

final CollectionResponse response = toSession.getServers().get();

Asynchronously

toSession
	.getServers()
	.whenCompleteAsync((servers, exception)->{
		if(exception != null){
			//Handle Exception
		} else {
			//Do something with your server list
		}
	});