WSO2 多部分二进制传递和 MultipartFormData

问题描述 投票:0回答:1

我们目前使用 WSO EI 6.4 作为 ESB。

我们进行了配置,以在 axis2.xml 中为一个 Carbon 应用程序获取“二进制传递”行为

<messageBuilder     contentType="multipart/form-data"   class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
<messageFormatter   contentType="multipart/form-data"   class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>

但是现在,我们需要开发一个新的碳应用程序,它需要创建多部分消息。 因此我们需要将配置更改为,如本文

中所述
<messageBuilder     contentType="multipart/form-data"   class="org.apache.axis2.builder.MultipartFormDataBuilder" />
<messageFormatter   contentType="multipart/form-data"   class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>

但是如果我们这样做,我们将失去“二进制直通”并破坏第一个碳应用程序。

是否有可能仅针对一个 Carbon 应用程序覆盖 messageBuilder 和 messageFormatter?

谢谢你


解决方案

在@tmoasz 的帮助下我能够解决这个问题。 完整解决方案在这里

<inSequence>

      <!--Extract value from Json-->
      <property name="Data1" expression="json-eval($.Data1)"/>
      <property name="Data2" expression="json-eval($.Data2)"/>
      <property name="File1" expression="json-eval($.File1)"/>

      <!-- remove body and set MessageBuilder
        if body not removed, MultipartFormDataFormatter is not call
      -->
      <script language="js">
        mc.getEnvelope().getBody().getFirstElement().detach();
      </script>
      <builder>
        <messageBuilder contentType="multipart/form-data"
          class="org.apache.axis2.builder.MultipartFormDataBuilder"
          formatterClass="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
      </builder>

      <payloadFactory media-type="xml">
        <format>
          <root xmlns="">
            <metadata xmlns="http://org.apache.axis2/xsd/form-data"
              filename="key1"
              name="key1">$1</metadata>
            <!-- content is decode from base64-->
            <file xmlns="http://org.apache.axis2/xsd/form-data"
              filename="file1.1"
              name="file1.1"
              content-type="application/xml">$3</file>
            <!-- content is not changed-->
            <metadata xmlns="http://org.apache.axis2/xsd/form-data"
              name="file1.2"
              filename="file1.2"
              content-type="application/xml">$3</metadata>
          </root>
        </format>
        <args>
          <arg expression="get-property('Data1')"/>
          <arg expression="get-property('Data2')"/>
          <arg expression="get-property('File1')"/>
        </args>
      </payloadFactory>

            <!--set messageType to trigger multiPart Formater -->
            <property name="messageType"  scope="axis2" type="STRING" value="multipart/form-data"/>
            <!--remove ContentType to force generate header content-type with boundary information -->
            <property name="ContentType" scope="axis2" action="remove"/>

      <send>
        <endpoint>
          <http method="post" uri-template="http://127.0.0.1:3000/mulitPart/wso2">
            <suspendOnFailure>
              <initialDuration>-1</initialDuration>
              <progressionFactor>-1</progressionFactor>
              <maximumDuration>0</maximumDuration>
            </suspendOnFailure>
            <markForSuspension>
              <retriesBeforeSuspension>0</retriesBeforeSuspension>
            </markForSuspension>
          </http>
        </endpoint>
      </send>


    </inSequence>

卷曲测试

curl --location --request POST 'http://127.0.0.1:8280/outgoing-mail' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Data1": "Value1",
    "Data2": "Value2",
    "File1" :  "PHhtbD4gICAKICAgIDxoZWxsbz5TdGFjazwvaGVsbG8+CjwveG1sPg=="
}'

生成多部分

--MIMEBoundary_dfa6d9a4ea9eee573969c1fae03dd6667159a66375689ec7
Content-Disposition: form-data; name="key1"; filename="key1"
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: binary

Value1
--MIMEBoundary_dfa6d9a4ea9eee573969c1fae03dd6667159a66375689ec7
Content-Disposition: form-data; name="file1.1"; filename="file1.1"
Content-Type: application/pdf; charset=ISO-8859-1
Content-Transfer-Encoding: binary

<xml>   
    <hello>Stack</hello>
</xml>
--MIMEBoundary_dfa6d9a4ea9eee573969c1fae03dd6667159a66375689ec7
Content-Disposition: form-data; name="file1.2"; filename="file1.2"
Content-Type: application/pdf; charset=ISO-8859-1
Content-Transfer-Encoding: binary

PHhtbD4gICAKICAgIDxoZWxsbz5TdGFjazwvaGVsbG8+CjwveG1sPg==
--MIMEBoundary_dfa6d9a4ea9eee573969c1fae03dd6667159a66375689ec7--
wso2 multipartform-data wso2-enterprise-integrator wso2-esb
1个回答
1
投票

也许

BuilderMediator
可以做到你想要实现的目标。 查看此:Builder+Mediator 文档。

© www.soinside.com 2019 - 2024. All rights reserved.