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: 
nic_botha2
Explorer

Introduction

Recently I did some work in SAP HANA Cloud Integration (HCI) and started to fiddle with the available adapters.  Although they are capable and cater for most needs you might find yourself in a similar situation where you need to create your own adapter.

For those wondering - adapters are used to connect external systems to a HCI tenant. An adapter encapsulates the details of connectivity and communication.  An integration designer will make use of the design tool and choose an appropriate adapter from the available options.  The HCI documentation lists all the available adapters.

This blog is the result of my experience which I would like to share.  It is a step-by-step guide with screenshots and examples.  Also read the SAP documentation on creating HCI adapters for more information.



What we'll do

I will show you how to create a new adapter in HCI, deploy the adapter and test that it is working.  The adapter will not be based on an existing camel component, that is the topic of a future blog :wink: .  We'll create the "echo" adapter that mocks the endpoints by inserting a dummy message.

Part 1 - Create a Camel component

Part 2 - Create the HCI adapter

Part 3 - Create integration flow using new adapter and see it working

What you'll need

All code used for this blog is available here GitHub - nicbotha/hci-echo-adapter

Part 1 - Create a Camel component

Camel components are extension points used for integration. A Camel component creates endpoints that understands the many protocols, data formats, API's etc.  Remember at runtime HCI uses Camel for the mediation and routing of messages, so we can make use of this extension point and add our own component.  The outcome of this part is a Camel component.

Step - Create a Camel component using Maven

Open a command prompt and run the following maven command:


mvn archetype:generate \
   -DarchetypeGroupId=org.apache.camel.archetypes \
   -DarchetypeArtifactId=camel-archetype-component \
   -DarchetypeVersion=2.12.3  \
   -DgroupId=my.domain \
   -DartifactId=echo











ℹ -DarchetypeVersion is the most interesting because it determines the camel-core version in the pom file (which you can change later).  But make sure it is not greater than the Camel version on your tenant.

















You will be prompted for a name and a scheme.  Your component has to have a unique URI and should not match any existing components.

The output of this step should be a success message looking like:

Step - Create an Eclipse project

Staying in the same command prompt navigate to where your new pom file is and run the following maven command:


mvn eclipse:eclipse \
-DdownloadSources \
-DdownloadJavadocs












ℹ Lines 2 and 3 are optional but I always like to pull the docs and source into my projects

















The output of this step should be a success message same as previous step.

Step - Import project into Eclipse

I'm not going into detail here as you surely know how to import an existing project into Eclipse.  What I'd like to point out is the generated code and project structure.  After importing you should have a project as below.

  1. A unit test is already created and you can run it.  It creates a camel route and assert that at least 1 message is present.
  2. The main code contains component, endpoint and consumer/producer.
  3. This file is used to map the URI scheme to the component.

Step - Define a URI parameter

You can specify URI parameters that will be passed to the component at runtime using the @UriParam annotation.  We will add a parameter to allow a user to specify the delay of the consumer.  Later you will see how this parameter is used during design time in the editor allowing the designer to configure a delay time.

Edit the echoEndPoint.java and add:


public class echoEndpoint extends DefaultEndpoint {
  @UriParam
private long delay;
....
public long getDelay() {
  return delay;
  }
  public void setDelay(long delay) {
  this.delay = delay;
  }










  • line 4 - use @UriParam annotation to define a parameter
  • line 5 - create the variable

Edit the echoConsumer.java and add:


public class echoConsumer extends ScheduledPollConsumer {
    private final echoEndpoint endpoint;
    public echoConsumer(echoEndpoint endpoint, Processor processor) {
        super(endpoint, processor);
        this.endpoint = endpoint;
        setDelay(this.endpoint.getDelay());
    }









  • line 8 - the delay value is set using the parameter that was passed in the URI to the endpoint.

Step - update the test

The unit test will not pass at this stage as the endpoint now expects a parameter in the URI.  Lets modify the echoComponentTest.java by adding this expected parameter:


protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() {
                from("echo://foo?delay=1")
                  .to("echo://bar")
                  .to("mock:result");
            }
        };
    }







  • line 4 - added delay=1 parameter

Step - build and test

All that remains is to build the project and ensure the test pass.  Open a command prompt and navigate to where the project pom is.  Run the following Maven command:


mvn clean install








The output of this step should be a success message looking like:


Conclusion

In Part 1 we have created a working Camel component.  At this point the consumer expects a parameter and will add a dummy message to be routed.  In the next part we will create the HCI Adapter project.

7 Comments