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文件名 –