Founder & CEO of KawanSoft. We are a french privately held company located in Paris and specialize in Swing, Java EE and client-server developments. We developp and support the OSS Awake Framework that allows file tranfers and JDBC calls through HTTP. Nicolas has posted 5 posts at DZone. You can read more from them at their website. View Full User Profile

Awake File: access remote files securely from Desktop Apps

05.30.2012
| 2437 views |
  • submit to reddit
Location: 
Software

Awake File is a secure Open Source framework which enables developers to very easily implement file uploads and downloads through HTTP.
 
Security has been taken into account from the design stage: server side configuration allows to specify strong security rules in order to protect the files. 
 
Awake File is licensed through the GNU Lesser General Public License (LGPL v2.1).

Awake Architecture 

Why Awake File?

Why is it so complicated with Java to access files on a remote Java server/container ?

For example, why is it so complicated to code the upload of a file from a PC Desktop to a remote Tomcat or other JavaEE server for treatment by a Servlet? Java developers have no easy built in APIs or tools to handle this. There is the solution to set up a FTP server but it’s cumbersome: it requires amendments to security rules and new developments to link the uploaded file to Tomcat or or other JavaEE server. Another solution is to use client and server libraries (Apache Commons HttpClient, FileUpload, etc.), but you have to write, test and maintain the code, define the security rules, handle proxy considerations, manage the errors, etc. 
 
Awake File is our attempt to offer an easy solution for: 

  • Uploading files to a remote server.
  • Downloading files from a remote server.
  • Listing remote directories.
  • Creating/deleting remote directories. 
  • Calling a remote java method without complicated setup. 
  • Defining strong security rules for all these operations. 
  • Displaying nice progress indicators to your users during uploads & downloads.

 

Example

    /**
     * Do some Awake File operations. This example:
     * <ul>
     * <li>Creates a remote directory.</li>
     * <li>Uploads two files to the remote directory.</li>
     * <li>Lists the content of the remote directory.</li>
     * <li>Downloads the files of the remote directory.</li>
     * </ul>
     *
     * @throws IOException
     *             if communication or configuration error is raised
     */
    public void doIt() throws IOException {
 
      // Define userHome var
      String userHome = System.getProperty("user.home") + File.separator;
 
      // Create an AwakeFile instance and username on the remote server
      // using the URL of the path to the AwakeFileManager Servlet
      String url = "https://www.acme.org/AwakeFileManager";

      // The login info for strong authentication on server side:
      String username = "myUsername";
      char[] password = { 'm', 'y', 'P', 'a', 's', 's', 'w', 'o', 'r', 'd' };

      // Create the Awake File Session to the remote Tomcat or JavaEE server:
      AwakeFileSession awakeFileSession = new AwakeFileSession(url, username,
            password);

      // Create a remote directory on the server:
      awakeFileSession.mkdirs("/mydir");
 
      // Upload two files image-1.jpg and image-2.jpg file located in our
      // user.home directory to the remote directory /mydir
      File image1 = new File(userHome + "image-1.jpg");
      File image2 = new File(userHome + "image-2.jpg");
 
      awakeFileSession.upload(image1, "/mydir/image-1.jpg");
      awakeFileSession.upload(image2, "/mydir/image-2.jpg");
 
      // List the subdirectories of our virtual server
      List<String> remoteDirs = awakeFileSession.listDirectories("/");
      System.out.println("directories located in /: " + remoteDirs);
 
      // List the files located in remote directory /mydir
      List<String> remoteFiles = awakeFileSession.listFiles("/mydir");
      System.out.println("files located in /mydir: " + remoteFiles);
 
      // Download the files - with a new name - in our user.home directory
      File downloadedImage1 = new File(userHome + "downloaded-image-1.jpg");
      File downloadedImage2 = new File(userHome + "downloaded-image-2.jpg");
 
      awakeFileSession.download("/mydir/image-1.jpg", downloadedImage1);
      awakeFileSession.download("/mydir/image-2.jpg", downloadedImage2);
 
      System.out.println("done!");
    }

 

Documentation, Tutorial, Source Code & Binaries

Please visit http://www.awake-file.org 

We will be very happy to have your comments and reviews!


 
0
Published at DZone with permission of its author, Nicolas De Pomereu.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)