0
我使用Anypoint Studio 6.2和Mule Runtime 3.8.3。如何將zip文件傳遞給Mule java變壓器中的有效載荷?
我想在src/main/resources/input文件夾中取一個文件,並將其壓縮並保存到src/main/resources/output,然後用zip文件替換消息有效負載。
要做到這一點,我已經添加了一個java變壓器,它引用了一個java類,我稱之爲zip,它將文件壓縮並保存到輸出文件夾,但是如何將新創建的zip文件添加到消息的有效負載中?
爪哇郵編類:
public class Zip extends AbstractMessageTransformer
{
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
System.out.print("***java.utils.Zip started***");
String sourceFile = "src/main/resources/input/log4j2.xml";
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream("src/main/resources/output/log4j2.zip");
ZipOutputStream zipOut = new ZipOutputStream(fos);
File fileToZip = new File(sourceFile);
fis = new FileInputStream(fileToZip);
ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
zipOut.putNextEntry(zipEntry);
final byte[] bytes = new byte[1024];
int length;
while((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
message.setPayload(????);
zipOut.close();
fis.close();
fos.close();
} catch (FileNotFoundException e) {
//File not found
e.printStackTrace();
} catch (IOException e) {
//IO Exception
e.printStackTrace();
}
System.out.print("***java.utils.Zip completed***");
return message;
}
}
由於
我可以在物理文件添加到有效載荷或可我只加了位置?謝謝 – user3165854
添加位置+ zip文件名 –