Skip to Content
0
Jul 09 at 09:46 PM

Using the downloadable SDK for SAP Cloud Integration Integration Content API

53 Views

Dear Community,

I have been trying to write a Java client for consuming the Integration Content OData API belonging to SAP Cloud Integration. To avoid creating the data structures and parsing the JSON responses myself, I had the intention of using the Java SDK which can be downloaded from https://api.sap.com/api/IntegrationContent/resource After downloading the resource, I have managed to import the coding to my IDE and have tried to call the API using the following coding:

package com.pp.test;


import com.sap.apibhub.sdk.client.*;
import com.sap.apibhub.sdk.client.auth.*;
import com.sap.apibhub.sdk.integrationcontent.model.*;
import com.sap.apibhub.sdk.integrationcontent.api.*;




public class ConfigurationsOfIntegrationFlowApiExample {




    public static void main(String[] args) {
    	
    	String user = "username";
    	String pass = "password";
    	
        ApiClient defaultClient = Configuration.getDefaultApiClient();
		String url = "https://mytenanturl.hana.ondemand.com/api/v1";
		defaultClient.setBasePath(url);
		defaultClient.addDefaultHeader("APIKey","API key copied from Business Hub"); 	
        
        HttpBasicAuth BasicAuthentication = (HttpBasicAuth) defaultClient.getAuthentication("BasicAuthentication");
        BasicAuthentication.setUsername(user);
        BasicAuthentication.setPassword(pass);




        ConfigurationsOfIntegrationFlowApi apiInstance = new ConfigurationsOfIntegrationFlowApi();
        
        IntegrationPackagesDesignApi packageAPI = new IntegrationPackagesDesignApi();
        packageAPI.setApiClient(defaultClient);
        
        try {
			CollectionOfDesigntimeIntegrationPackages result = packageAPI.integrationPackagesGet(null, null, null, null);
			System.out.println("All packages: " + result.toString());
		} catch (ApiException e1) {
			e1.printStackTrace();
		}
    }
}

As I try this, I always get a null object returned in result. I have figured out that I should be using null variables after looking at the coding of the SDK I have downloaded, but I have also tried the same call with empty strings ("") instead of null. All this is happening in spite of being able to retrieve the JSON format of my test tenant's integration packages' data in both the test view at API business hub, and using the following coding:

package com.pp.test;


import java.io.*;
import java.net.*;


public class CPIAPIClient {


	public CPIAPIClient() {


	}


	public void getThings() {


		final int BLOCK_SIZE = 1024;
		final int BUFFER_SIZE = 8 * BLOCK_SIZE;
		DataOutputStream dataOut = null;
		BufferedReader in = null;


		try {
			
			// API endpoint for own tenant
			String url = "https://mytenanturl.hana.ondemand.com/api/v1/IntegrationPackages";


			URL urlObj = new URL(url);
			HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
			// setting request method
			connection.setRequestMethod("GET");


			// adding headers
			connection.setRequestProperty("Content-Type", "application/json");
			connection.setRequestProperty("Accept", "application/json");
			// API Key
			connection.setRequestProperty("APIKey", "API key copied from Business Hub");
			
			String encoded = "properly encoded basic auth string";
			String auth = "Basic " + encoded;
			
			connection.setRequestProperty("Authorization",auth);
			
			connection.setDoInput(true);


			int responseCode = connection.getResponseCode();
			in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			StringBuilder response = new StringBuilder();
			char[] charArray = new char[BUFFER_SIZE];
			int charsCount = 0;
			while ((charsCount = in.read(charArray)) != -1) {
				response.append(String.valueOf(charArray, 0, charsCount));
			}


			// printing response
			System.out.println(response.toString());


		} catch (Exception e) {
			// do something with exception
			e.printStackTrace();
		} finally {
			try {
				if (dataOut != null) {
					dataOut.close();
				}
				if (in != null) {
					in.close();
				}


			} catch (IOException e) {
				// do something with exception
				e.printStackTrace();
			}
		}
	}


	
	
	public static void main(String[] args) {
		
		CPIAPIClient client = new CPIAPIClient();
		
		client.getThings();


	}


}

Does anyone have an idea about any modification which could help me retrieve the data?

Thanks and best regards,

Péter