Introduction:
Being SAP PI consultant we all know how Dynamic Configuration works with File adapter and how to set the target filename dynamically.Now we have started with SAP HCI era and need to find how to achieve the same.Here is the blog which showcase the same by using Apache Camel File Processing Parameters in Content Modifier.
Lets discuss various use cases in detail.
Is an agile and dynamic language for the Java Virtual Machine. With-dash-signs-and-single-quotes' = 'ALLOWED' assert map. In this example, if the name of the file is Main.groovy, then the script class is going to be Main. This property controls whether to include the destination classes directory in the classpath. Apache Camel is an open source project for implementing the EIP easily in a few lines of Java code or Spring XML configuration.
1. How to set Source File Name to Target File Name
Create integration Project like below
Step 1: Configure the Sender SFTP Channel
Step 2:Configure Content Modifier to set the source file name to target file name.
CamelFileName: Parameters which holds File Name in Apache Camel Framework (Upon which SAP HCI-PI is built on).
file:onlyname.noext: Holds the filename text without considering Extension.
There are also other parameters which can utilized( See the below table )
Expression | Returns |
---|---|
file:name | HCIInputFile.xml |
file:name.ext | xml |
file:name.noext | HCIInputFile |
file:onlyname | InputFile.xml |
file:onlyname.noext | InputFile |
file:ext | xml |
Step 3:Configure the receiver SFTP Channel like below
Go ahead and deploy the integration project.Now you will have a file in the target SFTP folder with filename same as source filename.
2. How to set target filename dynamically based on key field from incoming message.
Configuration: Create integration project similar to Use Case 1 and repeat the Steps 1 and 3 .
Step 2: Content Modifier configuration
Below are parameters used in the content modifier.
${date:now:yyyyMMdd}: Captures current date of file processing.
${header.User}, ${header.Group}: Captures values from incoming file.
Go ahead and deploy the integration project.Now you will have a file in the target SFTP folder with dynamic filename based on input file.
3. How to set target filename and target folder structure directly (By leaving the Directory and FileName Blank)
Configuration: Create integration project similar to Use Case 1 and repeat the Step1
![File File](http://i.dailymail.co.uk/i/pix/2017/09/28/09/44CF009600000578-0-image-a-21_1506585747277.jpg)
Step2:
${date:now:yyyyMMdd}: Captures current date of file processing.
${header.RecordCount}:Holds number of records in the input file.
${header.User}, ${header.Group}: Captures values from incoming file.
Step3:
Go ahead and deploy the integration project.Now you will have a file in the target SFTP server with dynamic filename based on input file and in the target folder which is set in the content modifier step.
Conclusion:
Hope this blog helped beginners to dynamically set filename and target folder in SAP HCI using Content Modifier.
Reference:
[1] Content Modifier:
[2] SFTP Adapter:
[3] Apache Camel File Configuration:
Regards,
Sriprasad Shivaram Bhat
How to Implement the Splitter and Aggregator Patterns with Apache Camel
01/19/2014 By Ghaith Alrabadi
I have found that Apache Camel is a good way to load data from log files into a database. Read on to see how I did this using the splitter and aggregator patterns with Apache Camel.
Problem
![Directory Directory](http://images.clipartof.com/Clipart-Of-A-3d-Happy-Business-Camel-Smiling-Around-A-Sign-Royalty-Free-Illustration-10241292900.jpg)
We have huge logging files for a project (months of system logging), the one file can be 12 mg.These files have a special common format [comma delimited format (csv)], and every record inside the one file represents some logging data about the login user and the actions they performed inside the system.
Example:
Now what we want is to transfer these huge records from these big text files into some sort of database to make the process of searching the data faster and more comprehensive.
Solution
The first thing came into my mind was the Camel framework from Apache.Camel supports most of the “Enterprise Integration Patterns” from the excellent book by Gregor Hohpe and Bobby Woolf, I recommend reading this book which can be found on Amazon <a title=”Enterprise Integration Patterns”here.
In this solution I used two of these patterns:
The application basically reads the files one by one from a configured path to a directory, then process and marshals each line in the file into java class and at the end saves these objects into a database. The Spring framework provids beans wiring and the inversion of control so the developer can switch between different implementations, for example injecting “MysqlPersistService” or “MongoPersistService” into “PersistService”.
To download a sample of the solution please click here.
Understanding Important Classes
LogRoute.java
This class contains the definition of the route and the flow of data from the beginning of the route till the end, it includes:1- Reading the csv file from “IN” directory.2- Split and stream the contents into sequence of messages using the splitter pattern.3- Marshall every incoming csv message into Java class format.4- Aggregate every 900 messages into a List of objects using the aggregator pattern.5- Save these messages into database as a batch.6- Move the processed files into the “OUT” directory and mark as processed.
ArrayListAggregationStrategy.java
The responsibility of this class is to aggregate the incoming messages from the new Exchange into a List of messages then save that List into the old Exchange with no conditions.Please click here to read more about the Camel Exchanges.
BatchSizePredicate.java
The responsibility of this class is to end the current aggregation when the size of the aggregated List reaches a certain number and then start a new aggregation.If this condition was not satisfied for the remaining messages that have aggregate size less than the batch required size another predicate will be used to finish the route.This predicate is provided by the camel: “completionTimeout(BATCH_TIME_OUT)”; please check LogRoute.java for more information.
RouteConfiguration.java
Java based configuration to auto wire Spring components and start Camel.
service classesThese classes are used in the route to save the messages List into a database (Mysql or Mongo).
Conclusion
In this blog I provided a sample solution for data conversion from a csv file into records saved in a database using a web application that is pulling files from a specific directory. Apache Camel made it easy to implement this solution with few lines of code using the Route Builder and different Processors implementation like Aggregators and Splitters.