sunleo
sunleo

Reputation: 10943

Spring Boot properties usage in Apache Camel route

Is this possible to use Spring Boot properties in Apache Camel route? @Value is working fine but is this possible to directly place in place holders of expressions.

Update: I know PropertiesComponent but which will be one more configuration apart from Applicaiton.yml that I don't like to have.

application.yml

sftp:
  host:     10.10.128.128
  user:     ftpuser1
  password: ftpuser1password  
  path:     /tmp/inputfile/test1

Spring Boot Apache Camel Route:

 @Value("${sftp.user}")
    private String sftpUser;

    @Value("${sftp.host}")
    private String sftpHost;

    @Value("${sftp.password}")
    private String sftpPassword;

    @Value("${sftp.path}")
    private String sftpInPath;

    from("sftp://"+sftpUser+"@"+sftpHost+sftpInPath+"?delete=true&password="+sftpPassword)
//this is working

    from("sftp://${sftp.user}@${sftp.host}${sftp.path}?password=${sftp.password}")
// is this possible something like this?

Upvotes: 7

Views: 5431

Answers (3)

ByeBye
ByeBye

Reputation: 6946

Instead of injecting all you properties to separate fields you can inject your full link like that:

@Value("#{'sftp://'+'${sftp.user}'+'@'+'${sftp.host}'+'${sftp.path}'+'?delete=true&password='+'${sftp.password}'}")
private String fullLink;

Then, you can use it in from method.

Upvotes: 3

mgyongyosi
mgyongyosi

Reputation: 2667

You can use property placeholders (http://camel.apache.org/properties.html) in Camel like this:

from("sftp://{{sftp.user}}@{{sftp.host}}{{sftp.path}}?password={{sftp.password}}")

Upvotes: 11

Manwlis.e
Manwlis.e

Reputation: 192

Haven't tried it locally but you could try to use this, by adding this properties component into the camel context( maybe u need to override the camel context configuration). Then you could use {{file.uri}} inside the from parts.

PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:com/mycompany/myprop.properties");
context.addComponent("properties", pc);

Upvotes: 2

Related Questions