我正在尝试将带有文件和两个输入的表单发送到Mule入站端点。我有一个自定义处理器,并且定义了这样的流程:
<custom-processor class="informa.app.classifier.transformers.MyfileUploadProcessor" name="fileuploadprocessor"></custom-processor>
<flow name="httpTest">
<http:inbound-endpoint
address="http://tango.privada.informa:11002/services/fileupload"></http:inbound-endpoint>
<processor ref="fileuploadprocessor"/>
</flow>
在MyfileUploadProcessor类中:
public class MyfileUploadProcessor实现MessageProcessor {
@Override
public MuleEvent process(MuleEvent event) throws MuleException {
// TODO Auto-generated method stub
String response = "success";
MuleMessage mulemessage = event.getMessage();
String countryCode = mulemessage.getInboundProperty("username");
String sourceCode = mulemessage.getInboundProperty("password");
InputStream input = (InputStream) mulemessage.getPayload();
...
要测试一个简单的html:
<form action="http://tango.privada.informa:11002/services/fileupload" method="post"
enctype="multipart/form-data">
<p>Country Code :<input type="text" name="username" /></p>
<p>Source Code :<input type="text" name="password" /></p>
<p>File :<input type="file" name="payload" /></p>
<p><input type="submit" name="submit" value="submit" />
<input type="reset" name="reset" value="reset"></p>
</form>
</body>
</html>
问题是我无法从mulemessage的有效负载创建文件,我不知道如何获取表单中输入的值...我做错了什么?任何线索?
提前致谢
答案 0 :(得分:3)
您需要配置HTTP连接器以使用org.mule.transport.http.HttpMultipartMuleMessageFactory
来处理multipart/form-data
HTTP POST。
为此,请在配置中添加以下内容:
<http:connector name="httpConnector">
<service-overrides messageFactory="org.mule.transport.http.HttpMultipartMuleMessageFactory"/>
</http:connector>
有了这个,payload
表单字段将成为Mule消息的流有效负载,所有其他字段值将在入站附件中(任何部分标题将在入站标题)。
答案 1 :(得分:1)
大卫给出了很好的回答(对我来说是一个救生员!大卫大卫) 为什么值得一些额外的项目,我一开始没有意识到httpConnector必须用作http传输参考,完整的流程将是
<http:connector name="httpConnector" doc:name="HTTP\HTTPS">
<service-overrides
messageFactory="org.mule.transport.http.HttpMultipartMuleMessageFactory" />
</http:connector>
<flow name="AttachmentTestFlow1" doc:name="AttachmentTestFlow1">
<http:inbound-endpoint connector-ref="httpConnector" doc:name="HTTP" exchange-pattern="request-response" host="localhost" port="8081"/>
<component class="ProcessAttachment" doc:name="Java" />
</flow>
我能够使用jmeter上传两个附件,第一个
然后可以通过正常的骡子流或组件来处理
public String process(@Payload String payload, @InboundAttachments("*") Map<String, DataHandler> headers ) throws IOException{
InputStream in = headers.get("attachment").getDataSource().getInputStream();