我只想在http:request中发送附件。因此,我准备了以下流程。
<flow name="http-request-payload-multipart-preparator">
<http:listener config-ref="GlobalHTTPConnector" path="/requestmultipartprep" doc:name="HTTP"/>
<expression-component doc:name="Expression"><![CDATA[
ds = new org.mule.message.ds.StringDataSource('key1','value1','text/plain');
dh = new javax.activation.DataHandler(ds);
message.outboundAttachments['key1'] = dh;
ds = new org.mule.message.ds.StringDataSource('key2','value2','text/plain');
dh = new javax.activation.DataHandler(ds);
message.outboundAttachments['key2'] = dh;]]></expression-component>
<set-payload value="#[null]" />
<http:request config-ref="HTTP_Request_Configuration" path="/simplemultiparthandler" method="POST" doc:name="HTTP"/>
</flow>
<flow name="sile-multipart-handler">
<http:listener config-ref="GlobalHTTPConnector" path="/simplemultiparthandler" doc:name="HTTP"/>
<logger level="INFO" message="#[message.inboundAttachments.keySet().toString()]" />
<logger level="INFO" message="#[message.inboundAttachments.'key1'.dataSource.name]" doc:name="Payload Logger"/>
<logger level="INFO" message="#[message.inboundAttachments.'key1'.dataSource.content]" doc:name="Payload Logger"/>
<logger level="INFO" message="#[message.inboundAttachments.'key2'.dataSource.name]" doc:name="Payload Logger"/>
<logger level="INFO" message="#[message.inboundAttachments.'key2'.dataSource.content]" doc:name="Payload Logger"/>
<set-payload value="baba sai" />
</flow>
这在mule 3.7中工作正常。在这里,我可以看到我有两个附件名称&#39; key1&#39;和&#39; key2&#39;分别。 但如果我在mule 3.5中用http:outbound-endpoint做同样的事情我无法获得密钥。它显示附件名称是&#39; value1&#39;和&#39; value2&#39;分别。
为什么这样做?
为了完成这项工作,我在3.5中更改了以下代码。我交换了密钥和值名称。
<flow name="http-request-payload-multipart-preparator">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9876" path="requestmultipart" connector-ref="NoSessionEncodingConnector" doc:name="HTTP" />
<expression-component doc:name="Expression"><![CDATA[
ds = new org.mule.message.ds.StringDataSource('value1','key1','text/plain');
dh = new javax.activation.DataHandler(ds);
message.outboundAttachments['key1'] = dh;
ds = new org.mule.message.ds.StringDataSource('value2','key2','text/plain');
dh = new javax.activation.DataHandler(ds);
message.outboundAttachments['key2'] = dh;
payload;]]></expression-component>
<set-payload value="#[null]" />
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="9876" method="POST" doc:name="HTTP" path="simplemultiparthandler" connector-ref="NoSessionEncodingConnector" />
</flow>
<flow name="sile-multipart-handler">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9876" path="simplemultiparthandler" connector-ref="NoSessionEncodingConnector" doc:name="HTTP" />
<logger level="INFO" message="#[message.inboundAttachments.keySet().toString()]" />
<logger level="INFO" message="#[message.inboundAttachments.'key1'.dataSource.name]" doc:name="Payload Logger"/>
<logger level="INFO" message="#[message.inboundAttachments.'key1'.dataSource.inputStream]" doc:name="Payload Logger"/>
<logger level="INFO" message="#[message.inboundAttachments.'key2'.dataSource.name]" doc:name="Payload Logger"/>
<logger level="INFO" message="#[message.inboundAttachments.'key2'.dataSource.inputStream]" doc:name="Payload Logger"/>
</flow>
为什么在3.5和3.7中存在差异?
答案 0 :(得分:1)
3.7的HTTP连接器完全重写了3.5及更早版本的HTTP传输。
附件支持在旧的传输中一直存在问题所以我认为MuleSoft决定在构建新连接器时解决问题。