读Spring Integration实际项目代码笔记(2)

1.Si-xml is useful in context file

 In last note, we introduce use si-xml transform and route. except that, si-xml also can use to do head enricher and filter

<si-xml:xpath-header-enricher>

   

   

<si-xml:xpath-filter match-value="value" match-type="case-insensitive">

   

si-xml:xpath-expression expression : The XPath expression to evaluate.

match-value : String value to be matched against the XPath evaluation result. If this is not provided, then the XPath evaluation MUST produce a boolean result directly.

match-type : Type of match to apply between the XPath evaluation result and the 'match-value'. Default is "exact". (Also can set "case-insensitive","reges"...)

2.An example for handle header info in context file

    

        expression="new Integer(headers['retryCount']) lt new Integer(${bostik.retryCount}) ? 'true' : 'false'"/>

...

   

Compare if "retrycount" in header < max retry count in property file. And if true "retrycount" +1

3.Email Attachments splitter

Most time we receive email only care kind of attachments . For example, Only excel record user data, other png file or txt file only about user info that no need transform. So we need filter and split useful files to single file.

Below simplified code include filter and split:

public class EmailAttachSplitter { 

@Splitter 

 public splitIntoMessages(final ListemailFragments) throws UnsupportedEncodingException {

//ListemailFragments are email Minimum processing unit and include an attachment and mostly email base info (from/to/subject...)

        for (EmailFragment emailFragment : emailFragments) {

            fileName = emailFragment.getFilename();

            for(String extension : this.extensionList){

            // extentinList convert the file type need process

                if (fileName.toLowerCase().endsWith(extension)) { 

                //Check file type

                    Message message = MessageBuilder.withPayload(emailFragment.getData())

                            .setHeader(FileHeaders.FILENAME, emailFragment.getFilename())

                            .build();

                    messages.add(message); 

                    //This message only contain one attachment.

              }

                continue;

            }

        }

        return messages;

    }

你可能感兴趣的:(读Spring Integration实际项目代码笔记(2))