Skip to Content

In a previous post I explored how to create a custom HCI adapter.  That is good if you have some very specific needs but most often you can just reuse an existing Camel component.  There are many Camel components already (just check which ones are compatible with your HCI tenant version).

The aim is to retrieve a Gmail profile but really you can also get messages, labels etc if you want.  I’ve decided to use the GoogleMail component.  The process is relatively easy:

  • Create OSGi bundle for dependent libraries
  • Create the HCI adapter and modify the metadata.xml
  • Create a test integration project to see how it works.


Create OSGi bundle

If the Camel component has dependencies on other 3rd party libraries then they need to be deployed with the adapter.  The way to do it is to create an OSGi bundle that contains all the dependent libraries.  Later this OSGi bundle will be imported into the adapter project.

Check dependencies

The easiest way to see the dependencies is to open the pom.xml in Eclipse and click the Dependency Hierarchy tab.  Below is the dependencies camel-google-mail jar has:

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

Create a new project

Follow the HCI doco for this part (I’ll just do it here with a few screenshots).

Instruction Screenshot
  • In Eclipse, go to Start of the navigation path File Next navigation step New Next navigation step Project End of the navigation path.
  • In the New Project wizard, search for Plug-in Development and select Plug-in from Existing JAR Archives.
  • Choose Next.
/wp-content/uploads/2016/05/g002_946787.png
  • If you have the JAR in the current workspace, then choose Add and select the JAR file from the JAR selection dialog.
  • If you do not have the JAR in your current workspace, then choose Add External and select the required JAR file from your local system.
  • Choose Next.
/wp-content/uploads/2016/05/g003_946788.png
  • In the Plug-in Project Propertiesdialog, specify a name in the Project name field.
  • In the Execution Environment drop down list box, select any java version that is less than or equal to JavaSE-1.7.
  • In the Target Platform, select an OSGi framework option.
  • Choose Finish.
/wp-content/uploads/2016/05/g004_946789.png
  • Select the MANIFEST.MF file of your project, and go to Runtime tab.
  • Choose Add.
  • Select the required export packages.
  • Choose OK and save the MANIFEST.MF file.
/wp-content/uploads/2016/05/g005_946790.png
  • Right Click on the project and choose Export.
  • In the Export wizard search for plug-in Development and choose Deployable plug-ins and fragments.
  • Choose Next.
/wp-content/uploads/2016/05/g006_946791.png
  • Choose Browse and select the directory where you want the plug-in to be generated.
  • Choose Finish.
/wp-content/uploads/2016/05/g007_946792.png

Create the HCI adapter

The next step is to create a new HCI adapter project.  Open Eclipse and select File > New > Other..  Expand the SAP HANA Cloud Integration section and select Adapter Project

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

click Next

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

click Finish

Now we need to do a bit of copy/paste.

  • Copy the google-mail-library.x.jar that was exported in the previous step and paste it in the gmail-adapter\libs folder.
  • Locate the camel-google-mail-x.jar (central repo or in your local maven repo) and paste it to the gmail-adapter\component folder.

Lastly right click the gmail-adapter project and select Generate Component Metadata.  The resulting project should look like this:

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

Modify metadata.xml

Modify the metadata.xml file by adding the <Varian> element.  Make sure your metadata.xml looks like below:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ComponentMetadata ComponentId="ctype::Adapter/cname::apache:google-mail/version::1.0.0" ComponentName="apache:google-mail" UIElementType="Adapter" IsExtension="false" IsFinal="true" IsPreserves="true" IsDefaultGenerator="true" MetadataVersion="2.0" xmlns:gen="http://www.sap.hci.adk.com/gen">
  <Variant VariantName="Get Profile" gen:RuntimeComponentBaseUri="google-mail" VariantId="ctype::AdapterVariant/cname::apache:google-mail/tp::https/mp::none/direction::Receiver" IsRequestResponse="true" MetadataVersion="2.0" AttachmentBehavior="Preserve">
  <InputContent Cardinality="1" Scope="outsidepool" MessageCardinality="1" isStreaming="false">
  <Content>
  <ContentType>Any</ContentType>
  <Schema xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></Schema>
  </Content>
  </InputContent>
  <OutputContent Cardinality="1" Scope="outsidepool" MessageCardinality="1" isStreaming="false">
  <Content>
  <ContentType>Any</ContentType>
  <Schema xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></Schema>
  </Content>
  </OutputContent>
  <Tab id="connection">
  <GuiLabels guid="8c1e4365-b434-486a-8ec8-2a8fd370f77f">
  <Label language="EN">Connection</Label>
  <Label language="DE">Connection</Label>
  </GuiLabels>
  <AttributeGroup id="defaultUriParameter">
  <Name xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">URI Setting</Name>
  <GuiLabels guid="d1004d88-8e54-4f46-a5e7-e6e4d0dca053">
  <Label language="EN">URI Setting</Label>
  <Label language="DE">URI Setting</Label>
  </GuiLabels>
  <AttributeReference>
  <ReferenceName>firstUriPart</ReferenceName>
  <description>Configure First URI Part</description>
  </AttributeReference>
  <AttributeReference>
  <ReferenceName>userId</ReferenceName>
  <description>Gmail User Id</description>
  </AttributeReference>
  </AttributeGroup>
  <AttributeGroup id="googleMailEndpoint">
  <Name xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Google Mail Endpoint</Name>
  <GuiLabels guid="7a914dcf-ab5e-4dfc-a859-d4709bd7402d">
  <Label language="EN">Google Mail Endpoint</Label>
  <Label language="DE">Google Mail Endpoint</Label>
  </GuiLabels>
  <AttributeReference>
  <ReferenceName>clientId</ReferenceName>
  <description>Client Id</description>
  </AttributeReference>
  <AttributeReference>
  <ReferenceName>clientSecret</ReferenceName>
  <description>Client Secret</description>
  </AttributeReference>
  <AttributeReference>
  <ReferenceName>accessToken</ReferenceName>
  <description>Acess Token</description>
  </AttributeReference>
  <AttributeReference>
  <ReferenceName>refreshToken</ReferenceName>
  <description>Refresh Token</description>
  </AttributeReference>
  </AttributeGroup>
  </Tab>
  </Variant>
  <AttributeMetadata>
  <Name>firstUriPart</Name>
  <Usage>false</Usage>
  <DataType>xsd:string</DataType>
  <Default></Default>
  <Length></Length>
  <IsParameterized>true</IsParameterized>
  <GuiLabels guid="d78fa735-e35e-49f1-95cb-a82b075615be">
  <Label language="EN">First URI Part</Label>
  <Label language="DE">First URI Part</Label>
  </GuiLabels>
  </AttributeMetadata>
  <AttributeMetadata>
  <Name>userId</Name>
  <Usage>false</Usage>
  <DataType>xsd:string</DataType>
  <Default></Default>
  <Length></Length>
  <IsParameterized>true</IsParameterized>
  <GuiLabels guid="71bcdd72-6b26-4423-b684-76d1ef626ca1">
  <Label language="EN">Gmail User Id</Label>
  <Label language="DE">Gmail User Id</Label>
  </GuiLabels>
  </AttributeMetadata>
  <AttributeMetadata>
  <Name>clientId</Name>
  <Usage>false</Usage>
  <DataType>xsd:string</DataType>
  <Default></Default>
  <Length></Length>
  <AttributeBehavior>SecureAlias</AttributeBehavior>
  <IsParameterized>true</IsParameterized>
  <GuiLabels guid="71bcdd72-6b26-4423-b684-76d1ef626ca1">
  <Label language="EN">Client Id</Label>
  <Label language="DE">Client Id</Label>
  </GuiLabels>
  </AttributeMetadata>
  <AttributeMetadata>
  <Name>clientSecret</Name>
  <Usage>false</Usage>
  <DataType>xsd:string</DataType>
  <Default></Default>
  <Length></Length>
  <AttributeBehavior>SecureAlias</AttributeBehavior>
  <IsParameterized>true</IsParameterized>
  <GuiLabels guid="dbf6df69-7666-46e5-9aaf-074d2fc0a080">
  <Label language="EN">Client Secret</Label>
  <Label language="DE">Client Secret</Label>
  </GuiLabels>
  </AttributeMetadata>
  <AttributeMetadata>
  <Name>accessToken</Name>
  <Usage>false</Usage>
  <DataType>xsd:string</DataType>
  <Default></Default>
  <Length></Length>
  <AttributeBehavior>SecureAlias</AttributeBehavior>
  <IsParameterized>true</IsParameterized>
  <GuiLabels guid="b8748d93-076c-46cb-b694-c84f6cd3095c">
  <Label language="EN">Access Token</Label>
  <Label language="DE">Access Token</Label>
  </GuiLabels>
  </AttributeMetadata>
  <AttributeMetadata>
  <Name>applicationName</Name>
  <Usage>false</Usage>
  <DataType>xsd:string</DataType>
  <Default></Default>
  <Length></Length>
  <IsParameterized>true</IsParameterized>
  <GuiLabels guid="c17aa8da-765e-417c-987f-b06f7aabd4bf">
  <Label language="EN">Application Name</Label>
  <Label language="DE">Application Name</Label>
  </GuiLabels>
  </AttributeMetadata>
  <AttributeMetadata>
  <Name>refreshToken</Name>
  <Usage>false</Usage>
  <DataType>xsd:string</DataType>
  <Default></Default>
  <Length></Length>
  <AttributeBehavior>SecureAlias</AttributeBehavior>
  <IsParameterized>true</IsParameterized>
  <GuiLabels guid="5373e7c4-cd24-40b8-957b-bc37f32376f7">
  <Label language="EN">Refresh Token</Label>
  <Label language="DE">Refresh Token</Label>
  </GuiLabels>
  </AttributeMetadata>
</ComponentMetadata>





Again, the parameters are secured.  To ensure all is good right click the project and select Execute Checks.  You should see the following in the console:


[9/05/16 3:49 PM] Checks executed successfully




And finally do a local build.  Right click the project and select Build Adapter Project.  Your should see the following in the console:


[9/05/16 3:51 PM] Build completed




Create a test integration project

Create a new integration project called google-mail-integration.  The outcome should be as follows:


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

Select the Channels tab and click on Browse.  If all went well you will see the google-mail adapter as an option in the dialog.  Select the google-mail option.

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

Select the Adapter Specific tab and enter details as required.  As you can see I am using secured parameters

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

You can also use some other endpoint prefix, see     Apache Camel: GoogleMail   

Deploy the HCI adapter

Deploy to your HCI tenant and check it deployed successfully.

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


Missing dependencies will throw an exception similar to this:

org.osgi.service.subsystem.SubsystemException: org.osgi.service.resolver.ResolutionException: Unable to resolve /tmp/inputStreamExtract2522187002793448101.zip/camel-google-mail-2.16.2.jar: missing requirement org.apache.aries.subsystem.core.archive.ImportPackageRequirement: namespace=osgi.wiring.package, attributes={}, directives={filter=(&(osgi.wiring.package=com.google.api.client.http.javanet)(version>=0.0.0))}, resource=/tmp/inputStreamExtract2522187002793448101.zip/camel-google-mail-2.16.2.jar

Go back and ensure the missing lib is in the OSGi bundle.


Deploy the integration project

Deploy the google-mail-integration project to your tenant and monitor the messages.  If everything worked you will see something like this

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

Conclusion

So it is much easier to use an existing Camel component than creating your own from scratch.  And although this example does not do anything significant it shows how to create an adapter using Camel components.

To report this post you need to login first.

7 Comments

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

  1. Michal Michalski

    Hi Nic,

    First of all thanks for your great blogs.

    I have a question regarding the one above.

    You mention that we should “just check which ones are compatible with your HCI tenant version”.

    Could you please give a hint on how can we check that?

    Can you confirm that we should look at HCI docu (currently it states camel core should be 2.12.3) and then we should download jars which are dependent on this version of camel core?

    Thanks.

    Best Regards,

    Michal Michalski

    (0) 
      1. Michal Michalski

        Thanks Nic.

        The camel-core component is also presented in the working node artifact list. We can see there that the current camel-core version is 2.16.2.

        I am trying to replicate your scenario along with other components. I keep on being stuck on deployment phase. It fails with errors as you mentioned:

        Nic Botha wrote:

        Missing dependencies will throw an exception similar to this:

        org.osgi.service.subsystem.SubsystemException: org.osgi.service.resolver.ResolutionException: Unable to resolve /tmp/inputStreamExtract2522187002793448101.zip/camel-google-mail-2.16.2.jar: missing requirement org.apache.aries.subsystem.core.archive.ImportPackageRequirement: namespace=osgi.wiring.package, attributes={}, directives={filter=(&(osgi.wiring.package=com.google.api.client.http.javanet)(version>=0.0.0))}, resource=/tmp/inputStreamExtract2522187002793448101.zip/camel-google-mail-2.16.2.jar

        Go back and ensure the missing lib is in the OSGi bundle.

        I went back a number of times and the packages mentioned are there in the OSGi bundle. I ended up in adding all jars up to jars where there are no dependencies  (tracked via maven) and still HCI won’t see the packages.

        1. Are the jars on your screen (second in table from section “Create a new project”) all the jars that are needed for google-mail-2.16.2?

        2. Have you experienced similar behavior? How did you walk around this?

        Many thanks for your inputs.

        Best regards,

        Michal

        (0) 
        1. Nic Botha Post author

          Hi Michal,

          1. Are the jars on your screen (second in table from section “Create a new project”) all the jars that are needed for google-mail-2.16.2?

          • Yes, that I can confirm

          2. Have you experienced similar behavior? How did you walk around this?

          • Yes, but by adding the missing dependency it was resolved.  Not very helpful I know.

          Can you share the error msg you are getting? And also a bit more info on the other components you are mentioning.

          Regards,

          Nic

          (0) 
          1. Michal Michalski

            Hi Nic,

            Thank you very much for your swift reply.

            1. I managed to deploy the google-mail adapter. However there was nothing different to what I did previously besides one thing. I had a couple more jars in the OSGi bundle than on your list. My list of jars was downloaded by maven based on POM with only one entry:

            <!– https://mvnrepository.com/artifact/org.apache.camel/camel-google-mail –>

            <dependency>

                <groupId>org.apache.camel</groupId>

                <artifactId>camel-google-mail</artifactId>

                <version>2.16.2</version>

            </dependency>

            I got these downloaded and highlighted once used for Plug-In project to export OSGi bundle:

            /wp-content/uploads/2016/10/jars_1048038.jpg

            With these libs HCI deployment fails with errors mentioning packages which are embedded in the jar.

            Would you know what is the key based on which you limited the jars from which you created the OSGi bundle? This is the main question for me now.

            2. As a second adapter I tried to deploy camel-stomp component onto HCI.

            The issue is the same. Deployment fails with libs provided in the OSGi bundle and complains about missing dependency while the dependency is there in the jar:

            /wp-content/uploads/2016/10/stomp_osgi_1048039.jpg

            /wp-content/uploads/2016/10/stomp_dep_err_1048064.jpg

            Would you have an idea on how to overcome this error?

            3.  I  have also raised a ticket to SAP with an issue that adapters that failed to deploy and after being undeployed still are visible in the list when you configure the channel. Have you noticed the same?

            Many thanks for you inputs. Greatly appreciated!

            Best regards,

            Michal

            (0) 
  2. JOnes Peter

    Hi Nic,

    I’m really struggling to get an adapter project to deploy  ! I’m trying to implment the camel-weather component and following the steps you’ve shown above but keep getting error messages such as

    2017 02 28 17:21:37#+00#ERROR#com.sap.it.nm.core.deploy.action.DeployTask##anonymous#AvatarThreadHIGH5#na#avrhcie#e0401iflmap#web##[CONTENT][CONTENT_DEPLOY][ErrorDeployArtifact]:Deployment of artifact: org.osgi.service.subsystem.SubsystemException: org.osgi.service.resolver.ResolutionException: Unable to resolve /tmp/inputStreamExtract15077490853259895.zip/camel-weather-2.16.2.jar: missing requirement org.apache.aries.subsystem.core.archive.ImportPackageRequirement: namespace=osgi.wiring.package, attributes={}, directives={filter=(&(osgi.wiring.package=org.apache.camel.spi)(&(version>=2.16.0)(!(version>=2.17.0))))}, resource=/tmp/inputStreamExtract15077490853259895.zip/camel-weather-2.16.2.jar was unsuccessfull on node: weather-adapter for task: NodePresence {, nodeId=59384d96139eeeaadafbfa3ff96c9fc3f1948fcf, baseUri=https://vsa2144953.od.sap.biz:8041/, nodeType=IFLMAP, productVariant=HCI, nodeCoordinate=NodeCoordinate { account=avrhcie, application=e0401iflmap, tenantId=a17f5e9a1, clusterName=avrhcie.gbt131.e0401 } , version=2.24.8, nodeStackProfileId=iflmap} with error message: e9583280-ee46-452e-a1bb-5f220d6d5d5a|

     

    I’m assuming it’s related to the version of camel-core that our HCI tenant is running (which appears to be 2.16.2.sap-17).

     

    Please, please help as this is so frustrating…..

     

     

    (0) 

Leave a Reply