ImageView in javaFx is not shown when i run it as webstart or in browser - imageview

I've been trying to load an image into an ImageView, and it works fine when I run it as a standalone app, but when I try to run it in the browser or as webstart it doesn't get shown.
I've tried:
ivFoto = new ImageView(new Image("file:/C:/Users/Carlos/Desktop/4fbzW.jpg"));
or
ivFoto = new ImageView(new Image("file:\\C:\\Users\\Carlos\\Desktop\\4fbzW.jpg"));
or
ivFoto = new ImageView("file:///C:/Users/Carlos/Desktop/4fbzW.jpg");
If anyone has any idea of what I'm doing wrong here, I would really appreciate the help!

Package your image (4fbzW.jpg) in your application jar file (in the same location as the class loading the image) and reference it as a resource:
ivFoto = new ImageView(
new Image(
this.getClass().getResource("4fbzW.jpg").toExternalForm()
)
);
There are a couple of things wrong with the image references in your question:
Hardcoding the file: protocol.
A JavaFX application will usually be packaged as a jar file, so resources for the application should be accessed using the jar protocol. By using the getResource method, the resource will be fetched by the same protocol used to load the class referencing the resource, thus it will automatically use the correct protocol to find the resource and you don't need to worry about this detail.
Referring to local resources on your development machine.
Webstart and browser embedded application deployment scenarios are primarily used to reference applications which are delivered over a network to a remote client. The user of the client machine could have any username or be using any supported OS, so they will be unlikely to have a file located at: C:/Users/Carlos/Desktop. By packaging the image with your application and getting it from a location relative to your application's code, then the image can always be found consistently no matter where it is deployed.
File based access violates the security sandbox for WebStart and browser embedded apps
These kind of deployment modes run applications with restricted privileges to prevent malicious applications from doing bad things (like deleting all users files or sending them to a foreign intelligence service). To allow applications to run with elevated security privileges under these deployment modes, you need to sign the applications and the user needs to explicitly trust the software provided by you. In the particular case of your app, I would not recommend signing, but instead package the resources you require with the app so that you and your users do not need to undergo the inconvenience of a signed app.
See also: Where does javafx.scene.image.Image("flower.png") look for flower.png?

Related

Where to put an embedded database in an AspNet Core application

I have lately re-discovered embedded databases such as Sqlite (sql, relational) and LiteDb (noSql) and I like working with them for small web apps or mobile apps.
However, I cannot find any good answer to where to place them. Where to put them if:
The web app is likely to be containerized
The database can grow dynamically
Changes to the code and new deployments should not risk losing any change in database
1. Database file as part of solution (versioned in source control)
I've seen places where the *.db file is placed somewhere in the solution and it's versioned in source control.
I can see how this could be a problem as the database can be modified outside the context of development (i.e: when the app is up and running in production, the DB may change and in the next deployment the db may be overwritten if no backup/restore process in place)
Sometimes I have seen it inside wwwroot/App_Data. See this for instance. I assume App_Data is some kind of protected folder and its files cannot be server statically by the web server (is it?). Otherwise this is even worse.
2. Database file in binary folder
When testing, it's fine to have the database file generated somewhere in the bin folder, but this causes a similar problem as the previous one. What happens when a new software version is released and therefore the database file is overwritten in production?
So the questions are:
Is there any good practice regarding where to place embedded database files?
Is there any alternative to having backup/restore processes to avoid the described data-loss scenarios?
What happens when the app is contenierized and the database file grows once deployed? If the file is inside a container along with the running application, can it grow indefinitely? I don't recall specifying anything about a maximum size for containers anywhere when creating images..
Is having the DB in an external storage such a cloud blob store the alternative? I'm guessing the real benefit of embedded databases is gone if the file is in a different host.
Any good read about this would be appreciated.
PS:
I am asking for AspNet Core apps mainly because I see some projects using the wwwroot folder to place the embedded DB, but the question applies to any technology/framework.
This other question doesn't help either.

JxBrowser: (why) can I (not) use URI path for cache directories?

I evaluated JxBrowser a short while ago. The following questions came to mind:
Can I use Java URIs to "reroute" all temporary files from the underlaying Chromium engine through a custom FileSystemProvider like encFs4J?
The reason I want to that is to comply with data privacy laws. Since browsers can not be forced by a web application to clear their cache or store any temporary files in a safe manner, I thought I could use JxBrowser for this. If I can handle all files myself, I can do some crypto magic so that (almost) no one has access to the data besides my application.
There is an API to define the directories via BrowserContextParams.
However, only absolute paths are allowed. URIs are not accepted.
Instead of doing
BrowserContext context = new BrowserContext(new BrowserContextParams("C:\\Chromium\\Data"));
Browser browser1 = new Browser(context);
I would like to do something like
BrowserContext context = new BrowserContext(new BrowserContextParams(new URI("enc+file:///C:/Chromium/Data"));
Browser browser1 = new Browser(context);
Does anyone know of a way to tap into the file handling routines of a process like JxBrowser? Can I somehow add this functionality like a wrapper around it?
I considered using something like VeraCrypt for this. But this is no good in terms of usability since you have to install virtual harddrive drivers. This is overkill for a rather simple issue.
Underlying Chromium engine in JxBrowser does not use Java IO API to access files. There is only a path string to the data directory that is passed to Chromium engine and it decides by itself how to handle all IO operations.
There is a mode in Chromium called incognito. In that mode all the files, including cookies, cache, history are stored in memory, nothing is stored on the hard drive, so once you close the application, all the data will be cleared automatically. If this meets your requirements we could investigate how to enable incognito mode in JxBrowser.
I will accepting Artem's answer to the original question. Incognito / private browser sessions - as long as they do not store anything on hard disk - would be a perfect and simple solution.
Furthermore, I want to share my research on this topic. The following answer is not related to JxBrowser but to any 3rd party applications and libraries which do not support URI path or require additional safeguarding of (temporary) files.
Option 1: RamDisk
needed: kernel mode driver for ram disk
privileges: admin once (to install the driver)
usability: might be seemless, if application can handle ram disk by code (not researched)
Installing a RamdDisk which can "catch" the files. If the ram disk only persists while the application is running, it is already automatically cleaned up. (not researched for feasibility)
With an own ram disk implementation one could perform additional steps.
Option 2: Virtual File System, e.g. VeraCrypt
needed: VeraCrypt, kernel mode driver
privileges: admin once (to install the driver)
usability: user has to mount container manually before using the application
Due to usability issues this was not further researched.
Option 3: embedded SMB server with local share
needed: SMB server implementation (e.g. JVLAN for Java), creating a server and share in code
privileges: user (Ports 1445 can be used under Linux etc.)
usability: seemless for the user, but quite a complicated solution for a simple issue
Steps: start a SMB server by code, add a share and user authentication (optional), mount the share to a local drive (windows) or mount point (linux), use an absolute path to access the files on the locally mounted share. If the application crashes, then the volatile / in-memory key for the "real" file encryption of the SMB server is lost and the files are safe from other eyes.
This option also has more potential, like clearing files once they got read, controling the access to third party apps and many more - even freakier - ideas.

FinderSync invalidated on El Capitan

We have an application written in Mono that needs to communicate with an Finder Sync App extension.
All is working fine until we tried our app on El Capitan instead of on Yosemite.
We use a shared SQLite database to tell what paths are in which state and use NSDistributedNotificationCenter for communication between the two.
The shared SQLite database is outside of the sandboxed env so we have putted an excepention in our entitlements com.apple.security.temporary-exception.files.home-relative-path.read-write
If we remove this exception from the app extension, the extension works (but obviously we can't read our db)
Then we tought of putting the SQLite DB into memory, but shared memory databases isn't possible over multiple processes.
I can't find how I can create a NSFileHandle for a Sqlite Connection.
We could send over all the info to the application extension, but then that has to keep it in memory (preferably in a SQLite, cause we need to do some querying.)
Does anyone has some pointers of what we could do?
Try to look in The Application Group Container Directory it might do in your case. Basically it allows you to have shared folder between apps/extension.
App group container directories. A sandboxed app can specify an entitlement that gives it access to one or more app group container directories, each of which is shared among all apps with that entitlement.
After some research on similar problem I found it's much easier to have simple TCP server in main app that responds to extension with file status. This way you can easily broadcast file status change to all extension instances etc.

Sharing data files between users in a Universal Windows Platform application

I am about to embark on the development of a line of business application using the Universal Windows Platform (Windows 10). One of the requirements of the application is the synchronisation of data from a server to a local SQLite database; this is required because the application needs to be usable where there is no network connectivity.
It is likely that multiple (windows domain) users will be accessing the application on the same device, sometimes simply by "swapping users", other times by logging off the first user and logging on as a new user.
I realise that UWP applications are installed at a user level, however I would like to be able to share the SQLite database between these users instead of forcing each user to download their own copy of the data.
Is this possible? I am struggling to find any reference to this kind of sharing within the Microsoft documentation - but of course that documentation is new and far from complete!
I guess at the end of the day I am looking for access to a folder that is accessible by any user running that application on the same device, such as the "x:\Users\Public" folders that are available from the desktop, but without having to ask the user to provide access to that folder via any picker control - instead simply being able to "open" it.
Thanks.
In case anyone runs across this, this functionality is now available as described in this blog post:
We introduced a new storage location Windows 10, ApplicationData.SharedLocalFolder, that allows multiple users of one app to share local data. Obviously this feature is only interesting with devices that will be used by more than one person. For such scenarios, for example in educational uses, it may make sense to place any large downloads in Shared Local. The benefits will be two-fold: any user can access these files without the need to re-download them, also there will be storage space savings
Keep in mind that Shared Local is only available if the machine has the right group policy, otherwise when you call ApplicationData.Current.SharedLocalFolder you will get back a null result.
In order to enable Shared Local the machine administrator should enable the corresponding policy.
Alternatively, the administrator could create a REG_DWORD value called AllowSharedLocalAppData with a value of 1 under HKLM\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\AppModel\StateManager
Note that data store in ShareLocal will only be persisted as long as the app is installed on the device and won’t be backed up by the system.
In Solution Explorer , Right click on Package.appxmanifest then click on ViewCode , end of this file in both projects add below code :
<Extensions>
<Extension Category="windows.publisherCacheFolders">
<PublisherCacheFolders>
<Folder Name="FolderName" />
</PublisherCacheFolders>
</Extension>
</Extensions>
After that in code you can access this folder with below line of code :
StorageFolder sharedDownloadsFolder = ApplicationData.Current.GetPublisherCacheFolder("FolderName");
It`s so important that the folder you will share between two these Apps depend on same publisher info at Certificate File [ProjectName]_TemporaryKey.pfx , if this Certificate File and publisher Info of app is same in both Projects , then you can access the same SharedFolder in both application and use it for create or use dataBase file(like SQLite Database file) or other files that need to be share in both applications.

How to open a local file with JavaFX?

I've wrote a mp3 player and works fine in desktop mode (jar file). But when I try to run it via web an AccessControlException is thrown.
I had the same problem with the buttons graphics, and I solved it by uploading the graphics to an image server. Obviously I don't want to do the same with the songs. I want that any user can play their local songs, using a FileChooser.
¿How can I do this?
.....................................................................................................
More details:
The AccessControlException exception occurs here:
try
{
// f is a File
listaCanciones.getItems().add(f.getName()); //adding filename to a ListView (works fine)
mp3Tmp = new Media(f.toURI().toString()); //creating a Media object
listaReproduccion.add(new MediaPlayer(mp3Tmp)); //creating MediaPlayer object and adding it to a playlist
}
The exception's toString() is:
java.security.AccessControlException: access denied ("java.io.FilePermission" "I:\music\song.mp3" "read")
If you want to access the local filesystem from a jnlp deployed application:
Request appropriate permissions in your jnlp file.
Sign the application.
The user has to accept a dialog prompt to grant those permissions to your application.
You can find more information in the Java client deployment guide:
3.2.4 Run in Sandbox Unless Signed and Trusted.
5.6 Sign the JAR Files.
jnlp security element - you shouldn't need to tweak this directly, instead you should specify the required permissions using your packaging tool (e.g. -allpermissions for the javapackager tool).
Note: an application which is not deployed via jnlp does not run in a sandbox and does not have the above requirements.
Oracle supply a FAQ for code signing.

Resources