Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

In the context of HCP applications, sometimes you need or it is more convenient to use a third party library that encapsulates the functionality of sending http requests. The problem with that is that the library most likely uses an implementation of the HttpClient interface, such as CloseableHttpClient.

What to do then? Surely, there are some pointers on the HCP documentation, namely here and here. There is also an API documentation.

What they all say is that HCP provides access to connectivity configuration, destination configuration and authentication headers to allow the developers making their own clients or http calls. But there is no explicit example of how they should be used for creating a CloseableHttpClient.

So here we go, there is my example for anybody who is interested. Say I have a destination and a third-party library which needs to have a CloseableHttpClient to make http calls. The most important part is apparently the proxy :-).

private CloseableHttpClient makeClient() throws Exception {

     String proxyType = destConfiguration.getProperty("ProxyType");

     HttpHost proxy = getProxy(proxyType);

     if (proxy == null)

          throw new Exception("Unable to get system proxy");

     CloseableHttpClient newClient = HttpClientBuilder.create().setProxy(proxy).build();

     return newClient;


private HttpHost getProxy(String proxyType) {        

     String proxyHost = null;        

     int proxyPort = 0;

     // Need to get proxy for internet destinations           

     if (proxyType.equals("Internet")) {                    

          proxyHost = System.getProperty("http.proxyHost");            

          proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));            

          return new HttpHost(proxyHost, proxyPort);        


     return null;    


In the example above, I assumed that the destConfiguration is already present, as specified here.