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.
cancel
Showing results for 
Search instead for 
Did you mean: 
Introduction

SAP Cloud Integration platform provides capability to add custom adapters to the Integration tooling via SAP ADK Framework. You can refer my earlier blog on how to create your own adapter using the SAP ADK Frame work. The Adapter you develop is essentially an OSGi composite subsystem. A good starting point to learn more about OSGi SubSystem is here

In OSGi environment, every service we use supposed to be an OSGi bundle. In this blog I will show you how you can use an external service which is non-osgi.

We will use HTTP client in out adapter. The maven coordinates given below









<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient</artifactId>

<version>4.5.5</version>

</dependency>


 

Note: This is a common problem in OSGi to refer to non-osgi jars. You can also refer external documents if needed.

Prerequisite

  1. You have already created a simple adapter as described in this blog

  2. You need to be aware of Java development

  3. You need to be aware of OSGi and OSGi subsystem specification. The adapter you develop is an OSGi esa file with type as Composite. This means it has be self-contained. If you use any dependencies, they must be bundled within this ESA.


Development


Let’s begin by creating a simple adapter as described here.

I have created a Test adapter project. This adapter will use the HTTP client to make a call to the google website. There is no major logic added to the receiver. The main objective is to show the usage of non-osgi jars in ADK; in this case the non-osgi jar is HTTP client

Step 1 - Identify your dependent service (in this case HTTPClient).


First step is to understand your service. If you want to use an apache HTTP Client, it is very important to know all its dependent service tree. A service may have more than one dependent services. You need to bring all of them to your project with appropriate versions. My HTTP client has a set of total 10 jars (dependencies).

Step 2 - Download the HTTP jars


Let’s download the HTTP client jars and here is my list of the jars

Following is the list of downloaded jars.


Step 3 – Create Adapter project


Create a sample adapter. In my project I have named it as MyHttpClient. Refer my blog on creating sample adapter

 

Step 4 -Create a lib folder



  1. In the current project, create a lib folder

  2.  Add all the HTTP jars downloaded to the lib folder (shown below)



3.  Add the lib folder to the build path.And select all the Lib jars and Apply (Save and close)


 



 

Step 5 - pom changes


We have two OSGi artifacts in an ADK project; 1) Camel Component and 2) The final ESA (target after build) Since we are using the dependencies from the lib, we need to give this information to the OSGi class path loader.  We use Bundle Classpath concept. For details refer OSGi specification.



We have added httpComponent as maven dependency for the design time to work. You must add the httpcomponents to the exclude list because this will conflict with other versions of the HTTP client of the server. Simply add the package to the <excludeGroupIds>



 

Step 6 – Use your service i.e. HttpClient in the Producer


I will simply test the receiver (Producer) here. Open the Producer (MyHttpCliendProducer) and replace your default process method with following
public void process(final Exchange exchange) throws Exception {

HttpClient client = new DefaultHttpClient();

HttpGet request = new HttpGet("https://www.google.co.in/");

HttpResponse response = client.execute(request);

StringBuilder stringBuilder = new StringBuilder();



// Get the response

BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));



String line = "";

while ((line = rd.readLine()) != null) {

stringBuilder.append(line);

}

exchange.getIn().setBody(stringBuilder.toString());

}

 

We are not adding any business logic here. We are simply making a call to google.com.

 

Step 7 – Build, deploy and consume


Build the adapter. Refer the old blog for digitals and deploy. (make sure you undeploy earlier sample adapters as they all use default endpoint names)

Build a simple Integration flow with HTTP as sender. Give the HTTP endpoint name as “testMe”

Add your new receiver. We are simply not using any adapter properties and hence no need to add any.

Deploy your Integration flow

 



 

 

After deployment, make a call to the HTTP endpoint “testMe”

 

https://<your node Url>/http/testMe

 

This should simply open the google.com page.

 

 

 

 
2 Comments