2017-10-12 5 views
0

私は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; 
    } 
} 

おかげ

答えて

0

message.setPayload( 'SRC /メイン/リソース/出力/ log4j2.zip');

これで、参照可能なペイロードにzipファイルの場所があります。

または、zipファイルパスを使用してプロパティ呼び出しを作成し、これをセットペイロードコンポーネントで使用できます。

message.setProperty( "test"、 "src/main/resources/output/log4j2.zip"、PropertyScope.INVOCATION);セットのペイロードで

#[flowVars.test]

+0

私は物理的にペイロードにファイルを追加することができたり、私が唯一の場所を追加することができますので、これは使用することができますか?ありがとう – user3165854

+0

場所を追加+ zipファイル名 –

関連する問題