Example usage for org.springframework.integration.mail.dsl Mail headers

List of usage examples for org.springframework.integration.mail.dsl Mail headers

Introduction

In this page you can find the example usage for org.springframework.integration.mail.dsl Mail headers.

Prototype

public static MailHeadersBuilder headers() 

Source Link

Document

A MailHeadersBuilder factory.

Usage

From source file:org.springframework.integration.samples.filesplit.Application.java

/**
 * Process file markers; ignore START, when END, flush the files, ftp them and
 * send an email./*from   w ww  . j a v  a2 s.c om*/
 *
 * @return the flow.
 */
@Bean
public IntegrationFlow markers() {
    return f -> f.<FileSplitter.FileMarker>filter(
            m -> m.getMark().equals(FileSplitter.FileMarker.Mark.END), e -> e.id("markerFilter"))
            .publishSubscribeChannel(s -> s

                    // first trigger file flushes
                    .subscribe(sf -> sf.transform("'/tmp/out/.*\\.txt'", e -> e.id("toTriggerPattern"))
                            .trigger("fileOut", e -> e.id("flusher")))

                    // send the first file
                    .subscribe(
                            sf -> sf.<FileSplitter.FileMarker, File>transform(p -> new File("/tmp/out/002.txt"))
                                    .enrichHeaders(h -> h.header(FileHeaders.FILENAME, "002.txt", true))
                                    .handle(Ftp.outboundAdapter(ftp1()).remoteDirectory("foo"),
                                            e -> e.id("ftp002")))

                    // send the second file
                    .subscribe(
                            sf -> sf.<FileSplitter.FileMarker, File>transform(p -> new File("/tmp/out/006.txt"))
                                    .enrichHeaders(h -> h.header(FileHeaders.FILENAME, "006.txt", true))
                                    .handle(Ftp.outboundAdapter(ftp2()).remoteDirectory("foo"),
                                            e -> e.id("ftp006")))

                    // send the third file
                    .subscribe(
                            sf -> sf.<FileSplitter.FileMarker, File>transform(p -> new File("/tmp/out/009.txt"))
                                    .enrichHeaders(h -> h.header(FileHeaders.FILENAME, "009.txt", true))
                                    .handle(Ftp.outboundAdapter(ftp3()).remoteDirectory("foo"),
                                            e -> e.id("ftp009")))

                    // send an email
                    .subscribe(sf -> sf.transform(FileSplitter.FileMarker::getFilePath)
                            .enrichHeaders(Mail.headers().subject("File successfully split and transferred")
                                    .from("foo@bar").toFunction(m -> new String[] { "bar@baz" }))
                            .enrichHeaders(h -> h.header(EMAIL_SUCCESS_SUFFIX, ".success"))
                            .channel("toMail.input")));
}

From source file:org.springframework.integration.samples.filesplit.Application.java

/**
 * Error flow - email failure/*ww  w. ja v  a  2  s. c o m*/
 *
 * @return the flow.
 */
@Bean
public IntegrationFlow tfrErrors() {
    return f -> f
            .enrichHeaders(Mail.headers().subject("File split and transfer failed").from("foo@bar")
                    .toFunction(m -> new String[] { "bar@baz" }))
            .enrichHeaders(
                    h -> h.header(EMAIL_SUCCESS_SUFFIX, ".failed").headerExpression(FileHeaders.ORIGINAL_FILE,
                            "payload.failedMessage.headers['" + FileHeaders.ORIGINAL_FILE + "']"))
            .<MessagingException, String>transform(
                    p -> p.getFailedMessage().getPayload().toString() + "\n" + getStackTraceAsString(p))
            .channel("toMail.input");
}