私はAnypoint Studio 6.2とMule Runtime 3.8.3を使用しています。Mule Javaトランスのペイロードにzipファイルを渡すにはどうしたらいいですか?
src/main/resources/inputフォルダ内のファイルを取り出し、圧縮してsrc/main/resources/outputに保存し、メッセージペイロードをzipファイルに置き換えます。
これを行うには、ファイルを圧縮して出力フォルダに保存するZipというJavaクラスを参照するJavaトランスフォーマを追加しましたが、新しく作成したzipファイルをメッセージのペイロードに追加する方法はありますか?
のJavaジップクラス:
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ファイル名 –