Flow獲取http請求,java組件創建zip文件並返回。壓縮文件得到下載,但當我解壓縮時,我得到錯誤說'壓縮文件夾無效'。 java在臨時位置創建的臨時zip工作正常。問題是如何將zip文件設置爲有效內容?Mule ESB:java組件提供zip文件但無法解壓
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage message = eventContext.getMessage();
message.setOutboundProperty("Content-type", "application/zip");
message.setOutboundProperty("Content-Disposition", "attachment;filename=\"my_Logs.zip\"");
File tempZip = File.createTempFile("LOGS", ".zip");
FileOutputStream fos = new FileOutputStream(tempZip);
ZipOutputStream zipOut = new ZipOutputStream(fos);
File logDir = new File("C:/Temp/logs");
zipOut.setMethod(ZipOutputStream.DEFLATED);
zipOut.setLevel(9);
FileInputStream in =null;
int len =0;
byte[] buf = new byte[1024];
for(File file : logDir.listFiles()){
String filename = file.getName();
in = new FileInputStream(file);
zipOut.putNextEntry(new ZipEntry(filename));
while ((len = in.read(buf))>0){
zipOut.write(buf,0,len);
}
zipOut.closeEntry();
in.close();
}
zipOut.close();
message.setPayload(tempZip);
return message;
}
流量
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="httppayloadFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="*" doc:name="HTTP"/>
<message-filter doc:name="Filter favicon">
<not-filter>
<wildcard-filter pattern="/favicon.ico" caseSensitive="true"/>
</not-filter>
</message-filter>
<component class="com.home.zipper.ZipLogs" doc:name="Java"/>
</flow>
我在做什麼錯在這裏?感謝任何幫助