1

I have dsl route:

from(String.format("sftp://%s@%s:%d/%s?password=%s&delete=true&readLock=changed&delay=%s",
                systemSettingsService.getSystemSettings().getSftpUserName(),
                systemSettingsService.getSystemSettings().getSftpHost(),
                systemSettingsService.getSystemSettings().getSftpPort(),
                systemSettingsService.getSystemSettings().getSftpSourcePathDestWorking(),
                systemSettingsService.getSystemSettings().getSftpPassword(),
                systemSettingsService.getSystemSettings().getSftpPollPeriod())).streamCaching()

                .process(...

I want to limit file size for consuming. For example I want to ignore files with size more than 100Mb. Optionally I want to have callback in case if camel met file more than 100mb

I have read:

http://camel.apache.org/ftp2.html

But I could not find anything relevant

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

3

You might consider using a filter.

from(String.format("sftp://%s@%s:%d/%s?filter=#myFilter",...

Create a custom bean that implements the GenericFileFilter interface

import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileFilter;

public class MyFileFilter<T> implements GenericFileFilter<T> {
    @Override
    public boolean accept(GenericFile<T> file) {
        // I'm guessing the return value will be in bytes
        if (file.getFileLength() < (100 * 1024 * 1024))
            return true;
        return false;
    }
}

Read more about it here. It's worth remembering that the FTP and SFTP components inherit from the File component.

Erik Karlstrand
  • 1,479
  • 9
  • 22
  • How to rrgister the filter in camel infrastructure? – gstackoverflow May 02 '18 at 06:41
  • I'm not that familiar with the Java DSL for Camel but after reading [this](https://access.redhat.com/documentation/en-us/red_hat_jboss_fuse/6.2/html/apache_camel_development_guide/basicprinciples-beanintegration) it would seem that you can use the @BeanInject annotation as explained in the section named `Accessing a Spring bean from Java` – Erik Karlstrand May 07 '18 at 08:42