Every customer has now understood that
digitalisation means to get your company
ready to embrace change. Maybe that's why
digitalisation contains all the letters of the word "
agile".
Being agile also means to be able to chose the best fitting solution in a sky full of cloud services. Many customers already use Azure, Google, Amazon and SAP, along with other specific services like Dropbox, Twitter, GitHub, Slack, Twitter, MailChimp, etc..
Using each one of these services separately is pretty easy: find and read the documentation, understand security like authentication, implement pagination, handle errors,.... This is pretty interesting (and may even be fun), but just imagine you have to do this for
all of your cloud services. Now it gets exhausting because all cloud services have different documentation, security, pagination, errors, etc.. This is where SAP Cloud Platform Open Connectors come into play:
one service to rule them all (I like that sentence although it kind of sounds familiar to me).
From now on, whenever you need to connect to a cloud service, you can define, test and check documentation of that API in OpenConnectors, centrally. This facade also brings advantages whenever changes are done in the cloud service (API update, authentication change, etc..), reducing efforts in the usage of these APIs.
To become proficient with SAP Cloud Platform Open Connectors, you can refer to any of the many information sources. Here is a list of interesting links I found so far:
Now my 2 cents to the awesome blogs above, is a simple guide that shows how to write the incoming payload of a SAP Cloud Platform Integration into Google Drive.
In the following lines, I will assume that you already have created an Open Connector to Google Drive, using the instructions found
here. It is pretty easy, but make sure you copy your token and SAP Cloud Platform OpenConnector URL to be used in the following steps.
I will also assume that you have an integration flow in place. In that you can add a multicast to parallelise the connection to Google Drive.
EDIT (29.03.2019): as part of our March Update, we now have the possibility to use a dedicated OpenConnectors adapter instead of the HTTP adapter.
Check out the details here:
https://blogs.sap.com/2019/03/13/cloud-integration-how-to-create-a-sample-integration-scenario-using...
Step 1: Add the GoogleDrive receiver system
You start with an existing integration flow such as the following (based on the CLD900 in class SAP course
🙂 😞
Add the "Receiver" as well as an "end message" components to your integration flow. Link them together from the multicast, and select "HTTP" for the connection. I also like to reposition the links so that the flow stays clean:
Click on the link connecting the GoogleDrive system (you may want to rename it too).
In the "Connection" tab, enter the following details:
As you may have noticed, we are using a property that we will create in the next step. We will also create the authentication in the next step, using the OpenConnector token.
Also, you may want to make sure that you have an "SAP" folder in GDrive, otherwise adapt the
Query to your file structure or create an "SAP" folder.
Step 2: Generate the file and the message for Google Drive
In this step, we will generate the message to be received by google drive, through the open connector.
To do so, add a Groovy Script component on the link between the multicast and the end message.
Click on the "+" button to create a script.
In the code editor, replace the complete code with the one below.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.text.SimpleDateFormat
def Message setHeader(Message message, String id) {
message.setHeader("authorization", "your_OpenConnector_token_here");
message.setHeader("content-type","multipart/form-data; boundary=--------------------------" + id);
return message;
}
def ByteArrayOutputStream getMultiPartBody(payload, filename, id) {
String charset = "US-ASCII";
def LINEFEED = "\r\n";
def output = new ByteArrayOutputStream();
output.write(("----------------------------"+ id).getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write(("Content-Disposition: form-data; name=\"file\"; filename=\""+filename+"\"").getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write("Content-Type: text/plain".getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write(LINEFEED.getBytes(charset));
byte[] byteArray = payload.getBytes();
for (int i = 0; i < byteArray.length; ++i)
output.write(byteArray[i]);
output.write(LINEFEED.getBytes(charset));
output.write(("----------------------------"+ id + "--").getBytes(charset));
output.write(LINEFEED.getBytes(charset));
return output;
}
def Message processData(Message message) {
String charset = "US-ASCII";
def id = "238360769909770904663504";
def map = message.getProperties();
def date = new Date()
sdf = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss")
def filename = "Your_File_Name_" + sdf.format(date) + ".txt";
def ByteArrayOutputStream output = getMultiPartBody(message.getBody(String.class),filename,id);
//def ByteArrayOutputStream output = getMultiPartBody("myPayload",filename,id);
message.setProperty("filename_property",filename);
message = setHeader(message, id);
message.setBody(output)
return message;
}
Note that I have re-used
Divya's code and adapted it to our specific needs.
Take a minute to review the code to replace the token with your own OpenConnector token, and if wanted, change the file name.
Step 3 - Test
If everything works fine, you should now be able to start your integration flow as usual. In parallel to your normal processing, a file containing the payload of your integration flow is created on Google Drive:
Final Words
As you can see, it is no rocket science to use OpenConnectors in a medium-complex scenario. But the true beauty of OpenConnectors is the fact that all of the APIs can be used in the same way, hence there is no steep learning curve when you want to connect to new services. Also, the OpenConnectors being managed centrally, it simplifies operations when it comes to changes in the cloud services.