Skip to Content

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. A new feature to this frame work is being introduced with the Aug 2017 release of Cloud Platform integration which is way more convenient for the developers. The project comes with Maven support out of the box and a sample Adapter implementation. i.e. you can simply create an Adapter project and experience the Adapter development by simply building, deploying and later consuming it in an Integration flow. Just like that. Not even writing a single line of code. Isn’t it a cool feature?

In this blog, I am going to show you how you can use this new Adapter Project Creation wizard and implement your own adapter. This contains following sections

  1. Create a Sample Adapter
  2. Deploy the Sample Adapter
  3. Consume the Sample Adapter in an Integration flow.
  4. Modify the sample Adapter to consume external dependent service.

 

1. Create a Sample Adapter with new wizard

Before you begin, do the followings

Pre-requisite

  1. Update your eclipse with latest SAP Cloud Integration tooling
  2. Download the maven plug-in from here. And install the maven plug-in to your system (locally). If you want to know how to do that refer this link
  3. After above two mandatory steps, open the eclipse (if you have not already after the update) and select File->New->Other, in the filter, provide “Adapter Project” and select “Adapter Project”. You must see the below dialog box

If you have experience in creating Adapters using SAP Cloud ADK frame work, you will see that this dialog box is almost similar. There is a check box Enable Maven, which states that this project is of type Maven by default. You can deselect this and old way of Adapter creation (Where things are manual) will be offered.

When to use the Old Project wizard? – before we begin lets understand if we need to use the old project wizard. Lets just say if you have a requirement of re-using an existing runtime component and you know its jar and dependent jars and you don’t want to add any customization, then you probably can use the Old project wizard.

Moving on, let’s enter the details keeping the Enable Maven check box selected. I have provided following details

Note that I have changed the Component and package names. Click Finish

If you have followed my suggestions on the details, you might see a fully functioning Adapter project in Maven nature.

As you can see, the new project structure is to help both UI (of your adapter) and runtime component development (along with dependencies management) in one place. Let’s look at the details of the sample implementation stub we have.

  1. GreetComponentEndpoint.java This is Enpoint class which has a String variable ‘greetingsMessage’. It is annoted with @UriParam. It contains one more important thing which will help developer a lot – that is logger. A recommended logger API is already added for you to use. You must use this logger for all your logging needs.
  2. metadata.xml – this is the metadata xml generated automatically for you (As sample). Observe that it has two fields or is firstUriPart which is by default. Another one is matching to your @UriParam i.e. ‘greetingsMessage’
  3. GreetingComponentConsumer – this is a polling consumer. What is polling consumer? Refer here. It just adds a Hello string with current time stamp.
  4. GreetingComponentProducer – this is the Receiver implementation which converts the ‘greetingsMessage’ to upper case and also appends the exchange input to the final message.
  5. GreetingComponentComponentTest – The test has a very useful test case which is to assert whether the ‘greetingsMessage’ is converted to uppercase or not. Go ahead and run the test after Maven build. If you see some error, try building the project first and then run the test.

2. Deploy the sample adapter

Enough of theory. Now lets build and deploy. Since it is a maven project, all you need to do is run the maven clean install. Once you have successfully built, check your target. It will have an ESA generated along with sample component (refer image below). You can simply deploy this ESA to the tenant (by right clicking and selecting the Deploy Adapter Project)

3. Consume the sample adapter in an Integration flow

  1. Create an Integration flow. Select your new Adapter which is Greetings as the Sender. In the Sender adapter configuration, leave the firstUri field empty and give a message to the message field say “Hello World one time” Since it is a polling consumer, you have to provide interval details. Give a longer interval to avoid many messages.
  2. Add a Request reply step and add your new Adapter as Receiver. In the Receiver adapter configuration, leave the firstUri field empty and give a message to the message field say “Hello World two times”
  3. Finally configure the email or SFTP adapter to receive the final message.

Deploy the Integration flow.

If you have configured an email adapter, you may receive periodic emails with message something like below

Hello World one time Now it is <some time stamp> : HELLO WORLD TWO TIMES

As you can see our receiver will be upper casing the given message.

4. Modify the sample adapter

Now lets get serious. This where I will show how you can start developing your adapter in more details.

Let’s think of an use case, where we want to extend this sample adapter to add some kind of formatting to the Greeting Message. Let’s say we want our Receiver to say “******** HELLO WORLD TWO TIMES *****”. i.e. add * as the formatter.

Ideally the formatting can be abstracted to a Service. There can be different formatter services (providing different characters as appenders say *, $, # etc)

For simplicity let’s assume we have StartFormatterService which appends “*” to a given message.

Let us also define that we will add this formatter only if user (Adapter user) wishes for it.

  1. Change GreetingsComponentEndpoint class – First thing for this enhancement is to add a #UriParam to our GreetComponentEndpoint. Since we just want a flag from user i.e Boolean                 Note that you have to provide getters and setters for each @UriParam
  2. Implement a formatter Service – Create a simple OSGi service which appends some *s to a given stringI will not details out on how an OSGi service will be built.
  3. Note: It is not best practice to create class and expose it as OSGi service. For simplicity and speed I have done that. Ideally there should be an interface and an implementation.
  4. Add the Formatter service dependency to your adapter project. You can directly add it to pom file or use pom file viewer (like I did here).
  5. Use the formatter service in Producer implementation
  6. Note: I have directly used the GreetMessageFormatter instance. You can use it via OSGi look up.
  7. Build the adapter project. (make sure you do this before step f)
  8. Regenerate the metadata.xml – Since we want user to take a decision about the formatting, we need to add the Boolean reference variable in the metadata. You can delete the current metadata and right click on the project and Select Generate Metadata -> Component Metadata. You can see that the new metadata has a check box added in addition to the greetingsMessage field automatically.
  9. Now perform the Step 2) i.e deploy the adapter and Re consume it in an Integration Integration flow i.e. Step 3)

 

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Ilya Kuznetsov

    Hi Gopalkrishna.

    For me your article is very interesting.

    Could you please advise, https://tools.hana.ondemand.com/additional/com.sap.it.public.generic.api-2.8.0.jar  seems to be 2.8.0 version but at Eclipse there is com.sap.cloud.adk.build_1.16.2.jar and pom.xml refers to 1.16.2 version.

    So, build is impossible.

    Where may I be wrong?

    Update: 

    Sorry,

    these are two different jars ( com.sap.cloud.adk.build_1.16.2.jar and com.sap.cloud.adk.build_1.16.2.jar ) so I will try fix my maven build. 

    (0) 
    1. Ilya Kuznetsov

      After new attempt from scratch, I have “Build failed:Build failed:null” message when RMB>Build Adapter Project.

      target/build is empty.

      com.sap.it.ide.ui.core.build.provider.BuildException: Build failed:Build failed:null
      com.sap.it.ide.ui.core.build.provider.BuildException: Build failed:Build failed:null at com.sap.it.ide.adapter.sdk.actions.BuildAdapterAction.build(BuildAdapterAction.java:191) at com.sap.it.ide.adapter.sdk.actions.BuildAdapterAction.run(BuildAdapterAction.java:69) at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:247)

      eclipse.buildId=4.6.3.M20170301-0400
      java.version=1.8.0_131
      java.vendor=Oracle Corporation
      BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
      Framework arguments: -product org.eclipse.epp.package.jee.product
      Command-line arguments: -data C:\workspace\workspace_d0204 -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

      Could you please share whole the project somewhere?

       

       

      (0) 
      1. Gopalkrishna Kulkarni Post author

         

        Hi Ilya,

        Thanks for trying this out.

        The Right click and Build/Deploy option should not be used directly.

        You must first Maven build the project by clicking on the pom file and selecting the Maven->Clean install. This step will build the ESA for you which you can deploy

         

        Let me know if your results

         

        Regards,

        Gopal

        (0) 
  2. Ilya Kuznetsov

    Hi Gopalkrishna,

    Thank you for the input. Now test adapter works fine in two tenants, both of them 2.30.15 version.

    It’s a miracle to see greetings message 🙂

     

    For developers: newly installed adapter is usable well only from Web UI (not eclipse-based).

     

    Regards, Ilya

    (0) 

Leave a Reply