preserve timestamp on file inbound channel adapter - spring

Is there a preserve-timestamp property in the file:inbound-channel-adapter like in the ftp:inbound-channel-adapter or sftp:inbound-channel-adapter?
I have a requirement to copy some files from one folder to another folder (not FTP) and I need to keep the timestamp.
If there isn't such property, can anyone suggest me how to this with spring integration?
For information, I'm using spring-integration 3.0.8.RELEASE.
Thanks a lot for the help.

The payload of the message from the file adapter is a java.io.File. If you want to move it to some other directory on the same physical disk, you could use a simple <service-activator ... expression="payload.renameTo(...)" />.
If you are using the file outbound channel adapter to copy the file to another disk, there is (currently) no option to preserve the timestamp.
I have opened a JIRA issue to add it as a new feature.
In the meantime; you could save off the lastModified in a header (using a header enricher) make the last channel before the outbound adapter a pub/sub channel, and add a second subscriber to set the lastModified on the new file.

Related

Download one file at a time through the same session in Apache Camel FTP

I want to implement following use case with Apache Camel FTP:
On a remote location I have 0 to n amount of files stored.
When I receive a command, using FTP, I want to download one file as a byte array (which one does not matter), if any files are available.
When the file is downloaded, I want to save it in a database as a blob.
Then I want to delete the stored/processed file on the remote location
Wait for the next download command and once received go back to step 1.
The files have to be downloaded through the same FTP session.
My problem is that if I use a normal FTP route, it downloads all available files.
When I tell the route to only download one, I have to create a new route for the other files and I cannot reuse the FTP session.
Is there a way to implement this use case with Apache Camel FTP?
Camel-ftp doesn't consume all available files at once it consumes them individually one after another meaning that each file gets processed separately. If you need to process them in some specific order you can try using file-name or modified date with sortBy option.
If you want to control when file gets downloaded i.e when command gets called you can call FTP Consumer endpoint using pollEnrich
Example:
// 1. Loads one file from ftp-server with timeout of 3 seconds.
// 2. logs the body and headers
from("direct:example")
.pollEnrich("ftp:host:port/directoryName", 3000)
.to("log:loggerName?showBody=true&showHeaders=true");
You can call the direct consumer endpoint with ProducerTemplate you can obtain from CamelContext or change it to whatever consumer endpoint fits your use case.
If you need to use dynamic URI you can use simple to provide the URI for poll-enrich and also also provide timeout afterwards.
from("direct:example")
.pollEnrich()
.simple("ftp:host:port/directoryName?fileName=${headers.targetFile}")
.timeout(3000)
.to("log:loggerName?showBody=true&showHeaders=true");

Need to Create File inbound channel adapter dynamically

I am new in spring integration. So please help me to resolve this problem.
Requirement is something like, we have multiple location from where we have to read the files and in future it can increase, location can be Any file system, so I am trying to use file inbound channel adapter to complete this requirement.
we can have multiple locations stored in our data base like pooling time and location from where we have to pool to get the files.
But if I go with xml configuration so I have to create new file inbound channel adapter every time in the xml configuration and all the details. if we want to pool that specific location to get the files. something like below -
int-file:inbound-channel-adapter id="AdapterOne" prevent-duplicates="false"
directory="${FileInputLoc}" filter="compositeFilter"
int:poller fixed-rate="${poolingTime}"
int-file:inbound-channel-adapter
int:service-activator input-channel="AdapterOne" ref="testbean"
bean id="testbean" class="com.SomeActivatorClass"
Please suggest me, how can I achieve this by code. so that based on data base row it create different channel adapter which pool at different time to different location.
Thanks,
Ashu

int-file:outbound-gateway ignored duplicate file name in `outbound-gateway ` memory state?

Thanks for attention, i using Spring Integration in my project, i want to retrieve files from servers into tmp folder by int-ftp:inbound-channel-adapterand move files to orginal forder by int-file:outbound-gateway for future batch processing, but i feel when file name is duplicate int-file:outbound-gateway not working for me and does not transmit the file and seems ignore them, how to solving this my problem.
<int-file:outbound-gateway id="tmp-mover"
request-channel="ready-to-process-inbound-tmp-mover"
reply-channel="ready-to-process-inbound"
directory="${backupRootPath}/ali/in//"
mode="REPLACE" delete-source-files="true"/>
Set the local-filter in the ftp inbound channel adapter to an AcceptAllFileListFilter. By default, it's an AcceptOnceFileListFilter.

Spring Integration AWS - S3-Inbound-Adapter - deleteSourceFiles and Backup files

We need to delete the files after reading it from the S3 bucket, I could not find a option. How do we delete the source file after reading the file from S3 bucket and how do I backup files after successfully reading it?
Is there way that S3-Inbound-Adapter outputs the payload to a outputchannel?
Appreciate your time and help!
Regards
Karthik
Karthik,
The S3-Inbound-Adapter works like all other file-based adapters for the remote file system. I mean FTP and SFTP. We synchronize the remote directory with the local one and pick up files from there on each poll. So, the remove operation should not be as a part of send file to output-channel process, just because the remote transfer and process are separated over the time.
I only see the option for you to delete/backup file in the end of your reading process, e.g. one more subscriber for the publish-subscriber-channel, or <transaction-synchronization on the <poller> of <int-aws:s3-inbound-channel-adapter>.
But with that you should supply somehow the AmazonS3Object properties to invoke the AmazonS3.deleteObject(String bucketName, String key) in the end...
I'm sure that we will be able to transfer those options through the MessageHeaders, so feel free to raise a JIRA on the matter!

How to receive a specific file thru BizTalk FTP receive port

My orchestration receives a message that contains a file name and I want to pick that file from my FTP. I can configure FTP receive port to receive all files from some folder in the FTP, but how do I receive a file with specific name?
The process looks like
I would rather recommend your solution of writing a custom .NET component which will fetch the file from FTP location (you can call that component from your expression shape).
Dynamically creating Receive Ports/Receive locations and later removing them won't scale and possibly will get you into serious trouble.
I'm not sure if this link helps - specifically the CreateFtpReceiveLocation method - i.e. programatically adding a receive location (pseudo dynamic receive location).
You would also need to remove the location afterwards. I'm guessing that you can also set the FileMask on the Transport Properties of the 'dynamic' Location to the filename in the Custom Props of the TransportTypeData, and would need to remove the Location once you are done with the file.

Resources