Page tree

Skip to end of metadata
Go to start of metadata

The Data Hub components expose a set of APIs (Application Programming Interfaces) that can be queried using external tools. These APIs are internally implemented using the Java 2 Platform Enterprise Edition (J2EE) Technologies and are provided as RESTful (Representational State Transfer) web services.

These are accessible through the HTTP protocol, with data exchange taking place in XML format. These services are called by clients implemented in any programming language supporting the corresponding protocols.

Examples on writing clients

This section provides an example about how to write a client for a RESTful service. The corresponding code needs to be adapted with specific calls according to the selected API.

For RESTful services (Capacity-aware Placement Advice API, TimeForecast Model API, Search API, Backend Control API), you need to make HTTP calls using the Data Access Objects (DAO) described in this guide.

The following code shows an example of a Java REST client:

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 further discussion on exposed APIs and how they can be queried using external tools, see: