how to replace string in SpEL expression?

2019-07-24 09:08发布

firstly,thanks for attention
i defined ftp adapter in my spring integration project and used mv command to move files in ftp server,directory structure is:
ftp-root
-----------Directory1\
-----------------in\
---------------------------file.in
-----------------out\

i want to move file file.in in ftp-root\Directory1\in\ directory to move ftp-root\Directory1\out\ with .out.rpt extension ftp-root\Directory1\out\a.out
i used int-ftp:outbound-gateway adapter to run mv command on ftp server,my code is:

<int-ftp:outbound-gateway id="gatewayMv"
                          session-factory="ftpSessionFactory"
                          expression="payload.remoteDirectory + '/' + payload.filename"
                          request-channel="mvChannel"
                          command="mv"
                          rename-expression="payload.remoteDirectory + '/' + payload.filename "
                          reply-channel="aggregateResultsChannel"/>

how to use SpEL expression to replace in with out in rename-expression option?

2条回答
可以哭但决不认输i
2楼-- · 2019-07-24 09:30

thanks for @Artem Bilan ane @Gary for answer
the other way to working with string define a bean as bellow :

public class StringUtil {
    public String replacement(String value,String var1,String var2) {
        return value.replace(var1,var2);
    }
}

and in expression option set to:

rename-expression="@stringUtil.replacement(payload.remoteDirectory + '/' + payload.filename,'in','out')"
查看更多
Fickle 薄情
3楼-- · 2019-07-24 09:36
rename-expression="payload.remoteDirectory + '/' + payload.filename.replaceFirst('in', 'out')"

In most cases SpEL work like the regular Java. Since filename is a String you can apply for it any string operation.

查看更多
登录 后发表回答