We are currently using WSO EI 6.4 as ESB.
We made the configuration to get the behaviour "Binary Passthrough" in axis2.xml for one carbon application
<messageBuilder contentType="multipart/form-data" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
<messageFormatter contentType="multipart/form-data" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
But now, we need to develop a new carbon application who need to create a multipart message. and so we need to change the configuration to, as decribed in this article
<messageBuilder contentType="multipart/form-data" class="org.apache.axis2.builder.MultipartFormDataBuilder" />
<messageFormatter contentType="multipart/form-data" class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
But if we do that, we will lose the "Binary Passthrough" adn broke the first carbon app.
Is there a possiblitiy to override the messageBuilder and messageFormatter just for one carbon application?
Thank you
With the help of @tmoasz i was able to solve this issue. Here the full solution
<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 for test
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=="
}'
Multipart Generated
--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--
Maybe the BuilderMediator
can do that, what you would to achieve.
Checkout this: Builder+Mediator documentation.