Using Public APIs

The Data Hub components expose a set of Application Programming Interfaces (APIs) that can be queried using external tools. These APIs are implemented using the Java 2 Platform Enterprise Edition (J2EE) technologies and are provided as Representational State Transfer (RESTful) web services. You can access these services using clients implemented in any programming language that supports the HTTP protocol. 

The following sample code for a Java REST client explains how to write a client for a RESTful service. The code must be adapted with specific calls according to the selected API. For RESTful services (TimeForecast Model API, Search API, and Backend Control API), you must make HTTP calls using Data Access Objects (DAO).


 Sample code
package com.bmc.bco.dataprv.test;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/*** A simple example that uses HttpClient to execute an HTTP request against
* a target site that requires user authentication.
*/

public
class ClientAuthentication {
   
public static void main(String[] args) throws Exception {
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
     credsProvider.setCredentials(
             new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
             new UsernamePasswordCredentials("user", "passwd"));
       CloseableHttpClient httpclient = HttpClients.custom()
              .setDefaultCredentialsProvider(credsProvider)
               .build();
      try {
           HttpGet httpget = new HttpGet("http://<bco_datahub_server>:wsport/dh-services/<ws_name>/<ws_method>");
           HttpClientContext context = HttpClientContext.create();
           CookieStore cookieStore = new BasicCookieStore();
           context.setCookieStore(cookieStore);           
		   context.setCredentialsProvider(credsProvider);
         
		System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget, context);
         try {
               System.out.println("----------------------------------------");
               System.out.println(response.getStatusLine());
               System.out.println(EntityUtils.toString(response.getEntity()));
           	} finally {
               response.close();
		 }
	} finally {
		httpclient.close();
			}
		}
}  

For information about the public APIs and how they can be queried using external tools, see the following topics:

Was this page helpful? Yes No Submitting... Thank you

Comments