Awake FILE v3.1

Quick Start


1      Development Environment. 1

2      Server Side Settings. 2

3      Client Side Settings. 3

4      From now on….. 5




1       Development Environment


Download and unzip or download and untar awake-file-3.1-bin.tar.gz.

Add the jar libraries of the /lib-client subdirectory to your IDE project or development CLASSPATH.


Or for Maven users:





2       Server Side Settings


1)    Create an awake-file-quickstart webapp on you Servlet container.


2)    Add the following lines to web.xml of the awake-file-quickstart webapp.















3)    Deploy the jar libraries of the  installation folder /lib-server subdirectory to your Servlet container webapp library folder - typically in /WEB-INF/lib. Restart your Servlet container.


For Maven users:





4)    Test you configuration in a browser with the URL: http://localhost:8080/awake-file-quickstart/ServerFileManager (assuming you test Awake on your machine with Tomcat running on default port). The status line should display OK & Running. If not, fix the displayed error and retry. That's it!



3       Client Side Settings


1)    Create an org.kawanfw.file.api.client.quickstart package in your IDE.


2)    Download this java source file: Then insert it in the package.


3)    The session to the remote server is created  using a RemoteSession.


4)    Modify if necessary the url variable in the remoteSessionBuilder() method. It must point to the ServerFileManager servlet as defined in your web.xml:



     * RemoteSession Quick Start client example. Creates an Awake RemoteSession.


     * @return the Awake Remote Session established with the remote Awake FILE

     *         server

     * @throws IOException

     *             if communication or configuration error is raised


    public static RemoteSession remoteSessionBuilder() throws IOException {


       // Path to the ServerFileManager Servlet:

       String url = "http://localhost:8080/awake-file-quickstart/ServerFileManager";


       // (usename, password) for authentication on server side.

       // No authentication will be done for our Quick Start:

       String username = "username";

       char[] password = { 'd', 'e', 'm', 'o' };


       // Establish a session with the remote server

       RemoteSession remoteSession = new RemoteSession(url, username, password);

       return remoteSession;



5)    Download the two files Koala.jpg and Tulips.jpg in your  "user.home" directory on the client side.


6)    Compile and run from your IDE the SessionExample class. It will create a remote directory, upload the two files to the server, list directories & files on the server, rename a remote file and download files from the server. Note that all operations on remote files use the same method name and signature as in



     * 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>Displays some info on a remote file.</li>

     * <li>Renames a remote file.</li>

     * <li>Downloads the files from the remote directory.</li>

     * </ul>


     * The example uses {@code RemoteFile} objects for operations on remote

     * files. The {@code RemoteFile} methods used are the same as in

     * {@code}.


     * @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;

       System.out.println("\"user.home\" is: " + userHome);


       // Create a remote directory on the server

       // RemoteFile methods are the same as methods

       System.out.println("Creating remote /mydir...");

       RemoteFile remoteDir = new RemoteFile(remoteSession, "/mydir");



       // Creating a subdirectory on the server

       System.out.println("Creating remote /mydir/subdir...");

       RemoteFile remoteSubdir = new RemoteFile(remoteSession, "/mydir/subdir");



       // Upload two files Koala.jpg and Tulips.jpg file located in our

       // user.home directory to the remote directory /mydir

       File image1 = new File(userHome + "Koala.jpg");

       File image2 = new File(userHome + "Tulips.jpg");


       System.out.println("Uploading " + userHome

             + " files to remote /mydir...");

       remoteSession.upload(image1, "/mydir/Koala.jpg");

       remoteSession.upload(image2, "/mydir/Tulips.jpg");


       // List all files located in remote directory /mydir

       RemoteFile[] remoteFiles = remoteDir.listFiles();


       System.out.println("All files located in " + remoteDir + "     : "

             + Arrays.asList(remoteFiles));


       // List subdirectories only of remote directory /mydir

       // Uses an Apache Commons IO FilterFilter

       FileFilter fileFilter = DirectoryFileFilter.DIRECTORY;


       remoteFiles = remoteDir.listFiles(fileFilter);

       System.out.println("Subdirectories of " + remoteDir + ": "

             + Arrays.asList(remoteFiles));


       RemoteFile koala = new RemoteFile(remoteSession, "/mydir/Koala.jpg");


       System.out.println("Display remote " + koala + " info...");

       System.out.println("last modified: " + new Date(koala.lastModified()));

       System.out.println("length       : " + koala.length());

       System.out.println("Parent       : " + koala.getParent());


       // Rename a file on server


       RemoteFile koalaRenamed = new RemoteFile(remoteSession,


       System.out.println("Renaming " + koala + " to " + koalaRenamed + "...");

       boolean renameDone = koala.renameTo(koalaRenamed);

       System.out.println("Rename done: " + renameDone);


       // Download the files - with a new name - in our user.home directory

       File downloadedImage1 = new File(userHome + "downloaded-Koala.jpg");

       File downloadedImage2 = new File(userHome + "downloaded-Tulips.jpg");



       System.out.println("Downloading files from remote /mydir in "

             + userHome + "...");"/mydir/Koala_RENAMED.jpg", downloadedImage1);"/mydir/Tulips.jpg", downloadedImage2);






Note that the root of the file server for the demo user will be located in the following directory:





user.home: value of System.getProperty("user.home") of your Servlet container.


This default server configuration is of course modifiable.



4       From now on…


You can read the Tutorial or run through the Javadoc.


You will learn :