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: 
Sriprasadsbhat
Active Contributor
Introduction:

In below blog would like to share how we can integrate Amazon S3 and SuccessFactors using SAP CPI & SAP Cloud Platform Open Connectors service.

Scenario:

Lets create simple scenario to pull user dump from SuccessFactors to create file in Amazon S3 Bucket.



Configuration in AWS [ Bucket and Folder Creation ]

Step 1:

Login to your AWS account and Navigate to S3 service.



Step 2:

Create a bucket shown like below following mentioned steps.









Step 3:

Create a folder like below





Configuration in AWS[ IAM service Configuration ]:

Now lets create an user and credentials required to connect AWS S3 bucket from SAP OCN.

Step 1:

Click on Services and navigate to IAM Service.



Step 2:

Navigate to Users and Click on Add User.





If already group is available you can select or else select Create Group.









Now we are all set with AWS Configuration and make sure to copy below credentials which is required for SAP OCN Configuration.



SAP Open Connector Configuration:

Login to SAP Cloud Platform and launch Open Connectors service.Search for Amazon S3 and click on authenticate.



Fill all the required details like below ( API Key,Secret,folder name and Region Endpoint ) and click on Create Instance.



Now you are successfully connected to S3 with below message and click on API Docs.



Click on Post files operation by selecting file that needs to uploaded and folder path inside S3 Bucket.



Navigate to response to copy the credentials and endpoint url to be used in SAP CPI .



SAP CPI Configuration:

Lets create an iflow to pull the data from SuccessFactors and connect to OpenConnectors endpoint url.



Step 1:

Configure Timer Event to initiate the IFlow deployment.



Step 2:

Add Request Reply step with SuccessFactors OData V2 protocol.And configure your channel like below .You can refer below link to make sure it works.

https://blogs.sap.com/2018/04/10/sap-cloud-platform-integration-odata-v2-query-wizard/





Step 3:

Add Content Modifier and set property to set filename with folder which later can be used in receiver adapter channel.



Step 4:

Add a script to log the payload.Refer below blog for payload logging .

https://blogs.sap.com/2016/04/19/hci-logging-using-groovy-scripts/

Step 5:

Add XML to CSV converter to generate CSV file.



Step 6:

Add a script to log the payload.Refer below blog for payload logging .

https://blogs.sap.com/2016/04/19/hci-logging-using-groovy-scripts/

Step 7:

Add Script to set authorization header and set multipart data.Make sure to replace below Auth header with value copied from SAP OCN configuration.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.io.*;

def Message setHeader(Message message, String id) {

message.setHeader("authorization", "YOUR AUTH HEADER GOES 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/csv".getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write(LINEFEED.getBytes(charset));

output.write( payload.getBytes(charset));
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 = "937427310133901149517591";

def map = message.getProperties();
def filename = "sriprasadtest_1.csv"

def ByteArrayOutputStream output = getMultiPartBody(message.getBody(String.class),filename,id);
message = setHeader(message, id);
message.setBody(output.toByteArray());

return message;
}

Step 8: 

Add HTTP adapter with below mentioned parameters.



Now you are all good to go with deployment.!

Result:

Once you deploy file will be created in Amazon S3 folder.Now time to check for the result!



Reference:

[ 1 ] – Open Connector Blog series

[ 2 ] -https://blogs.sap.com/2018/09/24/blog-series-simplify-integration-with-third-party-application-with-...

Hope this helps and Happy Learning!

Regards,

Sriprasad Shivaram Bhat
10 Comments