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: 
mandy_krimmel
Advisor
Advisor
This blog describes how to configure the new Poll Enrich pattern in combination with the sftp adapter, elaborating on use cases and different configuration options.

Use Poll Enrich with SFTP Adapter


In general, there are three main use cases for the Poll Enrich pattern:

  • You want to enrich the message payload with additional data retrieved from a file on the sftp server.

  • You want to poll from an sftp server triggered by an external trigger, for example triggered via HTTP call.

  • You need to poll from an sftp server but want to define the configuration in the sftp adapter dynamically, for example from a partner directory.


In this blog, I will focus on the second and third use case. Yet, I will shortly also mention the configuration option for the first use case when discussing the integration flow configuration.

This is the simple integration flow we are going to build:


The flow starts with a HTTP inbound adapter that triggers the message processing. In a subsequent Content Modifier, some properties are defined that are used dynamically in the sftp adapter when polling the file from sftp server. At the very end, the message is sent out to the receiver system.

Let's start.

In the integration flow, draw a connection from the Sender participant to the Start Message event and select the HTTP adapter; then add a Content Modifier next to it. Configure the HTTP adapter as you like.

In the Content Modifier, you define the properties that are to be used dynamically in the SFTP Adapter. For dynamically configurable settings, refer to the blog Cloud Integration – Dynamically Configure the SFTP Receiver Adapter. The same settings are allowed dynamically in the sftp adapter in the Poll-Enrich pattern. Note that with the first increment (version 1.0 of the Poll Enrich sftp adapter), Proxy Type and Authentication can't yet be set dynamically.

For my simple scenario, I define the following properties to set them dynamically via XPath from the incoming http request:


Next to the Content Modifier, configure the Poll Enrich step. For this, in the Call section of the modeler, select External Call and then Poll Enrich.


In the Poll Enrich step, we have to configure how the payloads need to be aggregated: the one before the Poll Enrich step and the payload fetched from sftp server need. In addition you configure what to do if no message is found on the sftp server.


The aggregation is configured with the help of the Aggregation Algorithm in the Poll Enrich step:


For our use case (to simply read files via external trigger or via dynamic configuration in the sftp adapter), the Replace option is the correct choice. This algorithm simply replaces the original message (payload and headers) before the Poll Enrich step with the new one fetched from the sftp server.

If you want to enrich your original payload (use case 1), you have to select one of the other two algorithms:

  • Combine XML: This option combines the message polled from the sftp server with the original message in multimapping format. This option makes most sense if both, the original and the polled message, are XML messages.

  • Concatenate: The message polled from the sftp server is added to the existing message. This option is useful for strings.


If you want to get an exception in case no message is found on the sftp server you can select the checkbox Throw Exception if no Message Found. If not selected, the header SAP_PollEnrichMessageFound is set to false if no message can be found during processing. Based on the header you can configure alternative processing.

Having defined the Poll Enrich step, we now need to configure the SFTP adapter. To do so, add another Sender participant and draw a connection from this new Sender participant to the Poll Enrich step. Select the SFTP adapter.

The configuration of the SFTP adapter will look familiar to you because it contains almost the same configuration options as the normal SFTP sender adapter. Some configurations, like the Scheduler tab, are missing because they are not relevant in this pattern, but most settings are equal.

In the configuration we specify the properties defined in the Content Modifier:


As a final step, configure a connection to the Receiver participant to send the message out.

Deploy the flow and trigger it with a payload that provides the necessary data; in my example, I use the following simple payload:
<?xml version='1.0' encoding='UTF-8' ?>
<request>
<sftp>
<Directory>test/test1</Directory>
<File>TestFile*</File>
</sftp>
</request>

Note that in case no file can be found on the sftp server, the processing continues with the payload before the Poll Enrich step. It is planned to offer specific handling in such a case.

I hope this simple scenario helps you to understand the Poll Enrich pattern.

Planned Extensions:



  • Dynamic Configuration of Proxy Type and Authentication (available after the June 2021 update)

  • Keep File and Process Again option not available (available with July 2021 update)

  • Configure Handling if File is not found on the sftp server (available with August 2021 update)

  • Support FTP adapter in Poll Enrich step


 
76 Comments
mandy_krimmel
Advisor
Advisor
0 Kudos
Hello,

I would suggest to open a ticket on LOD-HCI-PI-CON-SOAP so that the experts can check the issue in more detail. Its hard to do troubleshooting without any details. Please attach the message processing logs and the two integration flows to the ticket.

Best regards

Mandy
0 Kudos
Hello Mandy.

 

Thank you for your recomendation. It worked in this way.

 

It's important to say that is not possible to transfer all Headers (set * in the Runtime Configuration - Allowed Header(s)) to the Second Flow. It looks like there is some problem with headers populated from the previous round. At least that's what I realized.

 

Best regards.

 

Fellipe
mandy_krimmel
Advisor
Advisor
0 Kudos
Hello,

some internal or adapter specific headers are not transported, this is correct.

Best regards

Mandy
0 Kudos
Hello Mandy.

Thanks for the answer, what I meant is that if you transfer all headers (with *), the second pooling doesn't work, because the headers are transfered with "dirt" from the previous run.

I believe this is also what happens when you run two (or more) pools within the same iFlow (by loop).

It might be interesting to think about creating a parameter in the Pool enrich function allowing you to configure it to clear the headers to perform the second (and nexts) pooling.

 

Best regards

Fellipe
mandy_krimmel
Advisor
Advisor
0 Kudos
ok, thank you for this details, will forward this information to the developers.

Best regards

Mandy
0 Kudos
Hi Mandy,

Thankyou for the quick response.

This scenario did not work in trial tenant. I have imported the same flows in Dev account and it worked.

 

Regards,

Sachin Belide
bellizia_pwc
Explorer
0 Kudos
Hi Mandy,

there are some news about this component?

We asked more feature on it by Influence site and we hope they will take care about them.

 

1 ) List of Files before download them  (check correct number, or use them on a splitter)

 

body example of output:

<message_enrich>

<file>

<index>1</index>

<filename>File1.xml</filename>

<size>34555</size>

<absolute_path>/in/budget/2022/</absolute_path>

<permissions>755</permissions>

<user_owner>user22</user_owner>

<group_owner>budget_group</group_owner>

</file>

<file>....</file>

</message_enrich>

 

2 ) Attribute details of a single file or directory (check permissions for validation/error allerting

 

Federico Bellizia

 
mandy_krimmel
Advisor
Advisor
0 Kudos
The features will be discussed further in the implementing team based on priority. It was not yet taken up.

Best regards

Mandy
bellizia_pwc
Explorer
0 Kudos
I did a groovy solution with Jcraft Jsh Library.

 

Now I'm trying to create an Adapter to use instead SFTP ones with all SFTP commands (ssh commands too).

 

Federico Bellizia

 

 
mandy_krimmel
Advisor
Advisor
0 Kudos
that is strange but it's good that you got it working now.

Thank you for the information.

Best regards

Mandy
kaisand
Explorer
0 Kudos
Hi Mandy,

let's say I get a CSV file from a SFTP server. I noticed that the file doesn't get written into the message body after Poll Enrich received it. I'd like to convert it via CSV to XML in one case and in the other I want to access it via Groovy Script but it doesn't work. How can I make this work? Trying to store it in a data store doesn't work either. It saves the last message to the data store then. I used 'Replace' in the Poll Enrich element.

Thank you

 
mandy_krimmel
Advisor
Advisor
0 Kudos
Hi,

don't  fully understand your scenario. You use Poll-Enrich to poll a specific file from sftp and then convert it from CSV to XML? Usually this should work. I would suggest you activate trace to check the processing in more detail. Best would be if you could create a ticket on LOD-HCI-PI-CON-SOAP, attach the integration flow and add a clear description of the problem. The experts will have a look and suggest.

Best regards

Mandy
kaisand
Explorer
0 Kudos
Never mind. I just noticed that the default behavior for the SFTP File processing with Poll enrich is "Delete file". This is a very unlucky default. The file that I wanted to get didn't exist. I couldn't notice because the file name consists of a long string of numbers and there are many files in there. "Keep file and process again" seems to be a more friendly default.
kaisand
Explorer
0 Kudos

I thought that that must be it. But no, message.getBody() in Scripts now contains the apache camel RemoteFile but if you have a write operation to the data store after the poll enrich it saves the message from before the poll enrich. I create a ticket.

mandy_krimmel
Advisor
Advisor
0 Kudos

Yes, please create a ticket. Would be great if you can share the solution afterwrds.

sabarinath00
Explorer
0 Kudos
Hi
I have a scenario
I have 6files in a folder , let's say 3jpg and 3pdf
I want the output to be 3 zip file. In each Zip file there should be 1pdf and 1jpg.

How can I solve this
mandy_krimmel
Advisor
Advisor
0 Kudos
Hello,

I could imagine the following solution:

In the integration flow do a parallel multicast fetching a pdf and the corresponding jpg with poll-enrich, in gather use the zip aggregation strategy to zip the files into one zip file:

Cloud Integration – ZIP and Compress Capabilities: Encoder, Decoder, Splitter, Aggregate | SAP Blogs

Please let me know if this works for you

Mandy
purusottam_agar
Explorer
0 Kudos
Hi Mandy,

Very informative blog!

There is one scenario, I used a looping process call->Poll Enricher->SFTP.(to poll multiple files and to use the functionality of poll enricher).

And there are 2 cases,

Case1.If No file exists in SFTP ,throw an exception when polled files from SFTP at the scheduled date & time.

Sol. To check the checkbox "Throw Exception in no message found" in Poll enricher.

case2. If there are one file/multiple files it should process it and should not through any exception.

In this case I need your help

1.What will be the looping process call condition?

2.And can I use "CamelFileName" header in Looping process call condition?

Also I have raised my question in the below link.

https://answers.sap.com/questions/13913866/how-to-fetch-multiple-files-from-sftp-using-poll-e.html

Please let me your comments.

 

Thanks,

Purusottam

 
mandy_krimmel
Advisor
Advisor
Hello,

let me give you a suggestion: when polling for the files switch off 'ThrowException', and use the documented header SAP_PollEnrichMessageFound to validate if a file was found and either continue or not. Using the CamelLoopIndex header you can further evaluate if there was no file at all processed and create an exception if required.

Hope this helps.

Best regards

Mandy
purusottam_agar
Explorer
0 Kudos
Thanks for your suggestion.

 

BR,

Purusottam
madhu198621
Explorer
0 Kudos
Hi,

 

Can you please help me how to add process direct adapter in loop process call as I want to pull multiple files from sftp with poll enrich.
mandy_krimmel
Advisor
Advisor
0 Kudos
Hello,

I don't understand your question. Could you explain a bit more about the scenario and were exactly the process direct adapter needs to come into the game?

best regards

Mandy

 
0 Kudos
Hi ,

 

I have requirement to pick 3 different files from same directory. In CPI SFTP Adapter there is no Advanced selection of source file option, so in this case can you suggest me how to pick 3 different files from same path( we can't give * as it will pick all files) only 3 files required to be picked.

Example :

apple*

google*

microsoft*

 

Can I give filename as below in SFTP adapter or  in poll enrich how to mention each filename and pick the file.

1st method - "apple* || google* || microsoft*"

2nd Method - "apple* && google* && microsoft*"
sayed42
Explorer
0 Kudos
I've created a video for this blog, just incase if someone didn't understand something you can go through this video.

https://youtu.be/md7yyuMeKm4?si=fTxAfszmTvJyIRhH
mandy_krimmel
Advisor
Advisor
0 Kudos
Complex expressions are not supported in the sftp adapter. The adapter always only picks one file. You would have to pull the files separately, either by one channel per file or by using dynamic file name option to pass the file name.

Best regards

Mandy
mandy_krimmel
Advisor
Advisor
0 Kudos
thank you for sharing 🙂