View Javadoc

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