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:
Create a new project
Follow the HCI doco for this part (I'll just do it here with a few screenshots).
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
click Next
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:
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:
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.
Select the Adapter Specific tab and enter details as required. As you can see I am using secured parameters
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.
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
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.