我正在研究骡子流并遇到困难
要求:
答案 0 :(得分:1)
我对你所描述的要求,GZip压缩的使用以及流动截图感到困惑。
您的要求表明您将要加载Zip存档(文件),这与GZip流非常不同 - GZip连接器在这里不会帮助您。 GZip只是压缩一个字节流,它没有多个文件/文件夹的概念 - 这就是为什么在* nix世界中它通常与Tar结合(即Tar将许多文件连接到一个未压缩的存档中,那个档案然后是GZip)。 Zip基本上结合了这两者 - 存档和压缩。
此外,您的屏幕截图显示了HTTP入站端点 - 因此我假设该文件正在发布给您。 #[message.inboundProperties.originalFileName]
仅由文件入站端点设置,这就是您不会看到它的原因。您也没有提到您将使用的内容类型。我见过的最常见的用例是multipart/form-data
- 如果您正在使用它,那么您可以通过Mule的inboundAttachments
地图访问该文件及其名称。
如果我对您正在做的事情的理解是正确的,以下是我将如何实现它的示例(为简洁起见,错误检查/处理被删除):
来源:
<flow name="sampleFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/zip" allowedMethods="POST" doc:name="HTTP"/>
<foreach collection="#[message.inboundAttachments]" doc:name="For Each Attachment (There could be more than 1)">
<scripting:component doc:name="Groovy - examine attachment and set vars">
<scripting:script engine="Groovy"><![CDATA[import java.io.*;
import java.util.zip.*;
// should be application/zip - could valudate
flowVars.type = payload.dataSource.contentType;
// datasource will be HttpPartDataSource
flowVars.partName = payload.dataSource.part.name;
flowVars.filename = payload.dataSource.part.fileName;
flowVars.filesInZip = new java.util.ArrayList();
payload = payload.dataSource.content;
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(payload));
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null)
flowVars.filesInZip.add(ze.name);
zis.close();
return payload;
]]></scripting:script>
</scripting:component>
<ftp:outbound-endpoint host="localhost" port="21" path="/dest" passive="true" outputPattern="#[flowVars.filename]" responseTimeout="10000" doc:name="FTP"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-session-variable variableName="results"><![CDATA[%dw 1.0
%output application/java
---
(sessionVars.results default []) ++ [{
partName: flowVars.partName,
fileName: flowVars.filename,
filesInZip: flowVars.filesInZip joinBy ', '
}]
]]></dw:set-session-variable>
</dw:transform-message>
</foreach>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
sessionVars.results
]]></dw:set-payload>
</dw:transform-message>
</flow>
邮差样本电话:
输出:
[
{
"partName": "zip2",
"fileName": "OC.zip",
"filesInZip": "OC/staging/, OC/staging/b2b-test/, OC/staging/Madrid/, OC/staging/Madrid/B1805259-1527220273.txt, OC/staging/Madrid/B1805259-1527221226.txt, OC/staging/Madrid/B1805259-1527226248.txt, OC/staging/Madrid/B1805259-1527226249.txt, OC/staging/Madrid/B1805259-1527226475.txt, OC/staging/Madrid/B1805259-1527226476.txt, OC/staging/Madrid/B1805299-1527544507.txt, OC/staging/Madrid/B1805299-1527545678.txt, OC/staging/Madrid/B1805299-1527545679.txt, OC/staging/Madrid/B1805299-1527548307.txt, OC/staging/Madrid/B1805299-1527550180.txt, OC/staging/Madrid/B1805299-1527553547.txt, OC/staging/Madrid/B1805299-1527553548.txt"
},
{
"partName": "zip1",
"fileName": "FirstZipFile.zip",
"filesInZip": "LogitechWebcamFix.log, BGChanger.log"
}
]