Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » File handling(upload mp3 file from server to client )
File handling [message #761940] Wed, 07 December 2011 10:24 Go to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi,

I have some .mp3 files on my server (files in a directory). I need to play them on the client. How do I transfer a file from the server to the client.

Regards Bertin
Re: File handling [message #762007 is a reply to message #761940] Wed, 07 December 2011 12:21 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
I think mp3 file do not differ from any other file (like images or word).

Maybe you should have a look at RemoteFile.
Re: File handling [message #762029 is a reply to message #762007] Wed, 07 December 2011 12:59 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
I saw that but I think it is used for remote files, so for files that are accessable through a file path or url.

What i mean is that my file is on the server, that is where the scout server runs. The file is only accessable through the scout server, so that the scout client application gets the file from the scout server application. The directory where the file resides should not be visible or available on the client application.

Maybe it is possible with the remote file but I don't see how yet.

Regards Bertin

Re: File handling [message #762230 is a reply to message #762029] Wed, 07 December 2011 18:36 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
This code works for me:

RemoteFile[] files = SERVICES.getService(IRemoteFileService.class).getRemoteFiles("", new AcceptFileFilter(), null);
for (RemoteFile f : files) {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try {
    f.writeData(baos);
  }
  catch (IOException e) {
    e.printStackTrace();
  }
  MessageBox.showOkMessage(f.getName(), baos.toString(), null);
}


AcceptFileFilter is a simple class in Shared implementing FilenameFilter and Serializable. You could have a more complex Filter (for example test that the file is a mp3 file). You can also add field on this class in order to reuse it. Note:
* It is in shared because it has to be available in the client and in the server.
* Serializable because it is "transported" through the Service Tunnel.

import java.io.File;
import java.io.FilenameFilter;
import java.io.Serializable;

public class AcceptFileFilter implements FilenameFilter, Serializable {
  private static final long serialVersionUID = 1L;

  @Override
  public boolean accept(File arg0, String arg1) {
    return true;
  }
}


Where are the remotes files?
If you have a look a the RemoteFileService you will see that the function getFiles(String, FilenameFilter) uses the private field: m_rootPath to search for files.

This field has a setter: setRootPath(String)

Because this setter is in a Service class, Eclipse Scout supports that you set a value in your server config.ini (more information here: setter in config.ini). This also allows you to have a different configuration for your local development server and your production server.

In config.ini you can set the path for m_rootPath:
### Service Runtime Configuration
org.eclipse.scout.rt.server.services.common.file.RemoteFileService#rootPath=/Users/jebr/remote_files


If you have some text files in the folder defined in your config.ini, you will get some MessageBoxes.
Re: File handling [message #762653 is a reply to message #762230] Thu, 08 December 2011 12:59 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Almost works, except rootpath configuration

In RemoteFileService the following code is executed

@ConfigProperty(ConfigProperty.STRING)
protected String getConfiguredRootPath() {
return null;
}

protected void initConfig() throws ProcessingException {
setRootPath(getConfiguredRootPath());
}

so the result is that the rootpath is null, and it is not configured with the value from the config file.
Some later in the code the m_rootpath ="D:\Downloads\Eclipse\eclipse-scout-indigo-SR1-win32\eclipse" I guesss this must be some default value.

I have no File Services available in my scout perspective, so I cannot configure it like I did with for example SQLService. So is there a way to turn File Services on in the Scout Perspective or do I have to override getConfiguredRootPath() manually?
Re: File handling [message #762781 is a reply to message #762653] Thu, 08 December 2011 16:04 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
I think you missed the fact, that you can "configure" (eg call a setter function in a service) from a config.ini file.

In the scout Perspective open the config.ini file of one of your server config.ini (for example /<your app>.server/products/development/config.ini)
index.php/fa/6381/0/
change (or add if missing):
### Service Runtime Configuration
org.eclipse.scout.rt.server.services.common.file.RemoteFileService#rootPath=<<YOUR VALUE HERE>>

That way you do not need to change the RemoteFileService.




It is true that another possibility would be to create your own RemoteFileService: MyAppRemoteFileServer
public class MyAppRemoteFileServer extends RemoteFileService {
  @Override
  protected String getConfiguredRootPath() {
    return "<<YOUR VALUE HERE>>";
  }
}

With a bigger priority than the default RemoteFileService, your implementation would win.
But you need to do this from hand. There is no support form the Scout Perspective for that (could be requested).




PS: The possibility to call a setter of a service from the config.ini of the server is very usefull. See also: deploying to server => database configuration
config ini provides you the possibility to have database configuration that is independent of your compiled code (you just need to change the condig.ini to change database configuration).

Re: File handling [message #762837 is a reply to message #762781] Thu, 08 December 2011 17:32 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
This is what my ini file looks like


#Development Settings
osgi.clean=true
org.eclipse.equinox.http.jetty.http.port=8080
org.eclipse.equinox.http.jetty.context.path=/grammastudio6

#Eclipse Runtime Configuration File
osgi.noShutdown=true
eclipse.ignoreApp=false
eclipse.product=nl.rid.grammastudio6.server.product
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@start, org.eclipse.equinox.http.jetty@start, org.eclipse.equinox.http.registry@start, org.eclipse.core.runtime@start
osgi.bundles.defaultStartLevel=4

eclipse.consoleLog=true
org.eclipse.scout.log=eclipse
org.eclipse.scout.log.level=WARNING


### Service Runtime Configuration
org.eclipse.scout.rt.server.services.common.file.RemoteFileService#rootPath=D:


### Servlet Filter Runtime Configuration
org.eclipse.scout.rt.server.servlet.filter.BasicSecurityFilter#active=false
org.eclipse.scout.rt.server.servlet.filter.BasicSecurityFilter#realm=grammastudio6 Devleopment
org.eclipse.scout.rt.server.servlet.filter.BasicSecurityFilter#users=admin\=manager,allen\=allen,blake\=blake

org.eclipse.scout.rt.server.servlet.filter.AnonymousSecurityFilter#active=true



but when the call public RemoteFile[] getRemoteFiles() is executed at the server, the value of m_rootPath = "D:\Downloads\Eclipse\eclipse-scout-indigo-SR1-win32\eclipse" which is the installation directory of eclipse

So for some reason it takes some default instead of the value from the config.ini


Regards Bertin

Re: File handling [message #762913 is a reply to message #762837] Thu, 08 December 2011 20:01 Go to previous message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Works now

if the input in the config.ini is not a correct path, the value is not loaded.

thanks for the answers, it helped me a lot.

Regards Bertin
Previous Topic:PlannerField
Next Topic:External Component
Goto Forum:
  


Current Time: Tue Apr 23 17:58:19 GMT 2024

Powered by FUDForum. Page generated in 0.03566 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top