如何从WSO2 6.2 ESB REST API或自定义中介获取内容处置内容

如何从WSO2 6.2 ESB REST API或自定义中介获取内容处置内容,wso2,esb,mediator,Wso2,Esb,Mediator,我要做的是让文件名也包含扩展名。客户机可以使用任何类型的文件(如文本、图像、文档等)发布到RESTAPI 几天来,我一直在努力解决这个问题,但不幸的是,我还没有得到任何运气 有人能帮我摆脱这一切吗 我试图从属性上下文中获取,但什么也得不到 ESB代码: <api context="/esb" name="OCR" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="POST" uri-templ

我要做的是让文件名也包含扩展名。客户机可以使用任何类型的文件(如文本、图像、文档等)发布到RESTAPI

几天来,我一直在努力解决这个问题,但不幸的是,我还没有得到任何运气

有人能帮我摆脱这一切吗

我试图从属性上下文中获取,但什么也得不到

ESB代码:

    <api context="/esb" name="OCR" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST" uri-template="/upload">
        <inSequence>
            <property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
            <property name="ContentType" value="multipart/form-data" scope="axis2"/>
            <property expression="$body//file" name="fileVar" scope="default" type="STRING"/>
            <log level="custom">
                <property name="CONTENT_DISPOSITION_1" expression="get-property('CONTENT_DISPOSITION')"/>
                <property name="CONTENT_DISPOSITION_2" expression="get-property('TRANSPORT_HEADERS')"/>
            </log>
            <class name="com.example.GetContentDisposition"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

是否可以启用wire logs来检查头是否传递到ESB服务器

是否可以启用wire logs来检查头是否传递到ESB服务器

  • 这是因为您正在使用
  • 多部分/表单数据(这有一个bug) 将其更改为:

    应用程序/x-www-form-urlencoded

    您将在日志中看到:

    [2020-08-07 12:11:36,865] [EI-Core] DEBUG - headers http-incoming-15 << HTTP/1.1 200 OK
    [2020-08-07 12:11:36,865] [EI-Core] DEBUG - headers http-incoming-15 << Cache-Control: no-cache
    [2020-08-07 12:11:36,866] [EI-Core] DEBUG - headers http-incoming-15 << Content-Disposition: attachment; filename="IVT000763184.pdf"
    [2020-08-07 12:11:36,866] [EI-Core] DEBUG - headers http-incoming-15 << Content-Type: application/text
    [2020-08-07 12:11:36,866] [EI-Core] DEBUG - headers http-incoming-15 << Date: Fri, 07 Aug 2020 12:11:36 GMT
    [2020-08-07 12:11:36,867] [EI-Core] DEBUG - headers http-incoming-15 << Transfer-Encoding: chunked
    [2020-08-07 12:11:36,867] [EI-Core] DEBUG - headers http-incoming-15 << Connection: keep-alive
    
    [2020-08-07 12:11:36865][EI-Core]调试-头文件http-incoming-15
    
  • 这是因为您正在使用
  • 多部分/表单数据(这有一个bug) 将其更改为:

    应用程序/x-www-form-urlencoded

    您将在日志中看到:

    [2020-08-07 12:11:36,865] [EI-Core] DEBUG - headers http-incoming-15 << HTTP/1.1 200 OK
    [2020-08-07 12:11:36,865] [EI-Core] DEBUG - headers http-incoming-15 << Cache-Control: no-cache
    [2020-08-07 12:11:36,866] [EI-Core] DEBUG - headers http-incoming-15 << Content-Disposition: attachment; filename="IVT000763184.pdf"
    [2020-08-07 12:11:36,866] [EI-Core] DEBUG - headers http-incoming-15 << Content-Type: application/text
    [2020-08-07 12:11:36,866] [EI-Core] DEBUG - headers http-incoming-15 << Date: Fri, 07 Aug 2020 12:11:36 GMT
    [2020-08-07 12:11:36,867] [EI-Core] DEBUG - headers http-incoming-15 << Transfer-Encoding: chunked
    [2020-08-07 12:11:36,867] [EI-Core] DEBUG - headers http-incoming-15 << Connection: keep-alive
    

    [2020-08-07 12:11:36865][EI-Core]调试-标题http-incoming-15 Hi@user1998820,您找到解决方案了吗?我还试图从邮递员那里获取附件名称。请看下面。您好@user1998820,您找到解决方案了吗?我还试图从邮递员那里获取附件名称。请看下面。您好@user3345547,我们如何从来自邮递员的请求中获取附件/文件名?我也在尝试类似的操作。请查看下面的Hi@user3345547,我们如何从来自邮递员的请求中获取附件/文件名?我也在尝试类似的操作。请看下面
    
     <!--                Message Formatter                   -->
     <!-- ================================================= -->
     <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="application/octet-stream"
                           class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
         <messageFormatter contentType="application/pdf"
                           class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
         <messageFormatter contentType="application/json"
                           class="org.wso2.carbon.integrator.core.json.JsonStreamFormatter"/>
         <messageFormatter contentType="text/html"
                         class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
         <messageFormatter contentType="application/file"
                          class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
     </messageFormatters>
    
     <!-- ================================================= -->
     <!--                Message Builders                   -->
     <!-- ================================================= -->
    
     <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"/>
         <messageBuilder contentType="application/octet-stream"
                         class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
         <messageBuilder contentType="text/html"
                         class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
         <messageBuilder contentType="application/json"
                         class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>
         <messageBuilder contentType="application/pdf" 
                         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="application/file"
                         class="org.apache.axis2.format.BinaryBuilder"/>
     </messageBuilders>