Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Store files on server with the RemoteFileService
Store files on server with the RemoteFileService [message #1077379] Thu, 01 August 2013 12:06 Go to next message
Mirjam B. is currently offline Mirjam B.
Messages: 8
Registered: June 2013
Junior Member
Hi, is there any way to use the RemoteFileService for creating files on a server (Tomcat)?
I appreciate any idea Smile
Re: Store files on server with the RemoteFileService [message #1091701 is a reply to message #1077379] Wed, 21 August 2013 17:47 Go to previous message
Lukas Huser is currently offline Lukas Huser
Messages: 39
Registered: March 2010
Member
Hi Mirjam

Yes, this should be possible.

When you look at the interface IRemoteFileService, you will notice the method declaration
@RemoteServiceAccessDenied
void putRemoteFile(RemoteFile spec) throws ProcessingException;

and indeed, this method will allow you to store a RemoteFile on the server. Well, at least if you call this service method on the server itself. It is not allowed to call this method directly from the client -- note the RemoteServiceAccessDenied annotation. (You will get a SecurityException, if you try to do so.)

The reason for this restriction probably are security and/or performance considerations. Before you upload any file to your server from the client, you should do a thorough input validation on the file content and restrict the file size, etc.

That said, you can easily expose the method to the client by defining your own service and simply delegate to the existing implementation of the RemoteFileService to do the work.

Sample Code
Service interface in shared bundle. Register it as a proxy service on client side.
public interface IUploadService extends IService {
  void storeFile(RemoteFile file) throws ProcessingException;
}

Service implementation in server bundle.
public class UploadService extends AbstractService implements IUploadService {
  @Override
  public void storeFile(RemoteFile file) throws ProcessingException {
    SERVICES.getService(IRemoteFileService.class).putRemoteFile(file);
  }
}

You can now use this service on client side, e.g. to upload a file chosen by the user.
public class UploadForm extends AbstractForm {

  // GUI code omitted

  public class ModifyHandler extends AbstractFormHandler {
    @Override
    public void execLoad() throws ProcessingException {
      getFileField().setTypeLoad(true); // FileField extends AbstractFileChooserField
    }

    @Override
    public void execStore() throws ProcessingException {
      File file = getFileField().getValueAsFile();
      if (file != null) {

        // TODO thorough input validation (file size, content etc.)

        // all files are stored in subfolder "fileStore", relative to the root folder of the RemoteFileService
        RemoteFile remoteFile = new RemoteFile("fileStore", file.getName(), file.lastModified());
        try {
          remoteFile.readData(file); // read actual file content
        }
        catch (IOException e) {
          throw new ProcessingException("Error while reading file.", e);
        }
        IUploadService uploadService = SERVICES.getService(IUploadService.class);
        uploadService.storeFile(remoteFile);
      }
    }
  }
}


index.php/fa/15976/0/
  • Attachment: upload.png
    (Size: 5.35KB, Downloaded 80 times)
Previous Topic:Hyperlink Action not working in RAP
Next Topic:Adding Persistence Option to Forms and Services (CRUD)?
Goto Forum:
  


Current Time: Sun Apr 20 04:26:26 EDT 2014

Powered by FUDForum. Page generated in 0.01490 seconds