从HTML页面将文件上载到Mule(http连接器)

时间:2014-11-07 06:41:27

标签: html xml mule

我正在尝试将HTML文件从HTML页面上传到Mule-3.5(CE)。在Mule中,我无法检索文件的内容。我附加了HTML和Mule配置xml。我希望有人能帮助我解决这个问题。



<html>
<body>
<form action="http://localhost:8081" method="post" enctype="text/xml" >
INVOIC IDOC File:<input type="file" name="uploadedFile" size="40"  accept=".xml" />  
  <input type="submit" name="Submit" id="button" value="Send" />

</form>
</body>
</html>
&#13;
&#13;
&#13;

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:connector name="HTTP_HTTPS" enableCookies="true" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP-HTTPS">
    <reconnect/>
</http:connector>
<flow name="httpconnectorFlow1" doc:name="httpconnectorFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" connector-ref="HTTP_HTTPS"/>
    <echo-component doc:name="Echo"/>
</flow>
</mule>
&#13;
&#13;
&#13;

Mule脚本只是对HTTP连接器的测试。我正在搜索提取上传文件内容的方法。

1 个答案:

答案 0 :(得分:1)

你可以用它来搞定事情。我在HTML中更改的是enctype和文件输入的名称。

<html>
<body>
    <form action="http://localhost:8081" method="post" enctype="multipart/form-data" >
       INVOIC IDOC File:<input type="file" name="payload" size="40"  accept=".xml" />  
       <input type="submit" name="Submit" id="button" value="Send" />
    </form>
</body>
</html>

对于Mule部分,您可以将HttpMultipartMuleMessageFactory用于HTTP连接器。这使您可以接收多部分/表单数据。由于文件输入被称为有效载荷,因此它将是mule消息的有效载荷,它将是流式有效载荷。

下面是一个样本mule流,用于接收mule中的xml并记录有效负载。我使用一个简单的对象到字符串转换器来读取流。

<http:connector name="HTTP" doc:name="HTTP">
   <service-overrides messageFactory="org.mule.transport.http.HttpMultipartMuleMessageFactory" />
</http:connector>

<flow name="http-xml-receive-flow" doc:name="http-xml-receive-flow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
      <object-to-string-transformer doc:name="Object to String"/>
      <logger message="#[message.payload]" doc:name="Logger" level="INFO"/>
</flow>

如果您打算包含其他表单输入,则它们将作为mule消息上的inboundAttachments提供。