View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.ftp.server;
8   
9   import java.io.IOException;
10  
11  import org.apache.ftpserver.ftplet.DefaultFtplet;
12  import org.apache.ftpserver.ftplet.FtpException;
13  import org.apache.ftpserver.ftplet.FtpRequest;
14  import org.apache.ftpserver.ftplet.FtpSession;
15  import org.apache.ftpserver.ftplet.Ftplet;
16  import org.apache.ftpserver.ftplet.FtpletResult;
17  
18  /**
19   * {@link Ftplet} implementation that calls methods on its callback. Although this seems a bit 
20   * like jumping through hoops, it frees the individual test classes from having to deal with
21   * creating custom Ftplets.
22   */
23  public class MuleFtplet extends DefaultFtplet
24  {
25      public interface Callback
26      {
27          void fileUploadCompleted();
28          
29          void fileMoveCompleted();
30      }
31  
32      private Callback callback;
33      
34      public MuleFtplet(Callback callback)
35      {
36          super();
37          this.callback = callback;
38      }
39      
40      @Override
41      public FtpletResult onUploadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException
42      {
43          callback.fileUploadCompleted();
44          return null;
45      }
46  
47      @Override
48      public FtpletResult onRenameEnd(FtpSession session, FtpRequest request) throws FtpException, IOException
49      {
50          callback.fileMoveCompleted();
51          return null;
52      }
53  }