美文网首页
读Spring Integration实际项目代码笔记(2)

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

作者: 吉祥如意酥 | 来源:发表于2018-07-29 11:09 被阅读0次

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:header name="VBELN" xpath-expression="//vbeln" overwrite="true"/>

    <si-xml:header name="COUNTRY" xpath-expression="//country" overwrite="true"/>

</si-xml:xpath-header-enricher>

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

    <si-xml:xpath-expression expression="//value"/>

</si-xml:xpath-filter>

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

<int:header-enricher>

    <int:header name="needRetry">

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

</int:header-enricher>

...

<int:header-enricher>

    <int:header name="retryCount" expression="new Integer(headers.retryCount)+1" overwrite="true"/>

</int:header-enricher>

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 <List> 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)

      本文链接:https://www.haomeiwen.com/subject/mzanmftx.html