ExpressionEvaluatingRequestHandlerAdviceを使用してリモートサーバーにそれを押した後、ペイロードを削除することができません。

mhel:

私はExpressionEvaluatingRequestHandlerAdviceを使用してリモートサーバーにプッシュされたソースファイルを削除しようとしています:

    @Bean
    public Advice expressionAdvice(GenericEndpointSpec<FileTransferringMessageHandler<ChannelSftp.LsEntry>> c) {
        ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
        advice.setOnSuccessExpressionString("payload.delete()");
        advice.setOnFailureExpressionString("payload + ' failed to upload'");
        advice.setTrapException(true);
        return advice;
    }

以下のコードで:

    @Bean
    public IntegrationFlow integrationFlow() {
        return IntegrationFlows.from(fileReader(), spec -> spec.poller(Pollers.fixedDelay(1000)))
                .transform(transformer, "transform")
                .handle(
                        Sftp.outboundAdapter(sftpSessionFactory, FileExistsMode.REPLACE)
                        .remoteDirectory(sftpRemoteDirectory), 
                        c -> c.advice(expressionAdvice(c))
                )
                .get();
    }

    @Bean
    public FileReadingMessageSource fileReader() {
        FileReadingMessageSource source = new FileReadingMessageSource();
        source.setDirectory(new File(localSourceDirectory));
        return source;
    }

そして、私のTransformerクラス:


@Component
public class Transformer {

    public String transform(String filePath) throws IOException {
        String content = new String(Files.readAllBytes(Paths.get(filePath)));
        return "Transformed content: " + content;
    }

}

私はソースディレクトリをチェックするときただし、ファイルがまだそこにあります。私はここで何をしないのですか?助けてください。

私は春の統合5.2.4を使用しています。

前もって感謝します!


ここでArtemBilanの答え@に基づいて動作するコードです:


    @Bean
    public Advice expressionAdvice(GenericEndpointSpec<FileTransferringMessageHandler<ChannelSftp.LsEntry>> c) {
        ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
        // advice.setOnSuccessExpressionString("payload.delete()");
        advice.setOnSuccessExpressionString("headers[file_originalFile].delete()");
        advice.setOnFailureExpressionString("payload + ' failed to upload'");
        advice.setTrapException(true);
        return advice;
    }

アルテタ:

もう1回:

public String transform(String filePath) throws IOException {
    String content = new String(Files.readAllBytes(Paths.get(filePath)));
    return "Transformed content: " + content;
}

だから、あなたが.transform(transformer, "transform")作成しStringていませんFileこれがためokですSftp.outboundAdapter()、リモートファイルの内容にその文字列を変換することができますので。しかし、それは何であるadvice.setOnSuccessExpressionString("payload.delete()");のために行う必要がありますStringオブジェクト?私はあなたがファイルを削除したいと考えているので、あなたは正確に持っている必要がありFile、適切な作業への助言のためのオブジェクトを。

FileReadingMessageSource私たちのためを移入FileHeaders.ORIGINAL_FILEヘッダー。だから、あなたはこのに除去するために、あなたの表現を変更することができます。

headers[file_originalFile].delete()

そして、あなたはOKでなければなりません。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=340374&siteId=1