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 πŸ˜‰ .  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:

/wp-content/uploads/2016/05/mvn_arch_success_944437.png

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.

/wp-content/uploads/2016/05/eclipse_project_944472.png

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:


/wp-content/uploads/2016/05/part1_end_944473.png

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.

To report this post you need to login first.

6 Comments

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

  1. Eng Swee Yeoh

    Hi Nic

    Thank you so much for sharing such an excellent resource. This will definitely benefit the developer community.

    I just want to add on that Eclipse Luna comes with preinstalled Maven plugin (M2Eclipse). So those who are lazy (like me) can do all the steps above within the comfort of the Eclipse IDE πŸ™‚

    Regards

    Eng Swee

    (0) 
  2. Michal Krawczyk

    hi Nic,

    First of all thank you for the blog πŸ™‚

    Would you know if there would be a way to call a different iflow (context) from a custom adapter somehow ? I have two iflows (FTP and SOAP) and I need to be able to call to FTP iflow from SOAP call too (for testing purposes) without building another filow – SOAP-FTP. Do you think this would be possible ? (from PI it’s pretty easy by changing the header values but I need this for HCI too).

    Thank you for any tips πŸ™‚  

    Best Regards,

    Michal Krawczyk

    (0) 
    1. Martin Koch

      Hi Michal,

      as far is i know you can not call another iFlow directly, but you can write your message toΒ a datastore with global scope that can be polled from your other iflow triggered by an timer event.

      Best regards,
      Martin

      (1) 

Leave a Reply