title: Mule Zip File and send zipped file towards FTP server
body: <p>I know Mule has great support for gzip compression of data using the  element. However the client now wants zip compression since the file has to be placed on an FTP as a zip compressed file :(</p>
  
  <p>I encounter difficulties in mule with following scenario:</p>
  
  <p>I created a Spring bean where a file comes in. I want to compress this file using the ZipOutputStream class and pass it towards our ftp.</p>
  
  <p>This is my flow configuration:</p>
  
  <pre><code>&lt;flow name="testFlow" initialState="stopped"&gt;
      &lt;file:inbound-endpoint path="${home.dir}/out" moveToDirectory="${hip.dir}/out/hist" fileAge="10000" responseTimeout="10000" connector-ref="input"/&gt;
      &lt;component&gt;
          &lt;spring-object bean="zipCompressor"/&gt;
      &lt;/component&gt;
      &lt;set-variable value="#[message.inboundProperties.originalFilename]" variableName="originalFilename" /&gt;
      &lt;ftp:outbound-endpoint  host="${ftp.host}" port="${ftp.port}" user="${ftp.username}" password="${ftp.password}" path="${ftp.root.out}" outputPattern="#[flowVars['originalFilename']].zip" /&gt;
  &lt;/flow&gt;
  </code></pre>
  
  <p>This is the code of my zipCompressor:</p>
  
  <pre><code>@Component
  public class ZipCompressor implements Callable {
  
      private static final Logger LOG = LogManager.getLogger(ZipCompressor.class.getName());
  
      @Override
      @Transactional
      public Object onCall(MuleEventContext eventContext)  throws Exception {
  
          if (eventContext.getMessage().getPayload() instanceof File) {
              final File srcFile = (File) eventContext.getMessage().getPayload();
              final String fileName = srcFile.getName();
              final File zipFile = new File(fileName + ".zip");
  
              try {
  
                  // create byte buffer
                  byte[] buffer = new byte[1024];
                  FileOutputStream fos = new FileOutputStream(zipFile);
                  ZipOutputStream zos = new ZipOutputStream(fos);
                  FileInputStream fis = new FileInputStream(srcFile);
                  // begin writing a new ZIP entry, positions the stream to the start of the entry data
                  zos.putNextEntry(new ZipEntry(srcFile.getName()));
                  int length;
                  while ((length = fis.read(buffer)) &gt; 0) {
                      zos.write(buffer, 0, length);
                  }
                  zos.closeEntry();
                  // close the InputStream
                  fis.close();
                  // close the ZipOutputStream
                  zos.close();
              }
              catch (IOException ioe) {
                  LOG.error("Error creating zip file" + ioe);
              }
              eventContext.getMessage().setPayload(zipFile);
          }
          return eventContext.getMessage();
       }
   }
  </code></pre>
  
  <p>I wrote a unit test and the compression works great. A file is indeed transferred to the FTP with the correct name, but the zip file is invalid and by opening it in NotePad++, it contains just the original file name.</p>
  
  <p>I think I'm doing something wrong with passing the zip file back to the mule flow, but I'm stuck at the moment so any help would be greatly appreciated!</p>