本文介绍了为什么WSO2 ESB在Base64中编码电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代理服务从Gmail IMAP服务器接收电子邮件.电子邮件还具有 csv 文件附件.WSO2 ESB已成功接收到电子邮件,但是在日志附件中,内容打印为 base64 编码的字符串.以下是我的 axis2.xml 连接.

My proxy service receiving email from Gmail IMAP server. Email has csv file attachment as well. WSO2 ESB received the email successfully but in the logs attachment content is printed as base64 encoded string. Below are my axis2.xml connfigs.

    <!-- ================================================= -->
    <!--                Message Formatters                 -->
    <!-- ================================================= -->

    <!-- Following content type to message formatter mapping can be used to implement support -->
    <!-- for different message format serializations in Axis2. These message formats are -->
    <!-- expected to be resolved based on the content type. -->
    <messageFormatters>
        <messageFormatter contentType="application/x-www-form-urlencoded"
                          class="org.apache.synapse.commons.formatters.XFormURLEncodedFormatter"/>
        <messageFormatter contentType="multipart/form-data"
                          class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
        <messageFormatter contentType="application/xml"
                          class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
        <messageFormatter contentType="text/xml"
                         class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
        <messageFormatter contentType="application/soap+xml"
                         class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
        <messageFormatter contentType="text/plain"
                         class="org.apache.axis2.format.PlainTextFormatter"/>
<messageformatter contenttype="text/csv" class="org.apache.axis2.format.PlainTextFormatter"/>
        <!--JSON Message Formatters-->
        <messageFormatter contentType="application/json"
                          class="org.apache.synapse.commons.json.JsonStreamFormatter"/>
        <!--messageFormatter contentType="application/x-www-form-urlencoded"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="multipart/form-data"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <messageFormatter contentType="application/xml"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
        <!--messageFormatter contentType="text/html"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="application/soap+xml"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <messageFormatter contentType="text/xml"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
        <!--messageFormatter contentType="x-application/hessian"
                         class="org.apache.synapse.format.hessian.HessianMessageFormatter"/-->
        <!--messageFormatter contentType=""
                         class="org.apache.synapse.format.hessian.HessianMessageFormatter"/-->
        <!--messageFormatter contentType="application/edi-hl7"
                         class="org.wso2.carbon.business.messaging.hl7.message.HL7MessageFormatter"/-->
    </messageFormatters>

    <!-- ================================================= -->
    <!--                Message Builders                   -->
    <!-- ================================================= -->

    <!-- Following content type to builder mapping can be used to implement support for -->
    <!-- different message formats in Axis2. These message formats are expected to be -->
    <!-- resolved based on the content type. -->
    <messageBuilders>
        <messageBuilder contentType="application/xml"
                        class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
        <messageBuilder contentType="application/x-www-form-urlencoded"
                        class="org.apache.synapse.commons.builders.XFormURLEncodedBuilder"/>
        <messageBuilder contentType="multipart/form-data"
                        class="org.apache.axis2.builder.MultipartFormDataBuilder"/>
        <messageBuilder contentType="text/plain"
                        class="org.apache.axis2.format.PlainTextBuilder"/>

        <!--JSON Message Builders-->
        <messagebuilder contenttype="text/csv" class="org.apache.axis2.format.PlainTextBuilder"/>
        <messageBuilder contentType="application/json"
                        class="org.apache.synapse.commons.json.JsonStreamBuilder"/>
        <messageBuilder contentType="application/xml"
                        class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
        <!--messageBuilder contentType="application/x-www-form-urlencoded"
                        class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="multipart/form-data"
                        class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <messageBuilder contentType="multipart/related"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
    <!--<messageBuilder contentType="multipart/related" class="org.apache.axis2.builder.MIMEBuilder"/>-->
        <!--messageBuilder contentType="application/soap+xml"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <messageBuilder contentType="text/plain"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
        <messageBuilder contentType="text/xml"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
        <!--messageBuilder contentType="x-application/hessian"
                        class="org.apache.synapse.format.hessian.HessianMessageBuilder"/-->
        <!--messageBuilder contentType=""
                         class="org.apache.synapse.format.hessian.HessianMessageBuilder"/-->
        <!--messageBuilder contentType="application/edi-hl7"
                        class="org.wso2.carbon.business.messaging.hl7.message.HL7MessageBuilder"/-->
    </messageBuilders>

日志:

INFO - LogMediator To: /services/MailService MessageID: urn:uuid:492da964-ee6c-4ae7-b444-269ba8a52641 Direction: request%%%%%%%%%%%%Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">LS05NGViMmMxNDMyYmFmNmU3N2EwNTRiNGJiMzc5DQpDb250ZW50LVR5cGU6IG11bHRpcGFydC9hbHRlcm5hdGl2ZTsgYm91bmRhcnk9OTRlYjJjMTQzMmJhZjZlNzc2MDU0YjRiYjM3Nw0KDQotLTk0ZWIyYzE0MzJiYWY2ZTc3NjA1NGI0YmIzNzcNCkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD1VVEYtOA0KDQoNCg0KLS05NGViMmMxNDMyYmFmNmU3NzYwNTRiNGJiMzc3DQpDb250ZW50LVR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD1VVEYtOA0KDQo8ZGl2IGRpcj0ibHRyIj48L2Rpdj4NCg0KLS05NGViMmMxNDMyYmFmNmU3NzYwNTRiNGJiMzc3LS0NCi0tOTRlYjJjMTQzMmJhZjZlNzdhMDU0YjRiYjM3OQ0KQ29udGVudC1UeXBlOiB0ZXh0L2NzdjsgY2hhcnNldD1VUy1BU0NJSTsgbmFtZT0iY3N2LmNzdiINCkNvbnRlbnQtRGlzcG9zaXRpb246IGF0dGFjaG1lbnQ7IGZpbGVuYW1lPSJjc3YuY3N2Ig0KQ29udGVudC1UcmFuc2Zlci1FbmNvZGluZzogYmFzZTY0DQpYLUF0dGFjaG1lbnQtSWQ6IGZfajBra3Q0OWYwDQoNCmQyRnhZWE1zWVdkbERRcDNZWEZoY3l3eU13PT0NCi0tOTRlYjJjMTQzMmJhZjZlNzdhMDU0YjRiYjM3OS0tDQo=</ns:binary></soapenv:Body></soapenv:Envelope></soapenv:Body></soapenv:Envelope>
[2017-03-22 11:16:46,049] DEBUG - RelayUtils Content Type is multipart/mixed; boundary=94eb2c1432baf6e77a054b4bb379

代理代码:

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="MailTransportProtocolIMAP"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="mailto">
   <target>
      <inSequence>

               <log level="full" separator="---=== Invalid Subject ===---"/>

      </inSequence>
      <outSequence/>
   </target>
   <parameter name="mail.imap.starttls.enable">false</parameter>
   <parameter name="mail.imap.socketFactory.port">993</parameter>
   <parameter name="transport.mail.Address">[email protected]</parameter>
   <parameter name="mail.imap.fetchsize">100000</parameter>
   <parameter name="mail.imap.user">mapperxslt1</parameter>
   <parameter name="mail.imap.password">Password</parameter>
   <parameter name="transport.mail.ActionAfterProcess">MOVE</parameter>
   <parameter name="mail.imap.host">imap.gmail.com</parameter>
   <parameter name="transport.mail.ContentType">multipart/mixed</parameter>
   <parameter name="transport.mail.MoveAfterProcess">Processed</parameter>
   <parameter name="mail.imap.port">993</parameter>
   <parameter name="transport.PollInterval">5</parameter>
   <parameter name="transport.mail.Protocol">imap</parameter>
   <parameter name="transport.mail.Folder">inbox</parameter>
   <parameter name="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
   <parameter name="mail.imap.ssl.enable">false</parameter>
   <parameter name="mail.imap.socketFactory.fallback">false</parameter>
   <description/>
</proxy>

WSO2 ESB中有什么方法可以将附件保存在目录中吗?任何帮助将是极大的帮助.

Is there any way in WSO2 ESB to save the attachment as it is in the directory? Any help would be great favor.

推荐答案

您可以通过注册"org.apache.axis2.format.PlainTextBuilder"和"org.apache.axis2"来访问csv的请求/响应有效负载中的内容.format.PlainTextFormatter"作为文本/csv内容类型的消息生成器和格式化程序.

You can access the content inside request/response payload of csv by registering "org.apache.axis2.format.PlainTextBuilder" and "org.apache.axis2.format.PlainTextFormatter" as message builder and formatter for text/csv content-type.

请将以下格式化程序和构建器添加到axis2.xml.请检查构建器.

Please add the following formatters and builders to axis2.xml. please check builder.

<messageformatter contenttype="text/csv" class="org.apache.axis2.format.PlainTextFormatter"/>

<messagebuilder contenttype="text/csv" class="org.apache.axis2.format.PlainTextBuilder"/> 

这篇关于为什么WSO2 ESB在Base64中编码电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 22:51