Cisco Evolved Programmable Network Manager API
Evolved Programmable Network Manager API Documentation

Using Java

This Java code sample uses Apache HTTPClient. It makes an unverified HTTPS request to NBI resource and print response status and body.

package com.cisco.ncs.nbi;

import javax.net.ssl.SSLContext;

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.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;

public class SampleClient {

	public static void main(String[] args) throws Exception {

		String host = "my_server";
		String user = "user";
		String password = "password";
		String baseUri = String.format("https://%s/webacs/api/v4", host);
		String restPath = "/data/InventoryDetails";

		// Set credentials
		UsernamePasswordCredentials credentials
				= new UsernamePasswordCredentials(user, password);
		CredentialsProvider provider = new BasicCredentialsProvider();
		provider.setCredentials(AuthScope.ANY, credentials);

		// Set Basic Auth context
		AuthCache authCache = new BasicAuthCache();
		authCache.put(new HttpHost(host, 443, "https"), new BasicScheme());
		final HttpClientContext context = HttpClientContext.create();
		context.setCredentialsProvider(provider);
		context.setAuthCache(authCache);

		// Set SSL context
		SSLContext sslContext = new SSLContextBuilder()
				.loadTrustMaterial(null, new TrustAllStrategy()).build();

		CloseableHttpClient client = HttpClientBuilder.create()
				.setDefaultCredentialsProvider(provider)
				.setSSLContext(sslContext)
				.setSSLHostnameVerifier(new NoopHostnameVerifier())
				.build();

		HttpGet httpGet = new HttpGet(baseUri + restPath);
		HttpResponse response = client.execute(httpGet, context);

		System.out.println(response.getStatusLine());
		String responseBody = EntityUtils.toString(response.getEntity());
		System.out.println("Response content: " + responseBody);
	}
}