Vaadin with Amazon Web service java sdk

Hi All,
i am developing a web application with vaadin 6.8 and aws java sdk jars.
When i try to upload large files to s3 buckets using TransferManager class in the vaadin portlet,after some time my application is showing communication error.
Thanks in advance.

Wild guess, either browser or front proxy interrupts a long lasting request? You could try spawning a thread to do the file upload and e.g. show a ProgressIndicator during the process.

cheers,
matti

Thank you for your reply.
Actually in my project i need to store videos in Amazon Web Service buckets using vaadin 6.8 as portlet in Liferay.
So first i am uploading video file to a temp location in my server it is working fine then after i am transferring this file from temp location to s3 bucket using the AWS java sdk jars. In AWS , TransferManger class will do the transfer process while doing, this class blocks or place the all other threads in Queue till transfer Completes and it wont allow a component to display while this class work is going on. for example: i used indicator to see the progress but unfortunatly indicator is not showing. I think in background the indicator is working but not showing on the UI
I thought that these things are happening in vaadin because of Transfer Manager class of AWS.

Thank you in advance

Hi,

I checked the TransferManager javadocs, and it seems to be asynchronous, so no sepearate thread should be needed. But I think the ProgressIndicator is a must have if you have large files. Withouth seeing your code, it is pretty hard to say what is going wrong. Are you updating the progress from TransferManager listener? Then you should synchronize over you vaadin application instance.

cheers,
matti

Thank you
Yes i am updating the progress indicator and tried with setting the value of label also ,but it is not showing the progress while uploading.After completion of upload it is showing the Label or indicator
Code:
TransferManager transfer =new TransferManager(…);
com.amazonaws.services.s3.transfer.Upload s3Upload;
Label fileUploadedLabel = new Label();
fileUploadedLabel.setImmediate(true);
layout.addComponent(fileUploadedLabel);
ProgressListener progressListener = new ProgressListener() {
public void progressChanged(ProgressEvent progressEvent) {
fileUploadedLabel.setValue(s3Upload.getProgress().getPercentTransferred() + “%”);
System.out.println("Progress: " + s3Upload.getProgress().getPercentTransferred() + “%”);
}
};
s3Upload = transfer.upload(bucketName,folderName + fileName, file);
s3Upload.addProgressListener(progressListener);
s3Upload.waitForCompletion();

===============
in console the progress of uploading is printing but not updating the label value in the UI

And i tried in vaadin using (AWT) jframe components with progress bar inside jframe and panel.It is showing the progress while uploading to s3 but these components are standalone wherever uploading files it is showing progress in my system.So this is not correct

Hi,

Because of waitForCompletion() call your UI is not rendered until the actuall upload is completed. Here is a meta code how you should do it (I wrote it diretcly into here without compiling so migth contain some mistakes/missing parts):

        ProgressIndicator pi = new ProgressIndicator();
        pi.setPollingInterval(1000);
        // add the progress indicator somewhere to your UI,
        // if you want the UI to be blocked, use modal Window whre you 
        // place the indicator
        layout.addComponent(pi);
        
        // hook s3 progress listener & start the upload
        
        final Application application = getApplication();
        new Thread(){

            @Override
            public void run() {
                // blocking method call, needs to be run in separate process
                s3Upload.waitForCompletion();
                // Once completed, you can update the UI again, not UI thread
                // so synchronize manually
                synchronized(application) {
                    layout.removeComponent(pi);
                }
            }
        }.start();

Thank you
I used waitForCompletion() to stop the control flow till the upload completes because after uploading i need to get url of that uploaded objects and i need to sync into the liferay bookmarks.
s3Upload.waitForCompletion();
long folderId = getFolderId(folderName); //getting the id from object metadata
String url = getUrl(folderName + fileName);// getting the presigned Url from the uploaded object
Map<String, String> userData = addBookmarkEntry(folderId,url.toString(), fileName, folderName);//adding to bookmark
i need to update metadata to uploaded object. This metadata contains entry id and folderid of object in the liferay bookmarks
How can i achieve this requirement.
Thank you once again

Do that inside the synchronized block in the spawned thread.

cheers,
matti

can i do upload process inside thread or out side
Plz give me sample code

    final Application application = getApplication();
   transfer.upload(--,--,--,--);
    new Thread(){
        @Override
        public void run() {
            // can i write upload logic here
            s3Upload.waitForCompletion();
            // Once completed, you can update the UI again, not UI thread
            // so synchronize manually
            synchronized(application) {
                layout.removeComponent(pi);
            }
        }
    }.start();

Yes, attaching progress listener, starting the upload etc. should happen outside the thread, just the blocking waitForCompletion call and logic that should happen after the complection should go into the thread.

I can’t write all Vaadin apps in the world, but I’ll consider writing an article about the topic. Not strictly about s3 uploads, but “concurrency essentials for UI developers” and large s3upload could be one example.

cheers,
matti

You really did great work
Thank you alot and awesome feeling by seeing this solution
I am very very very thankfull for providing solution

Cheers.